changeset 225:640007b1a424

Merge with 55b3dce54b423196c69c40e9d2ea8d9d3f32c96f
author casties
date Fri, 08 Apr 2011 14:43:16 +0200
parents b2dd655793f4 (current diff) 55b3dce54b42 (diff)
children
files
diffstat 1 files changed, 23 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/gis_gui/blocks/map.js	Thu Apr 07 11:49:11 2011 +0200
+++ b/gis_gui/blocks/map.js	Fri Apr 08 14:43:16 2011 +0200
@@ -72,7 +72,6 @@
 
 guiBlocks.Block.prototype.showMapParams = function (elem, params) {
     // create html with layer parameters from params
-    var i, layers, $tmpl, lp, idx;
     var block = this;
     if (elem == null) {
         elem = this.element;
@@ -82,30 +81,33 @@
     }
     var $elem = $(elem);
     $elem.find(".map_name").val(params.name);
-    layers = params.map_layers;
+    var layers = params.map_layers;
     // remove old info
     $(elem).find(".map_layer_table .layer_info").remove();
     // write new info
     if (layers.length > 0) {
-        $tmpl = $elem.find(".layer_info_tmpl").tmpl(layers);
+        var $tmpl = $elem.find(".layer_info_tmpl").tmpl(layers);
         $elem.find(".map_layer_header").after($tmpl);
         // arm edit and delete buttons
-        for (i = 0; i < layers.length; ++i) {
-            lp = layers[i].layer;
-            idx = layers[i].idx;
-            console.debug("showmapparams lp=", lp, " idx=", idx);
-            $tmpl.find(".layer_edit_"+idx).click(function () {
-                var param = lp;
-                console.debug("open layer ",idx);
-                blocks.addLayerBlock("blocks/layer.html?table="+escape(lp.table),"layer", param);
-            });
-            $tmpl.find(".layer_delete_"+idx).click(function () {
-                var layerIdx = idx;
-                console.debug("del layer ",layerIdx);
-                params = block.deleteMapLayer(layerIdx);
-                block.showMapParams(elem, params);
-                block.updateMap(elem, params);
-            });
+        for (var i = 0; i < layers.length; ++i) {
+            // create closure to make sure we get copies of the variables
+            (function () {
+                var lp = layers[i].layer;
+                var idx = layers[i].idx;
+                console.debug("showmapparams lp=", lp, " idx=", idx);
+                $tmpl.find(".layer_edit_"+idx).click(function () {
+                    var param = lp;
+                    console.debug("open layer ",idx," param=", param);
+                    blocks.addLayerBlock("blocks/layer.html?table="+escape(lp.table),"layer", param);
+                });
+                $tmpl.find(".layer_delete_"+idx).click(function () {
+                    var layerIdx = idx;
+                    console.debug("del layer ",layerIdx);
+                    params = block.deleteMapLayer(layerIdx);
+                    block.showMapParams(elem, params);
+                    block.updateMap(elem, params);
+                });
+            })();
         }
     }
 };
@@ -138,7 +140,7 @@
     // update and draw the google map
     var le = $(elem).find(".map_box").get(0);
     // create empty map
-    if (google != null) {
+    if (typeof google !== "undefined") {
         var latlng = new google.maps.LatLng(29, 116);
         var mapOpts = {
                 zoom: 5,
@@ -179,7 +181,7 @@
                 return;
             }
             // render layer
-            if (google != null) {
+            if (typeof google !== "undefined") {
                 var newMarker=new google.maps.KmlLayer(kmlURL);
                 console.debug("new marker layer=",newMarker," map=",map);
                 newMarker.setMap(map);