Commits

Ralph Bean committed 40372d4

Added a properties callback. Ability to draw on the dots.

Comments (0)

Files changed (4)

tw2/polymaps/samples.py

         super(DemoPolyMap, self).prepare()
         self.resources.append(custom_css_1)
 
+    properties_callback = """function (_layer) {
+        _layer.on("load", org.polymaps.stylist()
+        .title(function(d) { return "Lon/lat:  " + d.properties.ATTR }));
+        return _layer
+    }"""
+
     @classmethod
     @geojsonify
     def request(cls, req):
         json = geojson.FeatureCollection(
             features=[
                 geojson.Feature(
-                    geometry=geojson.Point([mod(lon), mod(lat)])
+                    geometry=geojson.Point([mod(lon), mod(lat)]),
+                    properties={'ATTR': "%s, %s" % (mod(lon), mod(lat))},
                 ) for i in range(n)
 
             ]

tw2/polymaps/static/custom/js/tw2.polymaps.js

         return map;
 }
 
-function setupPolymapData(map, data_url, timeout)
+function setupPolymapData(map, data_url, timeout, properties_callback)
 {
         if ( data_url ) {
                 var layer = po.geoJson().url(data_url);
+                if ( properties_callback ) {
+                        layer = properties_callback(layer);
+                }
                 map.add(layer);
                 if ( timeout != 0 ) {
                         setTimeout(function(){

tw2/polymaps/templates/polymap.mak

 	% else:
 	map = setupPolymapData(map,
 				${w.j('data_url')},
-				${w.j('layer_lifetime')}
+				${w.j('layer_lifetime')},
+				${w.properties_callback}
 	);
 	% endif
 </script>

tw2/polymaps/widgets.py

     layer_lifetime = twc.Param(
         "Time in miliseconds until layers are removed.  0 means 'never'.",
         default=0)
+    properties_callback = twc.Param(
+        "Javascript callback.  Takes a layer and returns a layer",
+        default="function(layer){return layer;}"
+    )
 
     cloudmade_api_key = twc.Param("""Developer API key for cloudmade tiles.""")
     cloudmade_tileset = twc.Param(