[Checkins] SVN: keas.googlemap/trunk/src/keas/googlemap/ get the demo working again and use json to encode some javascript data structures.

Paul Carduner paulcarduner at gmail.com
Mon Oct 13 02:31:01 EDT 2008


Log message for revision 92090:
  get the demo working again and use json to encode some javascript data structures.

Changed:
  U   keas.googlemap/trunk/src/keas/googlemap/apikey.py
  U   keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py
  U   keas.googlemap/trunk/src/keas/googlemap/demo/configure.zcml
  U   keas.googlemap/trunk/src/keas/googlemap/demo/demo.pt
  U   keas.googlemap/trunk/src/keas/googlemap/demo/template.pt
  U   keas.googlemap/trunk/src/keas/googlemap/geocode.py
  A   keas.googlemap/trunk/src/keas/googlemap/jsoncompat.py

-=-
Modified: keas.googlemap/trunk/src/keas/googlemap/apikey.py
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/apikey.py	2008-10-13 02:52:16 UTC (rev 92089)
+++ keas.googlemap/trunk/src/keas/googlemap/apikey.py	2008-10-13 06:31:00 UTC (rev 92090)
@@ -48,10 +48,17 @@
         zope.interface.Interface,
         zope.interface.Interface)
 
+    srcURLTemplate = "http://maps.google.com/maps?file=api&v=2&key=%s&async=2&callback=keas_googlemap_maploader"
+
     def render(self):
         domainName = urlparse.urlparse(self.request.getURL())[1].split(':')[0]
         apikey = zope.component.queryUtility(interfaces.IGoogleMapAPIKey, domainName)
         if apikey is None:
             return '<!-- Google Maps API Key not found for %s -->' % domainName
-        srcURL = "http://maps.google.com/maps?file=api&v=2&key=%s&async=2&callback=keas_googlemap_maploader" % apikey.key
+        srcURL = self.srcURLTemplate % apikey.key
         return '<script type="text/javascript"\nsrc="%s">\n</script>' % srcURL
+
+class StaticAPIKeyViewlet(APIKeyViewlet):
+    """A viewlet for static pages."""
+
+    srcURLTemplate = "http://maps.google.com/maps?file=api&v=2&key=%s"

Modified: keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py	2008-10-13 02:52:16 UTC (rev 92089)
+++ keas.googlemap/trunk/src/keas/googlemap/browser/__init__.py	2008-10-13 06:31:00 UTC (rev 92090)
@@ -27,6 +27,7 @@
 
 from keas.googlemap.geocode import Geocode
 from keas.googlemap.browser import interfaces
+from keas.googlemap import jsoncompat as json
 
 
 class IGoogleMapBrowserLayer(IBrowserRequest):
@@ -92,12 +93,11 @@
         return self.template(view=self)
 
     def javascript(self):
-        markerString = '['
-        for marker in self.markers:
-            markerString += '{latitude:%s, longitude:%s, html:%s},' % (marker.geocode.latitude,
-                                                                         marker.geocode.longitude,
-                                                                         jsString(marker.html))
-        markerString += ']'
+        markerString = json.encode(
+            [dict(latitude=marker.geocode.latitude,
+                  longitude=marker.geocode.longitude,
+                  html=marker.html)
+             for marker in self.markers])
         return """
           var keas_googlemap_maploader = function(){
                keas.googlemap.initialize({id:'%(id)s',
@@ -111,13 +111,6 @@
                      type=self.type,
                      markers=markerString)
 
-def jsString(s):
-    """Returns the string as a one line javascript representation."""
-    if type(s) is unicode:
-        return repr(s)[1:]
-    return repr(s)
-
-
 class GoogleMapBrowserView(BrowserView, GoogleMap):
 
     def __init__(self, context, request, **kwargs):

Modified: keas.googlemap/trunk/src/keas/googlemap/demo/configure.zcml
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/demo/configure.zcml	2008-10-13 02:52:16 UTC (rev 92089)
+++ keas.googlemap/trunk/src/keas/googlemap/demo/configure.zcml	2008-10-13 06:31:00 UTC (rev 92090)
@@ -46,19 +46,31 @@
       />
 
   <browser:viewlet
+      name="googleMapJS"
+      manager=".browser.IJavaScript"
+      class="keas.googlemap.browser.GoogleMapJavaScriptViewlet"
+      permission="zope.Public"
+      layer=".interfaces.IGoogleMapSkin"
+      wieght="1"
+      />
+
+  <browser:viewlet
       name="googleMapsAPIKey"
       manager=".browser.IJavaScript"
-      class="keas.googlemap.apikey.APIKeyViewlet"
+      class="keas.googlemap.apikey.StaticAPIKeyViewlet"
       permission="zope.Public"
       layer=".interfaces.IGoogleMapSkin"
+      weight="5"
       />
 
   <browser:viewlet
-      name="googleMapJS"
+      name="markermanager.js"
       manager=".browser.IJavaScript"
-      class="keas.googlemap.browser.GoogleMapJavaScriptViewlet"
+      class="keas.googlemap.browser.GoogleMapMarkersViewletLocal"
       permission="zope.Public"
       layer=".interfaces.IGoogleMapSkin"
+      weight="7"
       />
 
+
 </configure>

Modified: keas.googlemap/trunk/src/keas/googlemap/demo/demo.pt
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/demo/demo.pt	2008-10-13 02:52:16 UTC (rev 92089)
+++ keas.googlemap/trunk/src/keas/googlemap/demo/demo.pt	2008-10-13 06:31:00 UTC (rev 92090)
@@ -14,3 +14,8 @@
     </td>
   </tr>
 </table>
+<script type="text/javascript">
+$(document).ready(function(){
+keas_googlemap_maploader();
+});
+</script>
\ No newline at end of file

Modified: keas.googlemap/trunk/src/keas/googlemap/demo/template.pt
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/demo/template.pt	2008-10-13 02:52:16 UTC (rev 92089)
+++ keas.googlemap/trunk/src/keas/googlemap/demo/template.pt	2008-10-13 06:31:00 UTC (rev 92090)
@@ -6,13 +6,10 @@
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
     <meta http-equiv="cache-control" content="no-cache" />
     <meta http-equiv="pragma" content="no-cache" />
-    <script type="text/javascript" src="++resource++jquery.js"></script>
-    <script type="text/javascript" src="++resource++keas.googlemap.js"></script>
-    <script tal:replace="structure provider:IJavaScript"> </script>
-    <script tal:replace="structure provider:ICSS"> </script>
     <script type="text/javascript"
-	    src="http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/release/src/markermanager.js">
+            tal:attributes="src context/++resource++jquery.js">
     </script>
+    <style tal:replace="structure provider:ICSS"> </style>
     <style type="text/css">
       body{
         font-size: small;
@@ -33,5 +30,6 @@
   <body>
     <div tal:replace="structure provider:pagelet"/>
   </body>
+  <script tal:replace="structure provider:IJavaScript"> </script>
 
 </html>

Modified: keas.googlemap/trunk/src/keas/googlemap/geocode.py
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/geocode.py	2008-10-13 02:52:16 UTC (rev 92089)
+++ keas.googlemap/trunk/src/keas/googlemap/geocode.py	2008-10-13 06:31:00 UTC (rev 92090)
@@ -19,7 +19,6 @@
 # Interesting Python library for geocoding here:
 # http://code.google.com/p/geolocator/source/browse/trunk/geolocator/gislib.py
 
-import simplejson
 import urllib
 from math import asin, sqrt, cos, sin, pi
 
@@ -29,8 +28,8 @@
 from zope.app.container.btree import BTreeContainer
 import zope.annotation
 
-from keas.googlemap import interfaces
-from keas.googlemap import apikey
+from keas.googlemap import interfaces, apikey
+from keas.googlemap import jsoncompat as json
 
 GEOCODE_BASE = 'http://maps.google.com/maps/geo'
 
@@ -82,7 +81,7 @@
              'output' : 'json',
              'q'      : geoQuery.query }
     url = GEOCODE_BASE + '?' + urllib.urlencode(dict)
-    info = simplejson.load(urllib.urlopen(url))
+    info = json.decode(urllib.urlopen(url).read())
     if info['Status']['code'] == 200:
         coords = info['Placemark'][0]['Point']['coordinates']
         return Geocode(coords[1], coords[0])

Added: keas.googlemap/trunk/src/keas/googlemap/jsoncompat.py
===================================================================
--- keas.googlemap/trunk/src/keas/googlemap/jsoncompat.py	                        (rev 0)
+++ keas.googlemap/trunk/src/keas/googlemap/jsoncompat.py	2008-10-13 06:31:00 UTC (rev 92090)
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Google Map JSON Support
+
+$Id$
+"""
+
+try:
+    import cjson
+    encode = cjson.encode
+    decode = cjson.decode
+except ImportError:
+    try:
+        import json #python 2.6
+        encode = json.dumps
+        decode = json.loads
+    except ImportError:
+        import simplejson
+        encode = simplejson.dumps
+        decode = simplejson.loads


Property changes on: keas.googlemap/trunk/src/keas/googlemap/jsoncompat.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list