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