Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

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