[Checkins] SVN: keas.googlemap/trunk/ Add a check for multiple markers with popupOnLoad == True.
Dan Korostelev
nadako at gmail.com
Fri Nov 7 04:50:05 EST 2008
Log message for revision 92826:
Add a check for multiple markers with popupOnLoad == True.
Pass the number of marker with popupOnLoad to javascript so we don't iterate over all markers once again.
Changed:
U keas.googlemap/trunk/CHANGES.txt
U keas.googlemap/trunk/src/keas/googlemap/browser/README.txt
U keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py
U keas.googlemap/trunk/src/keas/googlemap/browser/keas.googlemap.js
U keas.googlemap/trunk/src/keas/googlemap/demo/browser.py
-=-
Modified: keas.googlemap/trunk/CHANGES.txt
===================================================================
--- keas.googlemap/trunk/CHANGES.txt 2008-11-07 09:19:59 UTC (rev 92825)
+++ keas.googlemap/trunk/CHANGES.txt 2008-11-07 09:50:03 UTC (rev 92826)
@@ -18,7 +18,7 @@
- Feature: markers has now a popupOnLoad attribute that can be set to True
to get marker's info window displayed when page is loaded, not only when
- marker is clicked.
+ marker is clicked. Note that only one marker can have popupOnLoad == True.
Version 0.5.0 (2008-07-28)
--------------------------
Modified: keas.googlemap/trunk/src/keas/googlemap/browser/README.txt
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/browser/README.txt 2008-11-07 09:19:59 UTC (rev 92825)
+++ keas.googlemap/trunk/src/keas/googlemap/browser/README.txt 2008-11-07 09:50:03 UTC (rev 92826)
@@ -78,6 +78,7 @@
zoom:1,
type:G_NORMAL_MAP,
controls:["GLargeMapControl", "GMapTypeControl"],
+ popup_marker:null,
markers:[]});
};
$(document).unload( function() {GUnload();} );
@@ -111,7 +112,8 @@
zoom:1,
type:G_NORMAL_MAP,
controls:["GLargeMapControl", "GMapTypeControl"],
- markers:[{"popup_on_load": false, "latitude": 37.2..., "html": "\n<h1>My Marker</h1>\n<p>This is my marker</p>\n", "longitude": -23.1...}]});
+ popup_marker:null,
+ markers:[{"latitude": 37.2..., "html": "\n<h1>My Marker</h1>\n<p>This is my marker</p>\n", "longitude": -23.1...}]});
};
$(document).unload( function() {GUnload();} );
</script>
@@ -133,12 +135,26 @@
zoom:1,
type:G_NORMAL_MAP,
controls:["GLargeMapControl", "GMapTypeControl"],
- markers:[{"popup_on_load": true, "latitude": 37.2..., "html": "\n<h1>My Marker</h1>\n<p>This is my marker</p>\n", "longitude": -23.1...}]});
+ popup_marker:0,
+ markers:[{"latitude": 37.2..., "html": "\n<h1>My Marker</h1>\n<p>This is my marker</p>\n", "longitude": -23.1...}]});
};
$(document).unload( function() {GUnload();} );
</script>
<BLANKLINE>
+If we'll try to add one more marker with popupOnLoad == True, the map's ``render``
+method will raise a ValueError:
+
+ >>> marker = browser.Marker(geocode=geocode.Geocode(37.231,-23.123),
+ ... html=u'Test',
+ ... popupOnLoad=True)
+
+ >>> gmap.markers.append(marker)
+ >>> print gmap.render()
+ Traceback (most recent call last):
+ ...
+ ValueError: Only one marker can have popup on load at the same time
+
To properly display markers, you will need to include the
markermanager.js utility script from google. There is a viewlet that
renders the appropriate script tag.
Modified: keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py 2008-11-07 09:19:59 UTC (rev 92825)
+++ keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py 2008-11-07 09:50:03 UTC (rev 92826)
@@ -95,18 +95,25 @@
return self.template(view=self)
def javascript(self):
- markerString = json.encode(
- [dict(latitude=marker.geocode.latitude,
- longitude=marker.geocode.longitude,
- html=marker.html,
- popup_on_load=marker.popupOnLoad)
- for marker in self.markers])
+ markers = []
+ popup_marker = None
+ for i, marker in enumerate(self.markers):
+ if marker.popupOnLoad:
+ if popup_marker is not None:
+ raise ValueError('Only one marker can have popup on load at the same time')
+ else:
+ popup_marker = i
+ markers.append(dict(latitude=marker.geocode.latitude,
+ longitude=marker.geocode.longitude,
+ html=marker.html))
+ markerString = json.encode(markers)
return """
var keas_googlemap_maploader = function(){
keas.googlemap.initialize({id:'%(id)s',
zoom:%(zoom)s,
type:%(type)s,
controls:%(controls)s,
+ popup_marker:%(popup_marker)s,
markers:%(markers)s});
};
$(document).unload( function() {GUnload();} );
@@ -114,6 +121,7 @@
zoom=self.zoom,
type=self.type,
controls=json.encode(self.controls),
+ popup_marker=json.encode(popup_marker),
markers=markerString)
class GoogleMapBrowserView(BrowserView, GoogleMap):
Modified: keas.googlemap/trunk/src/keas/googlemap/browser/keas.googlemap.js
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/browser/keas.googlemap.js 2008-11-07 09:19:59 UTC (rev 92825)
+++ keas.googlemap/trunk/src/keas/googlemap/browser/keas.googlemap.js 2008-11-07 09:50:03 UTC (rev 92826)
@@ -6,6 +6,7 @@
zoom: 12, //the desired zoom level,
type: G_NORMAL_MAP, //a google maps map type string.
controls: ['GLargeMapControl'],
+ popup_marker: null, // number of the marker with popup or null
markers: [{latitude: 3.1234,
longitude: 4.52342,
html: "stuff that appears in the window",
@@ -43,11 +44,10 @@
mgr.refresh();
- for (var i=0; i < markers.length; i++){
- var conf = config.markers[i];
- if (conf.popup_on_load)
- markers[i].openInfoWindowHtml(conf.html);
- }
+ if (config.popup_marker != null) {
+ var i = config.popup_marker;
+ markers[i].openInfoWindowHtml(config.markers[i].html)
+ }
}
}
Modified: keas.googlemap/trunk/src/keas/googlemap/demo/browser.py
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/demo/browser.py 2008-11-07 09:19:59 UTC (rev 92825)
+++ keas.googlemap/trunk/src/keas/googlemap/demo/browser.py 2008-11-07 09:50:03 UTC (rev 92826)
@@ -88,6 +88,10 @@
return marker
def add(self, obj):
+ if obj.popupOnLoad:
+ for marker in self.markers:
+ if marker.popupOnLoad:
+ marker.popupOnLoad = False
self.markers.append(obj)
def nextURL(self):
More information about the Checkins
mailing list