annotate gis_gui/blocks/map.js @ 69:752ce3dfd23e

working on maps
author casties
date Tue, 23 Nov 2010 12:54:22 +0100
parents 49fb47bbe2e6
children 9ec7e32e8ad3
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
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
33 $(be).find(".map_update_button").click(function() {
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 });
67
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
38 // save button
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
39 $(be).find(".map_save_button").click(function() {
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
40 console.debug("map save. this=",this," block=",block);
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
41 params = block.readMapParams(be,params);
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
42 block.storeBlock("test1");
b6aa7b77d110 work on saving and loading maps
casties
parents: 65
diff changeset
43 });
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
44 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
45 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
46
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
47 guiBlocks.Block.prototype.appendMapLayer = function(layerparams) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
48 // add layer to this map
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
49 var layerinfo = {display: true, layer:layerparams};
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
50 var layers = this.params.map_layers;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
51 layers.push(layerinfo);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
52 // update indexes
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
53 for (var i = 0; i < layers.length; i++) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
54 layers[i].idx = i;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
55 }
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
56 return this.params;
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
57 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
58
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
59 guiBlocks.Block.prototype.showMapParams = function(elem,params) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
60 // create html with layer parameters from params
69
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
61 var i = 0;
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
62 if (elem == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
63 elem = this.element;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
64 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
65 if (params == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
66 params = this.params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
67 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
68 $(elem).find(".map_name").val(params.name);
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
69 var layers = params.map_layers;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
70 // remove old info
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
71 $(elem).find(".map_layer_table .layer_info").remove();
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
72 // write new info
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
73 if (layers.length > 0) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
74 var tmpl = $(elem).find(".layer_info_tmpl").tmpl(layers);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
75 $(elem).find(".map_layer_header").after(tmpl);
69
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
76 // arm edit and delete buttons
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
77 for (i = 0; i < layers.length; ++i)
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
78
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
79 tmpl.find(".layer_edit_"+i).click(function() {
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
80 blocks.addLayerBlock("blocks/layer.html?table="+escape(params.table),"layer", params)
752ce3dfd23e working on maps
casties
parents: 68
diff changeset
81 });
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
82 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
83 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
84
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
85 guiBlocks.Block.prototype.readMapParams = function(elem,params) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
86 // read layer parameters from html element and store in param
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
87 if (elem == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
88 elem = this.element;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
89 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
90 if (params == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
91 params = this.params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
92 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
93 params.name = $(elem).find(".map_name").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
94 var layers = params.map_layers;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
95 for (var i = 0; i < layers.length; i++) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
96 layers[i].display = $(elem).find(".layer_display_"+i).attr("checked");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
97 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
98 //params.position_field = $(elem).find(".map_position_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
99 //params.connect_line = $(elem).find(".layer_line_checkbox").attr("checked");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
100 return params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
101 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
102
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
103 guiBlocks.Block.prototype.updateMap = function(elem,map_params) {
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
104 if (elem == null) {
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
105 elem = this.element;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
106 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
107 if (map_params == null) {
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
108 map_params = this.params;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
109 }
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
110 // update and draw the google map
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
111 var le = $(elem).find(".map_box").get(0);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
112 // create empty map
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
113 if (google != null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
114 var latlng = new google.maps.LatLng(29, 116);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
115 var mapOpts = {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
116 zoom: 5,
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
117 center: latlng,
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
118 mapTypeId: google.maps.MapTypeId.TERRAIN
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 var map = new google.maps.Map(le, mapOpts);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
121 console.debug("new google map=",map," on el=",le);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
122 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
123 // add the layers
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
124 var layerList = map_params.map_layers;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
125 for (var i = 0; i < layerList.length; i++) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
126 if (!layerList[i].display) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
127 continue;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
128 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
129 var params = layerList[i].layer;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
130 var paramstr = "format=KML_URL";
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
131 if (params.position_field && params.position_field != "Default") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
132 paramstr += "&gis_id_field="+params.position_field;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
133 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
134 if (params.connect_line) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
135 paramstr += "&connect_line="+params.connect_line;
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 var layerurl = "../db/RESTdb/db/public/" + escape(params.table) + "?" + paramstr;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
138 jQuery.get(layerurl, function(data, textStatus, XMLHttpRequest) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
139 // function after load kml url finished
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
140 console.debug("kml url loaded! this=", this, " data=", data, " ("+typeof(data)+")");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
141 if (typeof(data) == "string") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
142 var kmlURL = data;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
143 } else {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
144 // broken, what now?
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
145 return;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
146 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
147 // render layer
68
49fb47bbe2e6 saving and loading maps
casties
parents: 67
diff changeset
148 if (google != null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
149 var newMarker=new google.maps.KmlLayer(kmlURL);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
150 console.debug("new marker layer=",newMarker," map=",map);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
151 newMarker.setMap(map);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
152 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
153 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
154 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
155 };
65
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
156
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
157 guiBlocks.Block.prototype.addMapLayer = function(elem,params) {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
158 var block = this;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
159 // show list of layers, select and add to map
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
160 var layerList = [];
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
161 var $dlg = $(elem).find(".dialog.add_layer_select");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
162 var $sel = $dlg.find("select.add_layer_select");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
163 // fill list of layers
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
164 blocks.loadListOfItems("test1", "layer", function(data) {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
165 console.debug("add layer list of items=",data);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
166 layerList = data;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
167 $sel.empty();
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
168 for (var i=0; i < data.length; i++) {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
169 var key = data[i].key;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
170 var val = data[i].val;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
171 var name = val.name;
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
172 console.debug("layer",i," key=",key," value=",name);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
173 $sel.append('<option value="'+key+'">'+name+'</option>');
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
174 }
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
175 });
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
176 console.debug("dlg=",$dlg);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
177 $dlg.dialog({
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
178 buttons: {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
179 "Ok": function() {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
180 var layerName = $(this).find(".add_layer_select").val();
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
181 $(this).dialog("close");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
182 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
183 console.debug("addlayerok params=",layerParams);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
184 params = block.appendMapLayer(layerParams);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
185 block.showMapParams(elem, params);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
186 params = block.readMapParams();
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
187 block.updateMap(elem,params);
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
188 },
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
189 "Cancel": function() {
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
190 $(this).dialog("close");
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
191 }
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
192 }
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
193 });
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
194 };
2f477270cc0c adding layers to maps works now
casties
parents: 63
diff changeset
195