Mercurial > hg > ChinaGisRestApi
changeset 223:55b3dce54b42
fixed bug with edit layer from map.
closure issue, there may be more...
author | casties |
---|---|
date | Fri, 08 Apr 2011 09:33:12 +0200 |
parents | b636b0417aab |
children | 640007b1a424 |
files | gis_gui/blocks/map.js |
diffstat | 1 files changed, 23 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/gis_gui/blocks/map.js Fri Apr 01 10:53:06 2011 +0200 +++ b/gis_gui/blocks/map.js Fri Apr 08 09:33:12 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);