summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/geo/openlayers/widget/Map.js
blob: da29758ec32cd6dd4c9a5a0ecb9922ddc6d21db0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//>>built
define("dojox/geo/openlayers/widget/Map", ["dojo/_base/kernel",
				"dojo/_base/declare",
				"dojo/_base/array",
				"dojo/_base/html",
				"dojo/query",
				"dijit/_Widget",
				"dojox/geo/openlayers/Map",
				"dojox/geo/openlayers/Layer",
				"dojox/geo/openlayers/GfxLayer"], function(dojo, declare, array, html, query, Widget, Map, Layer, GfxLayer){
		/*===== 
		var Widget = dijit.Widget; 
		=====*/
	return declare("dojox.geo.openlayers.widget.Map", Widget, {
		//	summary: 
		//		A widget version of the `dojox.geo.openlayers.Map` component.
		//	description: 
		//		The `dojox.geo.openlayers.widget.Map` widget is the widget 
		//		version of the `dojox.geo.openlayers.Map` component. 
		//		With this widget, user can specify some attributes in the markup suach as
		// 
		//	* `baseLayerType`: The type of the base layer. Permitted values are 
		//	* `initialLocation`: The initial location as for the dojox.geo.openlayers.Map.fitTo method
		//	* `touchHandler`: Tells if we attach touch handler or not.
		//	
		//	example:
		//	
		//	| <div id="map" dojoType="dojox.geo.openlayers.widget.Map" baseLayerType="Google" initialLocation="{
		//	|   position : [7.154126, 43.651748],
		//	|   extent : 0.2 }"
		//	| style="background-color: #b5d0d0; width: 100%; height: 100%;">
		//

		//	summay:
		//		Base layer type as defined in `dojox.geo.openlayer.BaseLayerType
		//	description:
		//		baseLayerType can be either 
		//		* `OSM`
		//		* `WMS`
		//		* `Google`
		//		* `VirtualEarth`
		//		* `Yahoo`
		//		* `ArcGIS`
		//	baseLayerType : String
		//		Base layer type property.
		baseLayerType : dojox.geo.openlayers.BaseLayerType.OSM,

		//	summary:
		//		The part of the map shown at startup time.
		//	description:
		//		initial location is the string description of the location shown at 
		//		startup time. Format is the same as for the `dojox.geo.openlayers.widget.Map.fitTo`
		//		method.
		//	|	{
		//	|	bounds : [ulx, uly, lrx, lry]
		//	|	}
		//		The map is fit on the specified bounds expressed as decimal degrees latitude and longitude.
		//		The bounds are defined with their upper left and lower right corners coordinates.
		//	
		//	|	{
		//	|	position : [longitude, latitude],
		//	|	extent : degrees
		//	|	}
		//	The map is fit on the specified position showing the extent <extent> around
		//	the specified center position.
		initialLocation : null,

		//	summary:
		//		Tells if the touch handler should be attached to the map or not.
		//	description:
		//		Tells if the touch handler should be attached to the map or not.
		//		Touch handler handles touch events so that the widget can be used
		//		on mobile applications.
		touchHandler : false,

		//	summary:
		//		The underlying `dojox.geo.openlayers.Map` object.
		//		This is s readonly member.
		map : null,

		startup : function(){
			//	summary:
			//		Processing after the DOM fragment is added to the document
			this.inherited(arguments);
			this.map.initialFit({
				initialLocation : this.initialLocation
			});
		},

		buildRendering : function(){
			//	summary:
			//		Construct the UI for this widget, creates the real dojox.geo.openlayers.Map object.		
			//	tags:
			//		protected
			this.inherited(arguments);
			var div = this.domNode;
			var map = new Map(div, {
				baseLayerType : this.baseLayerType,
				touchHandler : this.touchHandler
			});
			this.map = map;

			this._makeLayers();
		},

		_makeLayers : function(){
			//	summary:
			//		Creates layers defined as markup.
			//	tags:
			//		private
			var n = this.domNode;
			var layers = /* ?? query. */query("> .layer", n);
			array.forEach(layers, function(l){
				var type = l.getAttribute("type");
				var name = l.getAttribute("name");
				var cls = "dojox.geo.openlayers." + type;
				var p = dojo.getObject(cls);
				if (p) {
					var layer = new p(name, {});
					if (layer)
						this.map.addLayer(layer);
				}
			}, this);
		},

		resize : function(b){
			//	summary:
			//		Resize the widget.
			//	description:
			//		Resize the domNode and the widget to the dimensions of a box of the following form:
			//			`{ l: 50, t: 200, w: 300: h: 150 }`
			//	b: undefined | Box | width, height
			//		If passed, denotes the new size of the widget.
			// 		Can be either nothing (widget adapts to the div),
			// 		a box, or a width and a height.

			var olm = this.map.getOLMap();

			var box;
			switch (arguments.length) {
				case 0:
					// case 0, do not resize the div, just the surface
				break;
				case 1:
					// argument, override node box
					box = dojo.mixin({}, b);
					dojo.marginBox(olm.div, box);
				break;
				case 2:
					// two argument, width, height
					box = {
						w : arguments[0],
						h : arguments[1]
					};
					dojo.marginBox(olm.div, box);
				break;
			}
			olm.updateSize();
		}
	});
});