Subversion Repositories Applications.papyrus

Rev

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

Rev 1372 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.YahooMap");
13
dojo.provide("dojo.widget.YahooMap");
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.widget.HtmlWidget");
17
dojo.require("dojo.widget.HtmlWidget");
16
(function () {
18
(function () {
17
	var yappid = djConfig["yAppId"] || djConfig["yahooAppId"] || "dojotoolkit";
19
	var yappid = djConfig["yAppId"] || djConfig["yahooAppId"] || "dojotoolkit";
18
	if (!dojo.hostenv.post_load_) {
20
	if (!dojo.hostenv.post_load_) {
19
		if (yappid == "dojotoolkit") {
21
		if (yappid == "dojotoolkit") {
20
			dojo.debug("please provide a unique Yahoo App ID in djConfig.yahooAppId when using the map widget");
22
			dojo.debug("please provide a unique Yahoo App ID in djConfig.yahooAppId when using the map widget");
21
		}
23
		}
22
		var tag = "<scr" + "ipt src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=" + yappid + "'></scri" + "pt>";
24
		var tag = "<scr" + "ipt src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=" + yappid + "'></scri" + "pt>";
23
		if (!dj_global["YMap"]) {
25
		if (!dj_global["YMap"]) {
24
			document.write(tag);
26
			document.write(tag);
25
		}
27
		}
26
	} else {
28
	} else {
27
		dojo.debug("cannot initialize map system after the page has been loaded! Please either manually include the script block provided by Yahoo in your page or require() the YahooMap widget before onload has fired");
29
		dojo.debug("cannot initialize map system after the page has been loaded! Please either manually include the script block provided by Yahoo in your page or require() the YahooMap widget before onload has fired");
28
	}
30
	}
29
})();
31
})();
30
dojo.widget.defineWidget("dojo.widget.YahooMap", dojo.widget.HtmlWidget, function () {
32
dojo.widget.defineWidget("dojo.widget.YahooMap", dojo.widget.HtmlWidget, function () {
31
	this.map = null;
33
	this.map = null;
32
	this.datasrc = "";
34
	this.datasrc = "";
33
	this.data = [];
35
	this.data = [];
34
	this.width = 0;
36
	this.width = 0;
35
	this.height = 0;
37
	this.height = 0;
36
	this.controls = ["zoomlong", "maptype", "pan"];
38
	this.controls = ["zoomlong", "maptype", "pan"];
37
}, {isContainer:false, templatePath:null, templateCssPath:null, findCenter:function (aPts) {
39
}, {isContainer:false, templatePath:null, templateCssPath:null, findCenter:function (aPts) {
38
	var start = new YGeoPoint(37, -90);
40
	var start = new YGeoPoint(37, -90);
39
	if (aPts.length == 0) {
41
	if (aPts.length == 0) {
40
		return start;
42
		return start;
41
	}
43
	}
42
	var minLat, maxLat, minLon, maxLon, cLat, cLon;
44
	var minLat, maxLat, minLon, maxLon, cLat, cLon;
43
	minLat = maxLat = aPts[0].Lat;
45
	minLat = maxLat = aPts[0].Lat;
44
	minLon = maxLon = aPts[0].Lon;
46
	minLon = maxLon = aPts[0].Lon;
45
	for (var i = 0; i < aPts.length; i++) {
47
	for (var i = 0; i < aPts.length; i++) {
46
		minLat = Math.min(minLat, aPts[i].Lat);
48
		minLat = Math.min(minLat, aPts[i].Lat);
47
		maxLat = Math.max(maxLat, aPts[i].Lat);
49
		maxLat = Math.max(maxLat, aPts[i].Lat);
48
		minLon = Math.min(minLon, aPts[i].Lon);
50
		minLon = Math.min(minLon, aPts[i].Lon);
49
		maxLon = Math.max(maxLon, aPts[i].Lon);
51
		maxLon = Math.max(maxLon, aPts[i].Lon);
50
	}
52
	}
51
	cLat = dojo.math.round((minLat + maxLat) / 2, 6);
53
	cLat = dojo.math.round((minLat + maxLat) / 2, 6);
52
	cLon = dojo.math.round((minLon + maxLon) / 2, 6);
54
	cLon = dojo.math.round((minLon + maxLon) / 2, 6);
53
	return new YGeoPoint(cLat, cLon);
55
	return new YGeoPoint(cLat, cLon);
54
}, setControls:function () {
56
}, setControls:function () {
55
	var methodmap = {maptype:"addTypeControl", pan:"addPanControl", zoomlong:"addZoomLong", zoomshort:"addZoomShort"};
57
	var methodmap = {maptype:"addTypeControl", pan:"addPanControl", zoomlong:"addZoomLong", zoomshort:"addZoomShort"};
56
	var c = this.controls;
58
	var c = this.controls;
57
	for (var i = 0; i < c.length; i++) {
59
	for (var i = 0; i < c.length; i++) {
58
		var controlMethod = methodmap[c[i].toLowerCase()];
60
		var controlMethod = methodmap[c[i].toLowerCase()];
59
		if (this.map[controlMethod]) {
61
		if (this.map[controlMethod]) {
60
			this.map[controlMethod]();
62
			this.map[controlMethod]();
61
		}
63
		}
62
	}
64
	}
63
}, parse:function (table) {
65
}, parse:function (table) {
64
	this.data = [];
66
	this.data = [];
65
	var h = table.getElementsByTagName("thead")[0];
67
	var h = table.getElementsByTagName("thead")[0];
66
	if (!h) {
68
	if (!h) {
67
		return;
69
		return;
68
	}
70
	}
69
	var a = [];
71
	var a = [];
70
	var cols = h.getElementsByTagName("td");
72
	var cols = h.getElementsByTagName("td");
71
	if (cols.length == 0) {
73
	if (cols.length == 0) {
72
		cols = h.getElementsByTagName("th");
74
		cols = h.getElementsByTagName("th");
73
	}
75
	}
74
	for (var i = 0; i < cols.length; i++) {
76
	for (var i = 0; i < cols.length; i++) {
75
		var c = cols[i].innerHTML.toLowerCase();
77
		var c = cols[i].innerHTML.toLowerCase();
76
		if (c == "long") {
78
		if (c == "long") {
77
			c = "lng";
79
			c = "lng";
78
		}
80
		}
79
		a.push(c);
81
		a.push(c);
80
	}
82
	}
81
	var b = table.getElementsByTagName("tbody")[0];
83
	var b = table.getElementsByTagName("tbody")[0];
82
	if (!b) {
84
	if (!b) {
83
		return;
85
		return;
84
	}
86
	}
85
	for (var i = 0; i < b.childNodes.length; i++) {
87
	for (var i = 0; i < b.childNodes.length; i++) {
86
		if (!(b.childNodes[i].nodeName && b.childNodes[i].nodeName.toLowerCase() == "tr")) {
88
		if (!(b.childNodes[i].nodeName && b.childNodes[i].nodeName.toLowerCase() == "tr")) {
87
			continue;
89
			continue;
88
		}
90
		}
89
		var cells = b.childNodes[i].getElementsByTagName("td");
91
		var cells = b.childNodes[i].getElementsByTagName("td");
90
		var o = {};
92
		var o = {};
91
		for (var j = 0; j < a.length; j++) {
93
		for (var j = 0; j < a.length; j++) {
92
			var col = a[j];
94
			var col = a[j];
93
			if (col == "lat" || col == "lng") {
95
			if (col == "lat" || col == "lng") {
94
				o[col] = parseFloat(cells[j].innerHTML);
96
				o[col] = parseFloat(cells[j].innerHTML);
95
			} else {
97
			} else {
96
				o[col] = cells[j].innerHTML;
98
				o[col] = cells[j].innerHTML;
97
			}
99
			}
98
		}
100
		}
99
		this.data.push(o);
101
		this.data.push(o);
100
	}
102
	}
101
}, render:function () {
103
}, render:function () {
102
	var pts = [];
104
	var pts = [];
103
	var d = this.data;
105
	var d = this.data;
104
	for (var i = 0; i < d.length; i++) {
106
	for (var i = 0; i < d.length; i++) {
105
		var pt = new YGeoPoint(d[i].lat, d[i].lng);
107
		var pt = new YGeoPoint(d[i].lat, d[i].lng);
106
		pts.push(pt);
108
		pts.push(pt);
107
		var icon = d[i].icon || null;
109
		var icon = d[i].icon || null;
108
		if (icon) {
110
		if (icon) {
109
			icon = new YImage(icon);
111
			icon = new YImage(icon);
110
		}
112
		}
111
		var m = new YMarker(pt, icon);
113
		var m = new YMarker(pt, icon);
112
		if (d[i].description) {
114
		if (d[i].description) {
113
			m.addAutoExpand("<div>" + d[i].description + "</div>");
115
			m.addAutoExpand("<div>" + d[i].description + "</div>");
114
		}
116
		}
115
		this.map.addOverlay(m);
117
		this.map.addOverlay(m);
116
	}
118
	}
117
	var c = this.findCenter(pts);
119
	var c = this.findCenter(pts);
118
	var z = this.map.getZoomLevel(pts);
120
	var z = this.map.getZoomLevel(pts);
119
	this.map.drawZoomAndCenter(c, z);
121
	this.map.drawZoomAndCenter(c, z);
120
}, initialize:function (args, frag) {
122
}, initialize:function (args, frag) {
121
	if (!YMap || !YGeoPoint) {
123
	if (!YMap || !YGeoPoint) {
122
		dojo.raise("dojo.widget.YahooMap: The Yahoo Map script must be included in order to use this widget.");
124
		dojo.raise("dojo.widget.YahooMap: The Yahoo Map script must be included in order to use this widget.");
123
	}
125
	}
124
	if (this.datasrc) {
126
	if (this.datasrc) {
125
		this.parse(dojo.byId(this.datasrc));
127
		this.parse(dojo.byId(this.datasrc));
126
	} else {
128
	} else {
127
		if (this.domNode.getElementsByTagName("table")[0]) {
129
		if (this.domNode.getElementsByTagName("table")[0]) {
128
			this.parse(this.domNode.getElementsByTagName("table")[0]);
130
			this.parse(this.domNode.getElementsByTagName("table")[0]);
129
		}
131
		}
130
	}
132
	}
131
}, postCreate:function () {
133
}, postCreate:function () {
132
	while (this.domNode.childNodes.length > 0) {
134
	while (this.domNode.childNodes.length > 0) {
133
		this.domNode.removeChild(this.domNode.childNodes[0]);
135
		this.domNode.removeChild(this.domNode.childNodes[0]);
134
	}
136
	}
135
	if (this.width > 0 && this.height > 0) {
137
	if (this.width > 0 && this.height > 0) {
136
		this.map = new YMap(this.domNode, YAHOO_MAP_REG, new YSize(this.width, this.height));
138
		this.map = new YMap(this.domNode, YAHOO_MAP_REG, new YSize(this.width, this.height));
137
	} else {
139
	} else {
138
		this.map = new YMap(this.domNode);
140
		this.map = new YMap(this.domNode);
139
	}
141
	}
140
	this.setControls();
142
	this.setControls();
141
	this.render();
143
	this.render();
142
}});
144
}});
143
 
145