annotate gis_gui/blocks/map.js @ 236:52aa589f4c4d

show line and polygon-layer
author fknauft
date Mon, 05 Sep 2011 11:38:20 +0200
parents ed0cb46fb936
children 35c3d0ce2914
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
1
67
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
2 guiBlocks.prototype.addMapBlock = function(url, baseId, params, firstLayer) {
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
3 var block = this.addBlock(url, baseId, params, function() {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
4 // function after add block finished
67
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
5 console.debug("in mapblock after block load!");
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
6 var be = block.element;
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
7 params = block.params;
67
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
8 block.type = "map";
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
9 params.type = "map";
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
10 if (params.map_layers == null) {
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
11 params.map_layers = [];
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
12 }
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
13 if (firstLayer != null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
14 block.appendMapLayer(firstLayer);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
15 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
16 // show block
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
17 block.showMapParams();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
18 $(be).fadeIn();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
19
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
20 // save map params in block.param -- too early
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
21 //params = block.readLayerParams();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
22
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
23 // load map
67
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
24 block.updateMap(be,params);
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
25
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
26 // add layer button
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
27 $(be).find(".layer_add_button").click(function() {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
28 console.debug("layer add");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
29 params = block.readMapParams();
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
30 block.addMapLayer(be,params);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
31 });
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
32 // update button
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
33 $(be).find(".map_update_button").click(function () {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
34 console.debug("map update");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
35 params = block.readMapParams();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
36 block.updateMap(be,params);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
37 });
226
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
38 // new window button
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
39 $(be).find(".map_newwindow_button").click(function () {
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
40 console.debug("map in new window");
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
41 params = block.readMapParams();
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
42 var newWindow = window.open("blocks/map_newwindow.html");
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
43 block.updateMap(newWindow.document.getElementById("map_box"),params);
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
44 });
67
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
45 // save button
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
46 $(be).find(".map_save_button").click(function () {
67
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
47 console.debug("map save. this=",this," block=",block);
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
48 params = block.readMapParams(be,params);
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
49 block.storeBlock("test1");
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
50 });
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
51 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
52 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
53
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
54 guiBlocks.Block.prototype.appendMapLayer = function (layerparams) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
55 // add layer to this map
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
56 var layerinfo = {
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
57 display: true,
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
58 layer: layerparams
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
59 };
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
60 var layers = this.params.map_layers;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
61 layers.push(layerinfo);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
62 // update indexes
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
63 for (var i = 0; i < layers.length; i++) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
64 layers[i].idx = i;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
65 }
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
66 return this.params;
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
67 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
68
72
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
69 guiBlocks.Block.prototype.deleteMapLayer = function (idx) {
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
70 // remove layer from this map
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
71 var layers = this.params.map_layers;
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
72 layers.splice(idx,1);
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
73 // update indexes
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
74 for (var i = 0; i < layers.length; i++) {
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
75 layers[i].idx = i;
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
76 }
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
77 return this.params;
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
78 };
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
79
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
80 guiBlocks.Block.prototype.showMapParams = function (elem, params) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
81 // create html with layer parameters from params
72
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
82 var i, layers, $tmpl, lp, idx;
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
83 var block = this;
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
84 if (elem == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
85 elem = this.element;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
86 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
87 if (params == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
88 params = this.params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
89 }
72
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
90 var $elem = $(elem);
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
91 $elem.find(".map_name").val(params.name);
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
92 layers = params.map_layers;
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
93 // remove old info
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
94 $(elem).find(".map_layer_table .layer_info").remove();
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
95 // write new info
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
96 if (layers.length > 0) {
72
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
97 $tmpl = $elem.find(".layer_info_tmpl").tmpl(layers);
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
98 $elem.find(".map_layer_header").after($tmpl);
69
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
99 // arm edit and delete buttons
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
100 for (i = 0; i < layers.length; ++i) {
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
101 lp = layers[i].layer;
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
102 idx = layers[i].idx;
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
103 console.debug("showmapparams lp=", lp, " idx=", idx);
72
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
104 $tmpl.find(".layer_edit_"+idx).click(function () {
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
105 var param = lp;
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
106 console.debug("open layer ",idx);
72
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
107 blocks.addLayerBlock("blocks/layer.html?table="+escape(lp.table),"layer", param);
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
108 });
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
109 $tmpl.find(".layer_delete_"+idx).click(function () {
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
110 var layerIdx = idx;
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
111 console.debug("del layer ",layerIdx);
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
112 params = block.deleteMapLayer(layerIdx);
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
113 block.showMapParams(elem, params);
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
114 block.updateMap(elem, params);
70
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
115 });
9ec7e32e8ad3 working on maps
casties
parents: 69
diff changeset
116 }
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
117 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
118 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
119
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
120 guiBlocks.Block.prototype.readMapParams = function(elem,params) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
121 // read layer parameters from html element and store in param
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
122 if (elem == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
123 elem = this.element;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
124 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
125 if (params == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
126 params = this.params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
127 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
128 params.name = $(elem).find(".map_name").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
129 var layers = params.map_layers;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
130 for (var i = 0; i < layers.length; i++) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
131 layers[i].display = $(elem).find(".layer_display_"+i).attr("checked");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
132 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
133 //params.position_field = $(elem).find(".map_position_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
134 //params.connect_line = $(elem).find(".layer_line_checkbox").attr("checked");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
135 return params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
136 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
137
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
138 guiBlocks.Block.prototype.updateMap = function(elem,map_params) {
226
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
139
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
140 //************
231
0a3303682712 Upload of xml-tables with empty Cells possible
fknauft
parents: 229
diff changeset
141 //alert("bin in updateMap:" + elem + ", " + map_params)
226
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
142 //*************
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
143
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
144 if (elem == null) {
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
145 elem = this.element;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
146 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
147 if (map_params == null) {
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
148 map_params = this.params;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
149 }
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
150 // update and draw the google map
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
151 var le = $(elem).find(".map_box").get(0);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
152 // create empty map
226
0a1dee507612 general commit
fknauft
parents: 159
diff changeset
153
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
154 if (google != null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
155 var latlng = new google.maps.LatLng(29, 116);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
156 var mapOpts = {
231
0a3303682712 Upload of xml-tables with empty Cells possible
fknauft
parents: 229
diff changeset
157 zoom: 2,
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
158 center: latlng,
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
159 mapTypeId: google.maps.MapTypeId.TERRAIN
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
160 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
161 var map = new google.maps.Map(le, mapOpts);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
162 console.debug("new google map=",map," on el=",le);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
163 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
164 // add the layers
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
165 var layerList = map_params.map_layers;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
166 for (var i = 0; i < layerList.length; i++) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
167 if (!layerList[i].display) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
168 continue;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
169 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
170 var params = layerList[i].layer;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
171 var paramstr = "format=KML_URL";
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
172 if (params.position_field && params.position_field != "Default") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
173 paramstr += "&gis_id_field="+params.position_field;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
174 }
159
3dc6be23494c map layers with custom colors
fknauft
parents: 72
diff changeset
175 if (params.color_field != "Default") {
3dc6be23494c map layers with custom colors
fknauft
parents: 72
diff changeset
176 paramstr += "&color_field="+params.color_field;
3dc6be23494c map layers with custom colors
fknauft
parents: 72
diff changeset
177 }
3dc6be23494c map layers with custom colors
fknauft
parents: 72
diff changeset
178 if (params.geometry_field != "Default") {
3dc6be23494c map layers with custom colors
fknauft
parents: 72
diff changeset
179 paramstr += "&geometry_field="+params.geometry_field;
3dc6be23494c map layers with custom colors
fknauft
parents: 72
diff changeset
180 }
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
181 if (params.connect_line) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
182 paramstr += "&connect_line="+params.connect_line;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
183 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
184 var layerurl = "../db/RESTdb/db/public/" + escape(params.table) + "?" + paramstr;
72
825a92d0ab10 fixed potential closure problem
casties
parents: 70
diff changeset
185 jQuery.get(layerurl, function (data, textStatus, XMLHttpRequest) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
186 // function after load kml url finished
234
6e6e78adb447 show line and polygon-layer
fknauft
parents: 231
diff changeset
187 console.debug("kml url loaded! this=", this );
6e6e78adb447 show line and polygon-layer
fknauft
parents: 231
diff changeset
188 console.debug(" data=", data );
236
52aa589f4c4d show line and polygon-layer
fknauft
parents: 235
diff changeset
189 console.debug(" data type=", typeof(data));
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
190 if (typeof(data) == "string") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
191 var kmlURL = data;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
192 } else {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
193 // broken, what now?
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
194 return;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
195 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
196 // render layer
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
197 if (google != null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
198 var newMarker=new google.maps.KmlLayer(kmlURL);
234
6e6e78adb447 show line and polygon-layer
fknauft
parents: 231
diff changeset
199 console.debug("new marker layer=",newMarker);
6e6e78adb447 show line and polygon-layer
fknauft
parents: 231
diff changeset
200 console.debug(" map=",map);
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
201 newMarker.setMap(map);
234
6e6e78adb447 show line and polygon-layer
fknauft
parents: 231
diff changeset
202 console.debug("Map-Update finished");
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
203 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
204 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
205 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
206 };
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
207
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
208 guiBlocks.Block.prototype.addMapLayer = function(elem,params) {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
209 var block = this;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
210 // show list of layers, select and add to map
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
211 var layerList = [];
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
212 var $dlg = $(elem).find(".dialog.add_layer_select");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
213 var $sel = $dlg.find("select.add_layer_select");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
214 // fill list of layers
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
215 blocks.loadListOfItems("test1", "layer", function(data) {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
216 console.debug("add layer list of items=",data);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
217 layerList = data;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
218 $sel.empty();
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
219 for (var i=0; i < data.length; i++) {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
220 var key = data[i].key;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
221 var val = data[i].val;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
222 var name = val.name;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
223 console.debug("layer",i," key=",key," value=",name);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
224 $sel.append('<option value="'+key+'">'+name+'</option>');
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
225 }
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
226 });
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
227 console.debug("dlg=",$dlg);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
228 $dlg.dialog({
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
229 buttons: {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
230 "Ok": function() {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
231 var layerName = $(this).find(".add_layer_select").val();
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
232 $(this).dialog("close");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
233 var layerParams = jQuery.grep(layerList, function(x){return (x.key == layerName);})[0].val;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
234 console.debug("addlayerok params=",layerParams);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
235 params = block.appendMapLayer(layerParams);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
236 block.showMapParams(elem, params);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
237 params = block.readMapParams();
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
238 block.updateMap(elem,params);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
239 },
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
240 "Cancel": function() {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
241 $(this).dialog("close");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
242 }
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
243 }
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
244 });
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
245 };
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
246