Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Rev 2149 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.GoogleMap");
13
dojo.provide("dojo.widget.GoogleMap");
12
dojo.require("dojo.event.*");
14
dojo.require("dojo.event.*");
13
dojo.require("dojo.math");
15
dojo.require("dojo.math");
14
dojo.require("dojo.widget.*");
16
dojo.require("dojo.widget.*");
15
dojo.require("dojo.uri.Uri");
17
dojo.require("dojo.uri.Uri");
16
dojo.require("dojo.widget.HtmlWidget");
18
dojo.require("dojo.widget.HtmlWidget");
17
(function () {
19
(function () {
18
	var gkey = djConfig["gMapKey"] || djConfig["googleMapKey"];
20
	var gkey = djConfig["gMapKey"] || djConfig["googleMapKey"];
19
	var uri = new dojo.uri.Uri(window.location.href);
21
	var uri = new dojo.uri.Uri(window.location.href);
20
	if (uri.host == "www.dojotoolkit.org") {
22
	if (uri.host == "www.dojotoolkit.org") {
21
		gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hRqjp7ri2mNiOEYqetD3xnFHpt5rBSjszDd1sdufPyQKUTyCf_YxoIxvw";
23
		gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hRqjp7ri2mNiOEYqetD3xnFHpt5rBSjszDd1sdufPyQKUTyCf_YxoIxvw";
22
	} else {
24
	} else {
23
		if (uri.host == "blog.dojotoolkit.org") {
25
		if (uri.host == "blog.dojotoolkit.org") {
24
			gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hSkep6Av1xaMhVn3yCLkorJeXeLARQ6fammI_P3qSGleTJhoI5_1JmP_Q";
26
			gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hSkep6Av1xaMhVn3yCLkorJeXeLARQ6fammI_P3qSGleTJhoI5_1JmP_Q";
25
		} else {
27
		} else {
26
			if (uri.host == "archive.dojotoolkit.org") {
28
			if (uri.host == "archive.dojotoolkit.org") {
27
				gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hTaQpDt0dyGLIHbXMPTzg1kWeAfwRTwZNyrUfbfxYE9yIvRivEjcXoDTg";
29
				gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hTaQpDt0dyGLIHbXMPTzg1kWeAfwRTwZNyrUfbfxYE9yIvRivEjcXoDTg";
28
			} else {
30
			} else {
29
				if (uri.host == "dojotoolkit.org") {
31
				if (uri.host == "dojotoolkit.org") {
30
					gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hSaOaO_TgJ5c3mtQFnk5JO2zD5dZBRZk-ieqVs7BORREYNzAERmcJoEjQ";
32
					gkey = "ABQIAAAACUNdgv_7FGOmUslbm9l6_hSaOaO_TgJ5c3mtQFnk5JO2zD5dZBRZk-ieqVs7BORREYNzAERmcJoEjQ";
31
				}
33
				}
32
			}
34
			}
33
		}
35
		}
34
	}
36
	}
35
	if (!dojo.hostenv.post_load_) {
37
	if (!dojo.hostenv.post_load_) {
36
		if (!gkey || gkey == "") {
38
		if (!gkey || gkey == "") {
37
			dojo.raise("dojo.widget.GoogleMap: The Google Map widget requires a proper API key in order to be used.");
39
			dojo.raise("dojo.widget.GoogleMap: The Google Map widget requires a proper API key in order to be used.");
38
		}
40
		}
39
		var tag = "<scr" + "ipt src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=" + gkey + "'></scri" + "pt>";
41
		var tag = "<scr" + "ipt src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=" + gkey + "'></scri" + "pt>";
40
		if (!dj_global["GMap2"]) {
42
		if (!dj_global["GMap2"]) {
41
			document.write(tag);
43
			document.write(tag);
42
		}
44
		}
43
	} else {
45
	} else {
44
		dojo.debug("Cannot initialize Google Map system after the page has been loaded! Please either manually include the script block provided by Google in your page or require() the GoogleMap widget before onload has fired.");
46
		dojo.debug("Cannot initialize Google Map system after the page has been loaded! Please either manually include the script block provided by Google in your page or require() the GoogleMap widget before onload has fired.");
45
	}
47
	}
46
})();
48
})();
47
dojo.widget.defineWidget("dojo.widget.GoogleMap", dojo.widget.HtmlWidget, function () {
49
dojo.widget.defineWidget("dojo.widget.GoogleMap", dojo.widget.HtmlWidget, function () {
48
	this.map = null;
50
	this.map = null;
49
	this.geocoder = null;
51
	this.geocoder = null;
50
	this.data = [];
52
	this.data = [];
51
	this.datasrc = "";
53
	this.datasrc = "";
52
	this.controls = ["largemap", "scale", "maptype"];
54
	this.controls = ["largemap", "scale", "maptype"];
53
}, {templatePath:null, templateCssPath:null, isContainer:false, _defaultPoint:{lat:39.10662, lng:-94.578209}, setControls:function () {
55
}, {templatePath:null, templateCssPath:null, isContainer:false, _defaultPoint:{lat:39.10662, lng:-94.578209}, setControls:function () {
54
	var methodmap = {largemap:GLargeMapControl, smallmap:GSmallMapControl, smallzoom:GSmallZoomControl, scale:GScaleControl, maptype:GMapTypeControl, overview:GOverviewMapControl};
56
	var methodmap = {largemap:GLargeMapControl, smallmap:GSmallMapControl, smallzoom:GSmallZoomControl, scale:GScaleControl, maptype:GMapTypeControl, overview:GOverviewMapControl};
55
	for (var i = 0; i < this.controls.length; i++) {
57
	for (var i = 0; i < this.controls.length; i++) {
56
		this.map.addControl(new (methodmap[this.controls[i].toLowerCase()])());
58
		this.map.addControl(new (methodmap[this.controls[i].toLowerCase()])());
57
	}
59
	}
58
}, findCenter:function (bounds) {
60
}, findCenter:function (bounds) {
59
	if (this.data.length == 1) {
61
	if (this.data.length == 1) {
60
		return (new GLatLng(this.data[0].lat, this.data[0].lng));
62
		return (new GLatLng(this.data[0].lat, this.data[0].lng));
61
	}
63
	}
62
	var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2;
64
	var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2;
63
	var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2;
65
	var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2;
64
	return (new GLatLng(clat, clng));
66
	return (new GLatLng(clat, clng));
65
}, createPinpoint:function (pt, overlay) {
67
}, createPinpoint:function (pt, overlay) {
66
	var m = new GMarker(pt);
68
	var m = new GMarker(pt);
67
	if (overlay) {
69
	if (overlay) {
68
		GEvent.addListener(m, "click", function () {
70
		GEvent.addListener(m, "click", function () {
69
			m.openInfoWindowHtml("<div>" + overlay + "</div>");
71
			m.openInfoWindowHtml("<div>" + overlay + "</div>");
70
		});
72
		});
71
	}
73
	}
72
	return m;
74
	return m;
73
}, plot:function (obj) {
75
}, plot:function (obj) {
74
	var p = new GLatLng(obj.lat, obj.lng);
76
	var p = new GLatLng(obj.lat, obj.lng);
75
	var d = obj.description || null;
77
	var d = obj.description || null;
76
	var m = this.createPinpoint(p, d);
78
	var m = this.createPinpoint(p, d);
77
	this.map.addOverlay(m);
79
	this.map.addOverlay(m);
78
}, plotAddress:function (address) {
80
}, plotAddress:function (address) {
79
	var self = this;
81
	var self = this;
80
	this.geocoder.getLocations(address, function (response) {
82
	this.geocoder.getLocations(address, function (response) {
81
		if (!response || response.Status.code != 200) {
83
		if (!response || response.Status.code != 200) {
82
			alert("The address \"" + address + "\" was not found.");
84
			alert("The address \"" + address + "\" was not found.");
83
			return;
85
			return;
84
		}
86
		}
85
		var obj = {lat:response.Placemark[0].Point.coordinates[1], lng:response.Placemark[0].Point.coordinates[0], description:response.Placemark[0].address};
87
		var obj = {lat:response.Placemark[0].Point.coordinates[1], lng:response.Placemark[0].Point.coordinates[0], description:response.Placemark[0].address};
86
		self.data.push(obj);
88
		self.data.push(obj);
87
		self.render();
89
		self.render();
88
	});
90
	});
89
}, parse:function (table) {
91
}, parse:function (table) {
90
	this.data = [];
92
	this.data = [];
91
	var h = table.getElementsByTagName("thead")[0];
93
	var h = table.getElementsByTagName("thead")[0];
92
	if (!h) {
94
	if (!h) {
93
		return;
95
		return;
94
	}
96
	}
95
	var a = [];
97
	var a = [];
96
	var cols = h.getElementsByTagName("td");
98
	var cols = h.getElementsByTagName("td");
97
	if (cols.length == 0) {
99
	if (cols.length == 0) {
98
		cols = h.getElementsByTagName("th");
100
		cols = h.getElementsByTagName("th");
99
	}
101
	}
100
	for (var i = 0; i < cols.length; i++) {
102
	for (var i = 0; i < cols.length; i++) {
101
		var c = cols[i].innerHTML.toLowerCase();
103
		var c = cols[i].innerHTML.toLowerCase();
102
		if (c == "long") {
104
		if (c == "long") {
103
			c = "lng";
105
			c = "lng";
104
		}
106
		}
105
		a.push(c);
107
		a.push(c);
106
	}
108
	}
107
	var b = table.getElementsByTagName("tbody")[0];
109
	var b = table.getElementsByTagName("tbody")[0];
108
	if (!b) {
110
	if (!b) {
109
		return;
111
		return;
110
	}
112
	}
111
	for (var i = 0; i < b.childNodes.length; i++) {
113
	for (var i = 0; i < b.childNodes.length; i++) {
112
		if (!(b.childNodes[i].nodeName && b.childNodes[i].nodeName.toLowerCase() == "tr")) {
114
		if (!(b.childNodes[i].nodeName && b.childNodes[i].nodeName.toLowerCase() == "tr")) {
113
			continue;
115
			continue;
114
		}
116
		}
115
		var cells = b.childNodes[i].getElementsByTagName("td");
117
		var cells = b.childNodes[i].getElementsByTagName("td");
116
		var o = {};
118
		var o = {};
117
		for (var j = 0; j < a.length; j++) {
119
		for (var j = 0; j < a.length; j++) {
118
			var col = a[j];
120
			var col = a[j];
119
			if (col == "lat" || col == "lng") {
121
			if (col == "lat" || col == "lng") {
120
				o[col] = parseFloat(cells[j].innerHTML);
122
				o[col] = parseFloat(cells[j].innerHTML);
121
			} else {
123
			} else {
122
				o[col] = cells[j].innerHTML;
124
				o[col] = cells[j].innerHTML;
123
			}
125
			}
124
		}
126
		}
125
		this.data.push(o);
127
		this.data.push(o);
126
	}
128
	}
127
}, render:function () {
129
}, render:function () {
128
	if (this.data.length == 0) {
130
	if (this.data.length == 0) {
129
		this.map.setCenter(new GLatLng(this._defaultPoint.lat, this._defaultPoint.lng), 4);
131
		this.map.setCenter(new GLatLng(this._defaultPoint.lat, this._defaultPoint.lng), 4);
130
		return;
132
		return;
131
	}
133
	}
132
	this.map.clearOverlays();
134
	this.map.clearOverlays();
133
	var bounds = new GLatLngBounds();
135
	var bounds = new GLatLngBounds();
134
	var d = this.data;
136
	var d = this.data;
135
	for (var i = 0; i < d.length; i++) {
137
	for (var i = 0; i < d.length; i++) {
136
		bounds.extend(new GLatLng(d[i].lat, d[i].lng));
138
		bounds.extend(new GLatLng(d[i].lat, d[i].lng));
137
	}
139
	}
138
	var zoom = Math.min((this.map.getBoundsZoomLevel(bounds) - 1), 14);
140
	var zoom = Math.min((this.map.getBoundsZoomLevel(bounds) - 1), 14);
139
	this.map.setCenter(this.findCenter(bounds), zoom);
141
	this.map.setCenter(this.findCenter(bounds), zoom);
140
	for (var i = 0; i < this.data.length; i++) {
142
	for (var i = 0; i < this.data.length; i++) {
141
		this.plot(this.data[i]);
143
		this.plot(this.data[i]);
142
	}
144
	}
143
}, initialize:function (args, frag) {
145
}, initialize:function (args, frag) {
144
	if (this.datasrc) {
146
	if (this.datasrc) {
145
		this.parse(dojo.byId(this.datasrc));
147
		this.parse(dojo.byId(this.datasrc));
146
	} else {
148
	} else {
147
		if (this.domNode.getElementsByTagName("table")[0]) {
149
		if (this.domNode.getElementsByTagName("table")[0]) {
148
			this.parse(this.domNode.getElementsByTagName("table")[0]);
150
			this.parse(this.domNode.getElementsByTagName("table")[0]);
149
		}
151
		}
150
	}
152
	}
151
}, postCreate:function () {
153
}, postCreate:function () {
152
	while (this.domNode.childNodes.length > 0) {
154
	while (this.domNode.childNodes.length > 0) {
153
		this.domNode.removeChild(this.domNode.childNodes[0]);
155
		this.domNode.removeChild(this.domNode.childNodes[0]);
154
	}
156
	}
155
	if (this.domNode.style.position != "absolute") {
157
	if (this.domNode.style.position != "absolute") {
156
		this.domNode.style.position = "relative";
158
		this.domNode.style.position = "relative";
157
	}
159
	}
158
	this.map = new GMap2(this.domNode);
160
	this.map = new GMap2(this.domNode);
159
	try {
161
	try {
160
		this.geocoder = new GClientGeocoder();
162
		this.geocoder = new GClientGeocoder();
161
	}
163
	}
162
	catch (ex) {
164
	catch (ex) {
163
	}
165
	}
164
	this.render();
166
	this.render();
165
	this.setControls();
167
	this.setControls();
166
}});
168
}});
167
 
169