Subversion Repositories Applications.papyrus

Rev

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

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