63
|
1
|
|
2 guiBlocks.prototype.addLayerBlock = function(url, baseId, params) {
|
|
3 if (typeof(params) == "string") {
|
68
|
4 // then its the table name
|
196
|
5 params = {"type": "layer", "table": params, "color_field":"red","geometry_field":"point"};
|
63
|
6 }
|
|
7 var block = this.addBlock(url, baseId, params, function() {
|
|
8 // function after add block finished
|
|
9 var id = block.id;
|
|
10 var be = block.element;
|
|
11 block.type = "layer";
|
|
12 var tablename = params.table;
|
|
13 console.debug("in layerblock after block load!");
|
|
14 $(be).find(".layer_name").val(block.params.name);
|
|
15 $(be).find(".layer_position_select").load("../db/RESTdb/db/public/"+tablename+"?format=HTML&type=schema_table_rows&layout=select&element_id=rows #rows *",
|
|
16 function() {
|
|
17 $(this).find("option:first").before('<option>Default</option>');
|
|
18 if (!params.position_field) {
|
|
19 params.position_field = "Default";
|
|
20 }
|
|
21 $(this).find("option").filter(function(){return $(this).text() == params.position_field;}).attr("selected","true");
|
|
22 });
|
|
23 $(be).find(".layer_label_select").load("../db/RESTdb/db/public/"+tablename+"?format=HTML&type=schema_table_rows&layout=select&element_id=rows #rows *",
|
|
24 function() {
|
|
25 $(this).find("option:first").before('<option>Default</option>');
|
|
26 if (!params.label_field) {
|
|
27 params.label_field = "Default";
|
|
28 }
|
|
29 $(this).find("option").filter(function(){return $(this).text() == params.label_field;}).attr("selected","true");
|
|
30 });
|
|
31 $(be).find(".layer_size_select").load("../db/RESTdb/db/public/"+tablename+"?format=HTML&type=schema_table_rows&layout=select&element_id=rows #rows *",
|
|
32 function() {
|
|
33 $(this).find("option:first").before('<option>Default</option>');
|
|
34 if (!params.size_field) {
|
|
35 params.size_field = "Default";
|
|
36 }
|
|
37 $(this).find("option").filter(function(){return $(this).text() == params.size_field;}).attr("selected","true");
|
|
38 });
|
140
|
39
|
149
|
40 $(be).find(".layer_geom_select").attr("element","<select id='geom'><option selected>point</option><option>poly</option><option>line</option></select>");
|
197
|
41 if (!params.geometrie_field) {
|
|
42 params.geometrie_field = "point";
|
139
|
43
|
149
|
44 $(be).find(".layer_color_select").attr("element","<select id='color'><option selected>red</option><option>blue</option><option>black</option><option>green</option><option>violett</option></select>");
|
197
|
45 if (!params.color_field) {
|
|
46 params.color_field = "red";
|
140
|
47
|
63
|
48 $(be).find(".layer_shape_select").load("../db/RESTdb/db/public/"+tablename+"?format=HTML&type=schema_table_rows&layout=select&element_id=rows #rows *",
|
|
49 function() {
|
|
50 $(this).find("option:first").before('<option>Default</option>');
|
|
51 if (!params.shape_field) {
|
|
52 params.shape_field = "Default";
|
|
53 }
|
|
54 $(this).find("option").filter(function(){return $(this).text() == params.shape_field;}).attr("selected","true");
|
|
55 });
|
|
56 $(be).find(".layer_line_checkbox").attr("checked", params.connect_line);
|
|
57 // show block
|
|
58 $(be).fadeIn();
|
|
59
|
|
60 // save map params in block.param -- too early
|
|
61 //params = block.readLayerParams();
|
|
62
|
|
63 // load map
|
195
|
64 params = block.readLayerParams(); //FJK
|
63
|
65 block.updateLayer(be,params);
|
|
66
|
|
67 // update button
|
|
68 $(be).find(".layer_update_button").click(function() {
|
|
69 console.debug("layer update");
|
|
70 params = block.readLayerParams();
|
|
71 block.updateLayer(be,params);
|
|
72 });
|
|
73 // save button
|
|
74 $(be).find(".layer_save_button").click(function() {
|
|
75 console.debug("layer save. this=",this," block=",block);
|
|
76 params = block.readLayerParams(be,params);
|
|
77 block.storeBlock("test1");
|
|
78 });
|
|
79 // open table button
|
|
80 $(be).find(".layer_open_table_button").click(function() {
|
|
81 console.debug("layer open table. this=",this," block=",block);
|
|
82 var tblblock = blocks.addTableBlock("blocks/table.html?table="+escape(params.table),"table", params.table);
|
|
83 });
|
|
84 // create map button
|
|
85 $(be).find(".map_create_button").click(function() {
|
|
86 console.debug("layer create map. this=",this," block=",block);
|
68
|
87 var mapblock = blocks.addMapBlock("blocks/map.html?layer="+escape(params.name),"map",null,params);
|
63
|
88 });
|
|
89
|
|
90 });
|
|
91 };
|
|
92
|
|
93 guiBlocks.Block.prototype.readLayerParams = function(elem,params) {
|
|
94 // read layer parameters from html element and store in param
|
68
|
95 if (elem == null) {
|
63
|
96 elem = this.element;
|
|
97 }
|
111
|
98 if (params == null) {
|
63
|
99 params = this.params;
|
|
100 }
|
|
101 params.name = $(elem).find(".layer_name").val();
|
|
102 params.position_field = $(elem).find(".layer_position_select").val();
|
|
103 params.label_field = $(elem).find(".layer_label_select").val();
|
|
104 params.size_field = $(elem).find(".layer_size_select").val();
|
|
105 params.color_field = $(elem).find(".layer_color_select").val();
|
132
|
106 params.geometry_field = $(elem).find(".layer_geom_select").val();
|
63
|
107 params.shape_field = $(elem).find(".layer_shape_select").val();
|
|
108 params.connect_line = $(elem).find(".layer_line_checkbox").attr("checked");
|
|
109 return params;
|
|
110 };
|
|
111
|
|
112 guiBlocks.Block.prototype.updateLayer = function(elem,params) {
|
|
113 // update and draw the google map
|
|
114 var le = $(elem).find(".map_box").get(0);
|
|
115 var paramstr = "format=KML_URL";
|
|
116 if (params.position_field && params.position_field != "Default") {
|
|
117 paramstr += "&gis_id_field="+params.position_field;
|
|
118 }
|
117
|
119 if (params.color_field!="None"){
|
103
|
120 paramstr += "&color_field="+params.color_field;
|
|
121 }
|
123
|
122 if (params.geometry_field!="None"){
|
117
|
123 paramstr += "&geometry_field="+params.geometry_field;
|
|
124 }
|
63
|
125 if (params.connect_line) {
|
|
126 paramstr += "&connect_line="+params.connect_line;
|
|
127 }
|
|
128 var layerurl = "../db/RESTdb/db/public/" + escape(params.table) + "?" + paramstr;
|
165
|
129 //alert(layerurl);
|
63
|
130 jQuery.get(layerurl, function(data, textStatus, XMLHttpRequest) {
|
|
131 // function after load kml url finished
|
|
132 console.debug("kml url loaded! this=", this, " data=", data, " ("+typeof(data)+")");
|
|
133 if (typeof(data) == "string") {
|
|
134 var kmlURL = data;
|
|
135 } else {
|
|
136 // what to do?
|
|
137 return;
|
|
138 }
|
68
|
139 if (google != null) {
|
63
|
140 var latlng = new google.maps.LatLng(29, 116);
|
|
141 var mapOpts = {
|
|
142 zoom: 5,
|
|
143 center: latlng,
|
|
144 mapTypeId: google.maps.MapTypeId.TERRAIN
|
|
145 };
|
|
146 var map = new google.maps.Map(le, mapOpts);
|
|
147 console.debug("new google map=",map," on el=",le);
|
|
148
|
|
149 //geocoder = new google.maps.Geocoder();
|
194
|
150 var newMarker=new google.maps.KmlLayer(kmlURL,{ suppressInfoWindows: true, map: map});
|
|
151
|
|
152 google.maps.event.addListener(newMarker, 'click', function(kmlEvent) {
|
|
153 var text = kmlEvent.featureData.description;
|
|
154 showInContentWindow(text);
|
|
155 });
|
|
156
|
|
157 function showInContentWindow(text) {
|
|
158 var sidediv = document.getElementById('mapping_info');
|
|
159 sidediv.innerHTML = text;
|
|
160 }
|
|
161
|
63
|
162 console.debug("new marker layer=",newMarker);
|
194
|
163 //newMarker.setMap(map);
|
63
|
164 }
|
|
165 });
|
|
166
|
|
167 };
|
|
168
|