summaryrefslogtreecommitdiff
path: root/js/dojo-1.7.2/dojox/geo/charting/widget/Map.js
blob: dc28e7d280a58bd568db72fb2973c39b9a235c18 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//>>built

define("dojox/geo/charting/widget/Map", ["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/declare","dojo/_base/html","dojo/dom-geometry",
		"dijit/_Widget","dojox/geo/charting/Map"],
							function(dojo, lang, declare, html,domGeom, Widget, Map) {

return declare("dojox.geo.charting.widget.Map", Widget, {
	// summary:
	//		A map viewer widget based on the dojox.geo.charting.Map component
	//
	//	description:
	//		The `dojox.geo.charting.widget.Map` widget combines map display together with charting capabilities. 
	//		It encapsulates  an `dojox.geo.charting.Map` object on which most operations are delegated.
	//		Parameters can be passed as argument at construction time to specify map data file (json shape format)
	//		as well as charting data. 
	// 
	//	The parameters are :
	//	
	// * `shapeData`: The json object containing map data or the name of the file containing map data.
	// * `dataStore`: the dataStore to fetch the charting data from
	// * `dataBindingAttribute`: property name of the dataStore items to use as value for charting
	// * `markerData`: tooltips to display for map features, handled as json style.
	// * `adjustMapCenterOnResize`: if true, the center of the map remains the same when resizing the widget   
	// * `adjustMapScaleOnResize`: if true, the map scale is adjusted to leave the visible portion of the map identical as much as possible 
	//
	//	example:
	//
	// |	var map = new dojox.geo.charting.widget.Map({
	// |		shapeData : 'map.json',
	// |		adjustMapCenterOnresize : true,
	// |		adjustMapScaleOnresize : true,
	// |	});

	shapeData : "",
	dataStore : null,
	dataBindingAttribute : "",
	dataBindingValueFunction: null,
	markerData : "",
	series : "",
	adjustMapCenterOnResize: null,
	adjustMapScaleOnResize: null,
	animateOnResize: null,
	onFeatureClick: null,
	onFeatureOver: null,
	enableMouseSupport: null,
	enableTouchSupport: null,
	enableMouseZoom: null,
	enableMousePan: null,
	enableKeyboardSupport: false,
	showTooltips: false,
	enableFeatureZoom: null,
	colorAnimationDuration: 0,
	mouseClickThreshold: 2,
	_mouseInteractionSupport:null,
	_touchInteractionSupport:null,
	_keyboardInteractionSupport:null,
	constructor : function(/* Object */options, /* HtmlNode */div){
		//	summary: 
		//		Constructs a new Map widget
		this.map = null;
	},

	startup : function(){
		this.inherited(arguments);
		if (this.map) {
			this.map.fitToMapContents();
		}
		
	},

	postMixInProperties : function(){
		this.inherited(arguments);
	},

	create : function(/*Object?*/params, /*DomNode|String?*/srcNodeRef){
		this.inherited(arguments);
	},
	
	getInnerMap: function() {
		return this.map;
	},
	

	buildRendering : function(){
		//	summary:
		//		Construct the UI for this widget, creates the underlying real dojox.geo.charting.Map object.		
		//	tags:
		//		protected
		this.inherited(arguments);
		if (this.shapeData) {
			this.map = new Map(this.domNode, this.shapeData);
			if (this.markerData && (this.markerData.length > 0))
				this.map.setMarkerData(this.markerData);
			
			if (this.dataStore) {
				if (this.dataBindingValueFunction) {
					this.map.setDataBindingValueFunction(this.dataBindingValueFunction);
				}
				this.map.setDataStore(this.dataStore,this.dataBindingAttribute);
			}
			
			if (this.series && (this.series.length > 0)) {
				this.map.addSeries(this.series);
			}
			
			if (this.onFeatureClick) {
				this.map.onFeatureClick = this.onFeatureClick;
			}
			if (this.onFeatureOver) {
				this.map.onFeatureOver = this.onFeatureOver;
			}
			if (this.enableMouseSupport) {
				
				if (!dojox.geo.charting.MouseInteractionSupport) {
					throw Error("Can't find dojox.geo.charting.MouseInteractionSupport. Didn't you forget to dojo" + ".require() it?");
				}
				var options = {};
				options.enablePan = this.enableMousePan;
				options.enableZoom = this.enableMouseZoom;
				options.mouseClickThreshold = this.mouseClickThreshold;
				this._mouseInteractionSupport = new dojox.geo.charting.MouseInteractionSupport(this.map,options);
				this._mouseInteractionSupport.connect();
			}
			
			if (this.enableTouchSupport) {
				if (!dojox.geo.charting.TouchInteractionSupport) {
					throw Error("Can't find dojox.geo.charting.TouchInteractionSupport. Didn't you forget to dojo" + ".require() it?");
				}
				this._touchInteractionSupport = new dojox.geo.charting.TouchInteractionSupport(this.map,{});
				this._touchInteractionSupport.connect(); 
			}
			if (this.enableKeyboardSupport) {
				if (!dojox.geo.charting.KeyboardInteractionSupport) {
					throw Error("Can't find dojox.geo.charting.KeyboardInteractionSupport. Didn't you forget to dojo" + ".require() it?");
				}
				this._keyboardInteractionSupport = new dojox.geo.charting.KeyboardInteractionSupport(this.map,{});
				this._keyboardInteractionSupport.connect(); 
			}
			this.map.showTooltips = this.showTooltips;
			this.map.enableFeatureZoom = this.enableFeatureZoom;
			this.map.colorAnimationDuration = this.colorAnimationDuration;
			
			
		}
	},
	

	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 }`
		//	box:
		//		If passed, denotes the new size of the widget.

		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 = lang.mixin({}, b);
				domGeom.getMarginBox(this.domNode, box);
				break;
			case 2:
				// two argument, width, height
				box = {
					w : arguments[0],
					h : arguments[1]
				};
				domGeom.getMarginBox(this.domNode, box);
				break;
		}
		
		if (this.map) {
			this.map.resize(this.adjustMapCenterOnResize,this.adjustMapScaleOnResize,this.animateOnResize);
		}
	}
});
});