changeset 65:2f477270cc0c

adding layers to maps works now
author casties
date Tue, 09 Nov 2010 20:49:36 +0100
parents 3f6e32265c53
children da0556e4fa10
files RestDbGisApi.py gis_gui/blocks/map.html.pt gis_gui/blocks/map.js gis_gui/lib/blocks.js
diffstat 4 files changed, 69 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbGisApi.py	Tue Nov 09 16:29:56 2010 +0100
+++ b/RestDbGisApi.py	Tue Nov 09 20:49:36 2010 +0100
@@ -217,6 +217,8 @@
         # convert data
         kmlData = []
         for dataset in data['rows']:
+            xCoord = 0.0
+            yCoord = 0.0
             if gisIdIdx is not None:
                 gisID = dataset[gisIdIdx]
                 coords=self.getPointForChGisId(gisID)
--- a/gis_gui/blocks/map.html.pt	Tue Nov 09 16:29:56 2010 +0100
+++ b/gis_gui/blocks/map.html.pt	Tue Nov 09 20:49:36 2010 +0100
@@ -56,10 +56,9 @@
     <div class="dialog add_layer_select" title="Select Layer" style="display:none">
       <p>Select layer to add to map:<br>
       <form action="javascript:null">
-        <select>
-          <option>some layer</option>
+        <select size="5" name="add_layer_select" class="add_layer_select">
+          <option>[loading...]</option>
         </select>
-        <input type="button" value"Select"/>
       </p>
     </div>
 
--- a/gis_gui/blocks/map.js	Tue Nov 09 16:29:56 2010 +0100
+++ b/gis_gui/blocks/map.js	Tue Nov 09 20:49:36 2010 +0100
@@ -19,6 +19,12 @@
         // load map
         block.updateMap(be,block.params);
         
+        // add layer button
+        $(be).find(".layer_add_button").click(function() {
+            console.debug("layer add");
+            params = block.readMapParams();
+            block.addMapLayer(be,params);
+        });
         // update button
         $(be).find(".map_update_button").click(function() {
             console.debug("map update");
@@ -37,6 +43,7 @@
     for (var i = 0; i < layers.length; i++) {
         layers[i].idx = i;
     }
+    return this.params;
 };
 
 guiBlocks.Block.prototype.showMapParams = function(elem,params) {
@@ -44,12 +51,12 @@
     if (typeof(elem) == 'undefined') {
         elem = this.element;
     }
-    if (typeof(param) == 'undefined') {
+    if (typeof(params) == 'undefined') {
         params = this.params;
     }
     var layers = params.map_layers;
     // remove old info
-    $(elem).remove(".layer_info");
+    $(elem).find(".map_layer_table .layer_info").remove();
     // write new info
     if (layers.length > 0) {
         var tmpl = $(elem).find(".layer_info_tmpl").tmpl(layers);
@@ -62,7 +69,7 @@
     if (typeof(elem) == 'undefined') {
         elem = this.element;
     }
-    if (typeof(param) == 'undefined') {
+    if (typeof(params) == 'undefined') {
         params = this.params;
     }
     params.name = $(elem).find(".map_name").val();
@@ -76,6 +83,12 @@
 };
 
 guiBlocks.Block.prototype.updateMap = function(elem,map_params) {
+    if (! elem != null) {
+        elem = this.element;
+    }
+    if (! map_params != null) {
+        map_params = this.params;
+    }
     // update and draw the google map
     var le = $(elem).find(".map_box").get(0);
     // create empty map
@@ -122,3 +135,43 @@
         });
     }
 };
+
+guiBlocks.Block.prototype.addMapLayer = function(elem,params) {
+    var block = this;
+    // show list of layers, select and add to map
+    var layerList = [];
+    var $dlg = $(elem).find(".dialog.add_layer_select");
+    var $sel = $dlg.find("select.add_layer_select");
+    // fill list of layers
+    blocks.loadListOfItems("test1", "layer", function(data) {
+        console.debug("add layer list of items=",data);
+        layerList = data;
+        $sel.empty();
+        for (var i=0; i < data.length; i++) {
+            var key = data[i].key;
+            var val = data[i].val;
+            var name = val.name;
+            console.debug("layer",i," key=",key," value=",name);
+            $sel.append('<option value="'+key+'">'+name+'</option>');
+        }
+    });
+    console.debug("dlg=",$dlg);
+    $dlg.dialog({
+        buttons: {
+            "Ok": function() {
+                var layerName = $(this).find(".add_layer_select").val();
+                $(this).dialog("close");
+                var layerParams = jQuery.grep(layerList, function(x){return (x.key == layerName);})[0].val;
+                console.debug("addlayerok params=",layerParams);
+                params = block.appendMapLayer(layerParams);
+                block.showMapParams(elem, params);
+                params = block.readMapParams();
+                block.updateMap(elem,params);
+            }, 
+            "Cancel": function() { 
+                $(this).dialog("close"); 
+            } 
+        }
+    });
+};
+
--- a/gis_gui/lib/blocks.js	Tue Nov 09 16:29:56 2010 +0100
+++ b/gis_gui/lib/blocks.js	Tue Nov 09 20:49:36 2010 +0100
@@ -5,8 +5,8 @@
     console = {
 	log : function(){},
 	debug : function(){},
-	error : function(){},
-    }
+	error : function(){}
+    };
 }
 
 function defined(x) {
@@ -32,7 +32,7 @@
     this.id = id; // the blocks html id
     this.element = element; // the html dom element
     this.storeId = null; // the id in online storage
-    this.params = new Object(); // parameters to store
+    this.params = {}; // parameters to store
     return this;
 };
 
@@ -61,7 +61,7 @@
         } else {
         	// default after load function
         	$(this).fadeIn();
-        };
+        }
     	
     });
     // create new Block object
@@ -78,7 +78,7 @@
     // add to list of blocks
     this.blocks.push(block);
     return block;
-}
+};
 
 guiBlocks.prototype.getBlock = function(id) {
     for (b in this.blocks) {
@@ -87,7 +87,7 @@
 	}
     }
     return null;
-}
+};
 
 /*
 guiBlocks.prototype.getStoreItem = function(tag,type,item) {
@@ -100,7 +100,7 @@
     // loads list of id and type objects and executes callback function
     var url = "../db/RESTjson/db/public/gui_objects/"+escape(storeTag)+"/"+storeType+"?recursive=true";
     jQuery.getJSON(url,callback);
-}
+};
 
 
 guiBlocks.Block.prototype.storeBlock = function(storeTag) {
@@ -160,10 +160,10 @@
     // TitleBar Close
     $("div.block div.titlebar div.close_button").live("click", function(e){
 	segment = $(this).parents().filter("div.block");
-	segment.fadeOut(function(){ segment.remove()});
+	segment.fadeOut(function(){ segment.remove();});
       });
 
-};
+}
 
 
 function randomString() {