Subversion Repositories Applications.papyrus

Rev

Rev 2149 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2149 Rev 2150
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>";
-
 
43
		if (!dj_global["GMap2"]) {
42
		if (!dj_global["GMap2"]) {
44
			document.write(tag);
43
			document.write(tag);
45
		}
44
		}
46
	} else {
45
	} else {
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.");
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.");
48
	}
47
	}
49
})();
48
})();
50
dojo.widget.defineWidget("dojo.widget.GoogleMap", dojo.widget.HtmlWidget, function () {
49
dojo.widget.defineWidget("dojo.widget.GoogleMap", dojo.widget.HtmlWidget, function () {
51
	this.map = null;
50
	this.map = null;
52
	this.geocoder = null;
51
	this.geocoder = null;
53
	this.data = [];
52
	this.data = [];
54
	this.datasrc = "";
53
	this.datasrc = "";
55
	this.controls = ["largemap", "scale", "maptype"];
54
	this.controls = ["largemap", "scale", "maptype"];
56
}, {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 () {
57
	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};
58
	for (var i = 0; i < this.controls.length; i++) {
57
	for (var i = 0; i < this.controls.length; i++) {
59
		this.map.addControl(new (methodmap[this.controls[i].toLowerCase()])());
58
		this.map.addControl(new (methodmap[this.controls[i].toLowerCase()])());
60
	}
59
	}
61
}, findCenter:function (bounds) {
60
}, findCenter:function (bounds) {
62
	if (this.data.length == 1) {
61
	if (this.data.length == 1) {
63
		return (new GLatLng(this.data[0].lat, this.data[0].lng));
62
		return (new GLatLng(this.data[0].lat, this.data[0].lng));
64
	}
63
	}
65
	var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2;
64
	var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2;
66
	var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2;
65
	var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2;
67
	return (new GLatLng(clat, clng));
66
	return (new GLatLng(clat, clng));
68
}, createPinpoint:function (pt, overlay) {
67
}, createPinpoint:function (pt, overlay) {
69
	var m = new GMarker(pt);
68
	var m = new GMarker(pt);
70
	if (overlay) {
69
	if (overlay) {
71
		GEvent.addListener(m, "click", function () {
70
		GEvent.addListener(m, "click", function () {
72
			m.openInfoWindowHtml("<div>" + overlay + "</div>");
71
			m.openInfoWindowHtml("<div>" + overlay + "</div>");
73
		});
72
		});
74
	}
73
	}
75
	return m;
74
	return m;
76
}, plot:function (obj) {
75
}, plot:function (obj) {
77
	var p = new GLatLng(obj.lat, obj.lng);
76
	var p = new GLatLng(obj.lat, obj.lng);
78
	var d = obj.description || null;
77
	var d = obj.description || null;
79
	var m = this.createPinpoint(p, d);
78
	var m = this.createPinpoint(p, d);
80
	this.map.addOverlay(m);
79
	this.map.addOverlay(m);
81
}, plotAddress:function (address) {
80
}, plotAddress:function (address) {
82
	var self = this;
81
	var self = this;
83
	this.geocoder.getLocations(address, function (response) {
82
	this.geocoder.getLocations(address, function (response) {
84
		if (!response || response.Status.code != 200) {
83
		if (!response || response.Status.code != 200) {
85
			alert("The address \"" + address + "\" was not found.");
84
			alert("The address \"" + address + "\" was not found.");
86
			return;
85
			return;
87
		}
86
		}
88
		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};
89
		self.data.push(obj);
88
		self.data.push(obj);
90
		self.render();
89
		self.render();
91
	});
90
	});
92
}, parse:function (table) {
91
}, parse:function (table) {
93
	this.data = [];
92
	this.data = [];
94
	var h = table.getElementsByTagName("thead")[0];
93
	var h = table.getElementsByTagName("thead")[0];
95
	if (!h) {
94
	if (!h) {
96
		return;
95
		return;
97
	}
96
	}
98
	var a = [];
97
	var a = [];
99
	var cols = h.getElementsByTagName("td");
98
	var cols = h.getElementsByTagName("td");
100
	if (cols.length == 0) {
99
	if (cols.length == 0) {
101
		cols = h.getElementsByTagName("th");
100
		cols = h.getElementsByTagName("th");
102
	}
101
	}
103
	for (var i = 0; i < cols.length; i++) {
102
	for (var i = 0; i < cols.length; i++) {
104
		var c = cols[i].innerHTML.toLowerCase();
103
		var c = cols[i].innerHTML.toLowerCase();
105
		if (c == "long") {
104
		if (c == "long") {
106
			c = "lng";
105
			c = "lng";
107
		}
106
		}
108
		a.push(c);
107
		a.push(c);
109
	}
108
	}
110
	var b = table.getElementsByTagName("tbody")[0];
109
	var b = table.getElementsByTagName("tbody")[0];
111
	if (!b) {
110
	if (!b) {
112
		return;
111
		return;
113
	}
112
	}
114
	for (var i = 0; i < b.childNodes.length; i++) {
113
	for (var i = 0; i < b.childNodes.length; i++) {
115
		if (!(b.childNodes[i].nodeName && b.childNodes[i].nodeName.toLowerCase() == "tr")) {
114
		if (!(b.childNodes[i].nodeName && b.childNodes[i].nodeName.toLowerCase() == "tr")) {
116
			continue;
115
			continue;
117
		}
116
		}
118
		var cells = b.childNodes[i].getElementsByTagName("td");
117
		var cells = b.childNodes[i].getElementsByTagName("td");
119
		var o = {};
118
		var o = {};
120
		for (var j = 0; j < a.length; j++) {
119
		for (var j = 0; j < a.length; j++) {
121
			var col = a[j];
120
			var col = a[j];
122
			if (col == "lat" || col == "lng") {
121
			if (col == "lat" || col == "lng") {
123
				o[col] = parseFloat(cells[j].innerHTML);
122
				o[col] = parseFloat(cells[j].innerHTML);
124
			} else {
123
			} else {
125
				o[col] = cells[j].innerHTML;
124
				o[col] = cells[j].innerHTML;
126
			}
125
			}
127
		}
126
		}
128
		this.data.push(o);
127
		this.data.push(o);
129
	}
128
	}
130
}, render:function () {
129
}, render:function () {
131
	if (this.data.length == 0) {
130
	if (this.data.length == 0) {
132
		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);
133
		return;
132
		return;
134
	}
133
	}
135
	this.map.clearOverlays();
134
	this.map.clearOverlays();
136
	var bounds = new GLatLngBounds();
135
	var bounds = new GLatLngBounds();
137
	var d = this.data;
136
	var d = this.data;
138
	for (var i = 0; i < d.length; i++) {
137
	for (var i = 0; i < d.length; i++) {
139
		bounds.extend(new GLatLng(d[i].lat, d[i].lng));
138
		bounds.extend(new GLatLng(d[i].lat, d[i].lng));
140
	}
139
	}
141
	var zoom = Math.min((this.map.getBoundsZoomLevel(bounds) - 1), 14);
140
	var zoom = Math.min((this.map.getBoundsZoomLevel(bounds) - 1), 14);
142
	this.map.setCenter(this.findCenter(bounds), zoom);
141
	this.map.setCenter(this.findCenter(bounds), zoom);
143
	for (var i = 0; i < this.data.length; i++) {
142
	for (var i = 0; i < this.data.length; i++) {
144
		this.plot(this.data[i]);
143
		this.plot(this.data[i]);
145
	}
144
	}
146
}, initialize:function (args, frag) {
145
}, initialize:function (args, frag) {
147
	if (this.datasrc) {
146
	if (this.datasrc) {
148
		this.parse(dojo.byId(this.datasrc));
147
		this.parse(dojo.byId(this.datasrc));
149
	} else {
148
	} else {
150
		if (this.domNode.getElementsByTagName("table")[0]) {
149
		if (this.domNode.getElementsByTagName("table")[0]) {
151
			this.parse(this.domNode.getElementsByTagName("table")[0]);
150
			this.parse(this.domNode.getElementsByTagName("table")[0]);
152
		}
151
		}
153
	}
152
	}
154
}, postCreate:function () {
153
}, postCreate:function () {
155
	while (this.domNode.childNodes.length > 0) {
154
	while (this.domNode.childNodes.length > 0) {
156
		this.domNode.removeChild(this.domNode.childNodes[0]);
155
		this.domNode.removeChild(this.domNode.childNodes[0]);
157
	}
156
	}
158
	if (this.domNode.style.position != "absolute") {
157
	if (this.domNode.style.position != "absolute") {
159
		this.domNode.style.position = "relative";
158
		this.domNode.style.position = "relative";
160
	}
159
	}
161
	this.map = new GMap2(this.domNode);
160
	this.map = new GMap2(this.domNode);
162
	try {
161
	try {
163
		this.geocoder = new GClientGeocoder();
162
		this.geocoder = new GClientGeocoder();
164
	}
163
	}
165
	catch (ex) {
164
	catch (ex) {
166
	}
165
	}
167
	this.render();
166
	this.render();
168
	this.setControls();
167
	this.setControls();
169
}});
168
}});
170
 
169