|
1 /* |
|
2 * :organization: Logilab |
|
3 * :copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
4 * :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
5 * |
|
6 * |
|
7 */ |
|
8 |
|
9 Widgets.GMapWidget = defclass('GMapWidget', null, { |
|
10 __init__: function(wdgnode) { |
|
11 // Assume we have imported google maps JS |
|
12 if (GBrowserIsCompatible()) { |
|
13 var uselabelstr = wdgnode.getAttribute('cubicweb:uselabel'); |
|
14 var uselabel = true; |
|
15 if (uselabelstr){ |
|
16 if (uselabelstr == 'True'){ |
|
17 uselabel = true; |
|
18 } |
|
19 else{ |
|
20 uselabel = false; |
|
21 } |
|
22 } |
|
23 var map = new GMap2(wdgnode); |
|
24 map.addControl(new GSmallMapControl()); |
|
25 var jsonurl = wdgnode.getAttribute('cubicweb:loadurl'); |
|
26 var self = this; // bind this to a local variable |
|
27 jQuery.getJSON(jsonurl, function(geodata) { |
|
28 if (geodata.center) { |
|
29 var zoomLevel = 8; // FIXME arbitrary ! |
|
30 map.setCenter(new GLatLng(geodata.center.latitude, geodata.center.longitude), |
|
31 zoomLevel); |
|
32 } |
|
33 for (var i=0; i<geodata.markers.length; i++) { |
|
34 var marker = geodata.markers[i]; |
|
35 self.createMarker(map, marker, i+1, uselabel); |
|
36 } |
|
37 }); |
|
38 jQuery(wdgnode).after(this.legendBox); |
|
39 } else { // incompatible browser |
|
40 jQuery.unload(GUnload); |
|
41 } |
|
42 }, |
|
43 |
|
44 createMarker: function(map, marker, i, uselabel) { |
|
45 var point = new GLatLng(marker.latitude, marker.longitude); |
|
46 var icon = new GIcon(); |
|
47 icon.image = marker.icon[0]; |
|
48 icon.iconSize = new GSize(marker.icon[1][0], marker.icon[1][1]) ; |
|
49 icon.iconAnchor = new GPoint(marker.icon[2][0], marker.icon[2][1]); |
|
50 if(marker.icon[3]){ |
|
51 icon.shadow4 = marker.icon[3]; |
|
52 } |
|
53 |
|
54 var gmarker = new LabeledMarker(point, { |
|
55 icon: icon, |
|
56 title: marker.title, |
|
57 labelText: uselabel?'<strong>' + i + '</strong>':'', |
|
58 labelOffset: new GSize(2, -32) |
|
59 }); |
|
60 map.addOverlay(gmarker); |
|
61 GEvent.addListener(gmarker, 'click', function() { |
|
62 jQuery.post(marker.bubbleUrl, function(data) { |
|
63 map.openInfoWindowHtml(point, data); |
|
64 }); |
|
65 }); |
|
66 }, |
|
67 |
|
68 appendLegendItem: function(marker, i) { |
|
69 var ul = this.legendBox.firstChild; |
|
70 ul.appendChild(LI(null, [SPAN({'class': "itemNo"}, i), |
|
71 SPAN(null, marker.title)])); |
|
72 } |
|
73 |
|
74 }); |