annotate gis_gui/blocks/layer.js @ 200:990ca3264040

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