annotate gis_gui/blocks/layer.js @ 197:a1fb4c3ac037

Open new Layer with default red points
author fknauft
date Wed, 16 Feb 2011 16:46:30 +0100
parents ec2f2d5e3e21
children 1b3c75891824
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>");
197
a1fb4c3ac037 Open new Layer with default red points
fknauft
parents: 196
diff changeset
41 if (!params.geometrie_field) {
a1fb4c3ac037 Open new Layer with default red points
fknauft
parents: 196
diff changeset
42 params.geometrie_field = "point";
139
c570e374935e polygon-Layers
fknauft
parents: 133
diff changeset
43
149
143b67a139f9 polygon-Layers
fknauft
parents: 141
diff changeset
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
a1fb4c3ac037 Open new Layer with default red points
fknauft
parents: 196
diff changeset
45 if (!params.color_field) {
a1fb4c3ac037 Open new Layer with default red points
fknauft
parents: 196
diff changeset
46 params.color_field = "red";
140
c0551ecb0509 polygon-Layers
fknauft
parents: 139
diff changeset
47
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
48 $(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
49 function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
50 $(this).find("option:first").before('<option>Default</option>');
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
51 if (!params.shape_field) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
52 params.shape_field = "Default";
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 $(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
55 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
56 $(be).find(".layer_line_checkbox").attr("checked", params.connect_line);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
57 // show block
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
58 $(be).fadeIn();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
59
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
60 // save map params in block.param -- too early
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
61 //params = block.readLayerParams();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
62
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
63 // load map
195
f1b76cc939f4 Text from Features in a Side-Info-Box
fknauft
parents: 194
diff changeset
64 params = block.readLayerParams(); //FJK
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
65 block.updateLayer(be,params);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
66
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
67 // update button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
68 $(be).find(".layer_update_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
69 console.debug("layer update");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
70 params = block.readLayerParams();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
71 block.updateLayer(be,params);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
72 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
73 // save button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
74 $(be).find(".layer_save_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
75 console.debug("layer save. this=",this," block=",block);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
76 params = block.readLayerParams(be,params);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
77 block.storeBlock("test1");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
78 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
79 // open table button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
80 $(be).find(".layer_open_table_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
81 console.debug("layer open table. this=",this," block=",block);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
82 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
83 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
84 // create map button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
85 $(be).find(".map_create_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
86 console.debug("layer create map. this=",this," block=",block);
68
49fb47bbe2e6 saving and loading maps
casties
parents: 63
diff changeset
87 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
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 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
91 };
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 guiBlocks.Block.prototype.readLayerParams = function(elem,params) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
94 // read layer parameters from html element and store in param
68
49fb47bbe2e6 saving and loading maps
casties
parents: 63
diff changeset
95 if (elem == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
96 elem = this.element;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
97 }
111
086e6a257e60 changable color for dots in map
fknauft
parents: 103
diff changeset
98 if (params == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
99 params = this.params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
100 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
101 params.name = $(elem).find(".layer_name").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
102 params.position_field = $(elem).find(".layer_position_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
103 params.label_field = $(elem).find(".layer_label_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
104 params.size_field = $(elem).find(".layer_size_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
105 params.color_field = $(elem).find(".layer_color_select").val();
132
66f4491519ae polygon-Layers
fknauft
parents: 123
diff changeset
106 params.geometry_field = $(elem).find(".layer_geom_select").val();
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
107 params.shape_field = $(elem).find(".layer_shape_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
108 params.connect_line = $(elem).find(".layer_line_checkbox").attr("checked");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
109 return params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
110 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
111
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
112 guiBlocks.Block.prototype.updateLayer = function(elem,params) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
113 // update and draw the google map
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
114 var le = $(elem).find(".map_box").get(0);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
115 var paramstr = "format=KML_URL";
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
116 if (params.position_field && params.position_field != "Default") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
117 paramstr += "&gis_id_field="+params.position_field;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
118 }
117
3369c21b66e0 polygon-Layers
fknauft
parents: 111
diff changeset
119 if (params.color_field!="None"){
103
06309d0702de changable color for dots in map
fknauft
parents: 102
diff changeset
120 paramstr += "&color_field="+params.color_field;
06309d0702de changable color for dots in map
fknauft
parents: 102
diff changeset
121 }
123
f0a5a4e324ea polygon-Layers
fknauft
parents: 117
diff changeset
122 if (params.geometry_field!="None"){
117
3369c21b66e0 polygon-Layers
fknauft
parents: 111
diff changeset
123 paramstr += "&geometry_field="+params.geometry_field;
3369c21b66e0 polygon-Layers
fknauft
parents: 111
diff changeset
124 }
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
125 if (params.connect_line) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
126 paramstr += "&connect_line="+params.connect_line;
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 var layerurl = "../db/RESTdb/db/public/" + escape(params.table) + "?" + paramstr;
165
1d5d50a94024 smaller point icons
fknauft
parents: 159
diff changeset
129 //alert(layerurl);
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
130 jQuery.get(layerurl, function(data, textStatus, XMLHttpRequest) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
131 // function after load kml url finished
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
132 console.debug("kml url loaded! this=", this, " data=", data, " ("+typeof(data)+")");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
133 if (typeof(data) == "string") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
134 var kmlURL = data;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
135 } else {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
136 // what to do?
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
137 return;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
138 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 63
diff changeset
139 if (google != null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
140 var latlng = new google.maps.LatLng(29, 116);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
141 var mapOpts = {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
142 zoom: 5,
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
143 center: latlng,
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
144 mapTypeId: google.maps.MapTypeId.TERRAIN
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 var map = new google.maps.Map(le, mapOpts);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
147 console.debug("new google map=",map," on el=",le);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
148
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
149 //geocoder = new google.maps.Geocoder();
194
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
150 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
151
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
152 google.maps.event.addListener(newMarker, 'click', function(kmlEvent) {
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
153 var text = kmlEvent.featureData.description;
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
154 showInContentWindow(text);
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
155 });
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
156
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
157 function showInContentWindow(text) {
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
158 var sidediv = document.getElementById('mapping_info');
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
159 sidediv.innerHTML = text;
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
160 }
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
161
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
162 console.debug("new marker layer=",newMarker);
194
6f6f109bb6ca Text from Features in a Side-Info-Box
fknauft
parents: 165
diff changeset
163 //newMarker.setMap(map);
63
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 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
166
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
167 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
168