annotate gis_gui/blocks/layer.js @ 140:c0551ecb0509

polygon-Layers
author fknauft
date Thu, 03 Feb 2011 12:14:34 +0100
parents c570e374935e
children 97cb016e29ec
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
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
5 params = {"type": "layer", "table": params};
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
c0551ecb0509 polygon-Layers
fknauft
parents: 139
diff changeset
40 $(be).find(".layer_geom_select").attr("element","<select id='geom'><option>point</option><option>poly</option><option>line</option></select>");
139
c570e374935e polygon-Layers
fknauft
parents: 133
diff changeset
41
140
c0551ecb0509 polygon-Layers
fknauft
parents: 139
diff changeset
42 $(be).find(".layer_color_select").attr("element","<select id='color'><option>red</option><option>blue</option><option>black</option><option>green</option><option>violett</option></select>");
c0551ecb0509 polygon-Layers
fknauft
parents: 139
diff changeset
43
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
44 $(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
45 function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
46 $(this).find("option:first").before('<option>Default</option>');
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
47 if (!params.shape_field) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
48 params.shape_field = "Default";
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
49 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
50 $(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
51 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
52 $(be).find(".layer_line_checkbox").attr("checked", params.connect_line);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
53 // show block
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
54 $(be).fadeIn();
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 // save map params in block.param -- too early
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
57 //params = block.readLayerParams();
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 // load map
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
60 block.updateLayer(be,params);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
61
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
62 // update button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
63 $(be).find(".layer_update_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
64 console.debug("layer update");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
65 params = block.readLayerParams();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
66 block.updateLayer(be,params);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
67 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
68 // save button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
69 $(be).find(".layer_save_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
70 console.debug("layer save. this=",this," block=",block);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
71 params = block.readLayerParams(be,params);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
72 block.storeBlock("test1");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
73 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
74 // open table button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
75 $(be).find(".layer_open_table_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
76 console.debug("layer open table. this=",this," block=",block);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
77 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
78 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
79 // create map button
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
80 $(be).find(".map_create_button").click(function() {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
81 console.debug("layer create map. this=",this," block=",block);
68
49fb47bbe2e6 saving and loading maps
casties
parents: 63
diff changeset
82 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
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 });
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 guiBlocks.Block.prototype.readLayerParams = function(elem,params) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
89 // read layer parameters from html element and store in param
68
49fb47bbe2e6 saving and loading maps
casties
parents: 63
diff changeset
90 if (elem == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
91 elem = this.element;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
92 }
111
086e6a257e60 changable color for dots in map
fknauft
parents: 103
diff changeset
93 if (params == null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
94 params = this.params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
95 }
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
96 params.name = $(elem).find(".layer_name").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
97 params.position_field = $(elem).find(".layer_position_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
98 params.label_field = $(elem).find(".layer_label_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
99 params.size_field = $(elem).find(".layer_size_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
100 params.color_field = $(elem).find(".layer_color_select").val();
132
66f4491519ae polygon-Layers
fknauft
parents: 123
diff changeset
101 params.geometry_field = $(elem).find(".layer_geom_select").val();
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
102 params.shape_field = $(elem).find(".layer_shape_select").val();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
103 params.connect_line = $(elem).find(".layer_line_checkbox").attr("checked");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
104 return params;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
105 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
106
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
107 guiBlocks.Block.prototype.updateLayer = function(elem,params) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
108 // update and draw the google map
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
109 var le = $(elem).find(".map_box").get(0);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
110 var paramstr = "format=KML_URL";
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
111 if (params.position_field && params.position_field != "Default") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
112 paramstr += "&gis_id_field="+params.position_field;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
113 }
117
3369c21b66e0 polygon-Layers
fknauft
parents: 111
diff changeset
114 if (params.color_field!="None"){
103
06309d0702de changable color for dots in map
fknauft
parents: 102
diff changeset
115 paramstr += "&color_field="+params.color_field;
06309d0702de changable color for dots in map
fknauft
parents: 102
diff changeset
116 }
123
f0a5a4e324ea polygon-Layers
fknauft
parents: 117
diff changeset
117 if (params.geometry_field!="None"){
117
3369c21b66e0 polygon-Layers
fknauft
parents: 111
diff changeset
118 paramstr += "&geometry_field="+params.geometry_field;
3369c21b66e0 polygon-Layers
fknauft
parents: 111
diff changeset
119 }
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
120 if (params.connect_line) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
121 paramstr += "&connect_line="+params.connect_line;
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 var layerurl = "../db/RESTdb/db/public/" + escape(params.table) + "?" + paramstr;
140
c0551ecb0509 polygon-Layers
fknauft
parents: 139
diff changeset
124 //alert(layerurl);
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
125 jQuery.get(layerurl, function(data, textStatus, XMLHttpRequest) {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
126 // function after load kml url finished
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
127 console.debug("kml url loaded! this=", this, " data=", data, " ("+typeof(data)+")");
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
128 if (typeof(data) == "string") {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
129 var kmlURL = data;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
130 } else {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
131 // what to do?
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
132 return;
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
133 }
68
49fb47bbe2e6 saving and loading maps
casties
parents: 63
diff changeset
134 if (google != null) {
63
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
135 var latlng = new google.maps.LatLng(29, 116);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
136 var mapOpts = {
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
137 zoom: 5,
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
138 center: latlng,
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
139 mapTypeId: google.maps.MapTypeId.TERRAIN
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
140 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
141 var map = new google.maps.Map(le, mapOpts);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
142 console.debug("new google map=",map," on el=",le);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
143
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
144 //geocoder = new google.maps.Geocoder();
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
145 var newMarker=new google.maps.KmlLayer(kmlURL);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
146 console.debug("new marker layer=",newMarker);
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
147 newMarker.setMap(map);
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 });
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
150
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
151 };
7f008e782563 add gui files to product via FileSystemSite
casties
parents:
diff changeset
152