author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Fri, 22 Mar 2013 20:10:19 +0100 | |
changeset 8773 | 21edcb0a5ed7 |
parent 8163 | f0a0bfc4a0c8 |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
1 |
/** |
0 | 2 |
* :organization: Logilab |
5767
1d811df051c2
[packaging] MANIFEST.in cleanups, update js/css copyright, remove no more used files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
553
diff
changeset
|
3 |
* :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 4 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 |
*/ |
|
6 |
||
7 |
Widgets.GMapWidget = defclass('GMapWidget', null, { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
8 |
__init__: function(wdgnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
9 |
// Assume we have imported google maps JS |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
10 |
if (GBrowserIsCompatible()) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
11 |
var uselabelstr = wdgnode.getAttribute('cubicweb:uselabel'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
12 |
var uselabel = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
13 |
if (uselabelstr) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
14 |
if (uselabelstr == 'True') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
15 |
uselabel = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
16 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
17 |
else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
18 |
uselabel = false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
19 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
20 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
21 |
var map = new GMap2(wdgnode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
22 |
map.addControl(new GSmallMapControl()); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
23 |
var jsonurl = wdgnode.getAttribute('cubicweb:loadurl'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
24 |
var self = this; // bind this to a local variable |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
25 |
jQuery.getJSON(jsonurl, function(geodata) { |
8154
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
26 |
var zoomLevel; |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
27 |
var center; |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
28 |
var latlngbounds = new GLatLngBounds( ); |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
29 |
for (var i = 0; i < geodata.markers.length; i++) { |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
30 |
var marker = geodata.markers[i]; |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
31 |
var latlng = new GLatLng(marker.latitude, marker.longitude); |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
32 |
latlngbounds.extend( latlng ); |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
33 |
} |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
34 |
if (geodata.zoomlevel) { |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
35 |
zoomLevel = geodata.zoomlevel; |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
36 |
} else { |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
37 |
zoomLevel = map.getBoundsZoomLevel( latlngbounds ) - 1; |
8163
f0a0bfc4a0c8
gmap: fix regression from 151058945234
Julien Cristau <julien.cristau@logilab.fr>
parents:
8154
diff
changeset
|
38 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
39 |
if (geodata.center) { |
8154
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
40 |
center = new GLatng(geodata.center.latitude, geodata.center.longitude); |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
41 |
} else { |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
42 |
center = latlngbounds.getCenter(); |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
43 |
} |
151058945234
gmap: set center and zoomlevel automatically (closes #2144255)
Julien Cristau <julien.cristau@logilab.fr>
parents:
5774
diff
changeset
|
44 |
map.setCenter(center, zoomLevel); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
45 |
for (var i = 0; i < geodata.markers.length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
46 |
var marker = geodata.markers[i]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
47 |
self.createMarker(map, marker, i + 1, uselabel); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
48 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
49 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
50 |
jQuery(wdgnode).after(this.legendBox); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
51 |
} else { // incompatible browser |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
52 |
jQuery.unload(GUnload); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
53 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
54 |
}, |
0 | 55 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
56 |
createMarker: function(map, marker, i, uselabel) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
57 |
var point = new GLatLng(marker.latitude, marker.longitude); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
58 |
var icon = new GIcon(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
59 |
icon.image = marker.icon[0]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
60 |
icon.iconSize = new GSize(marker.icon[1][0], marker.icon[1][1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
61 |
icon.iconAnchor = new GPoint(marker.icon[2][0], marker.icon[2][1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
62 |
if (marker.icon[3]) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
63 |
icon.shadow4 = marker.icon[3]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
64 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
65 |
if (typeof LabeledMarker == "undefined") { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
66 |
var gmarker = new GMarker(point, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
67 |
icon: icon, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
68 |
title: marker.title |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
69 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
70 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
71 |
var gmarker = new LabeledMarker(point, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
72 |
icon: icon, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
73 |
title: marker.title, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
74 |
labelText: uselabel ? '<strong>' + i + '</strong>': '', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
75 |
labelOffset: new GSize(2, - 32) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
76 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
77 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
78 |
map.addOverlay(gmarker); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
79 |
GEvent.addListener(gmarker, 'click', function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
80 |
jQuery.post(marker.bubbleUrl, function(data) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
81 |
map.openInfoWindowHtml(point, data); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
82 |
}); |
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
|
83 |
}); |
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
|
84 |
} |
0 | 85 |
|
86 |
}); |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
553
diff
changeset
|
87 |