author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Fri, 13 Nov 2009 15:36:09 +0100 | |
branch | stable |
changeset 3847 | 7cf2b338a8e7 |
parent 553 | c69eac8298c0 |
child 5658 | 7b9553a9db65 |
child 5767 | 1d811df051c2 |
permissions | -rw-r--r-- |
0 | 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) { |
|
553
c69eac8298c0
[gmap] zoom level is now a url parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
78
diff
changeset
|
29 |
var zoomLevel = geodata.zoomlevel; |
0 | 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 |
} |
|
78
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
53 |
if (typeof LabeledMarker == "undefined") { |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
54 |
var gmarker = new GMarker(point, {icon: icon, |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
55 |
title: marker.title}); |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
56 |
} else { |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
57 |
var gmarker = new LabeledMarker(point, { |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
58 |
icon: icon, |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
59 |
title: marker.title, |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
60 |
labelText: uselabel?'<strong>' + i + '</strong>':'', |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
61 |
labelOffset: new GSize(2, -32) |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
62 |
}); |
079c4d11a616
[javascript][gmap] only use LabeledMarker in google maps when the extension is loaded
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
63 |
} |
0 | 64 |
map.addOverlay(gmarker); |
65 |
GEvent.addListener(gmarker, 'click', function() { |
|
66 |
jQuery.post(marker.bubbleUrl, function(data) { |
|
67 |
map.openInfoWindowHtml(point, data); |
|
68 |
}); |
|
69 |
}); |
|
70 |
} |
|
71 |
||
72 |
}); |