comparison app/view/panel/Map.js @ 1279:291df0037835

Ortszuordnung window: create, change and display (wip)
author Maximilian Krambach <mkrambach@intevation.de>
date Wed, 18 Jan 2017 11:41:50 +0100
parents a792eecf1614
children 08085b7d1d0b
comparison
equal deleted inserted replaced
1278:cb9609380056 1279:291df0037835
25 */ 25 */
26 26
27 /** 27 /**
28 * @cfg 28 * @cfg
29 * OpenLayers map options. 29 * OpenLayers map options.
30 * Please note that TMS zoom levels are roughly as this:
31 * 7 = 1:4000000 14 = 1:35000
30 */ 32 */
31 mapOptions: { 33 mapOptions: {
32 maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), 34 maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
33 //scales: [5000000, 3000000, 2000000, 1000000, 500000, 250000, 100000, 25000], 35 numZoomLevels: 15,
34 //numZoomLevels: 7,
35 projection: 'EPSG:3857', 36 projection: 'EPSG:3857',
36 displayProjection: new OpenLayers.Projection('EPSG:4326') 37 displayProjection: new OpenLayers.Projection('EPSG:4326')
37 }, 38 },
38 39
39 40
57 }) 58 })
58 ]; 59 ];
59 this.map = new OpenLayers.Map('map_' + id, { 60 this.map = new OpenLayers.Map('map_' + id, {
60 controls: [], 61 controls: [],
61 tileManager: null, 62 tileManager: null,
62 zoomMethod: null 63 zoomMethod: null,
64 // initializing with view centered on germany
65 center: new OpenLayers.LonLat(1160000,6694000),
66 zoom: 7
63 }); 67 });
64 this.map.setOptions(this.mapOptions); 68 this.map.setOptions(this.mapOptions);
65 this.map.addLayers(this.layers); 69 this.map.addLayers(this.layers);
66 var keyControl = new OpenLayers.Control.KeyboardDefaults(); 70 var keyControl = new OpenLayers.Control.KeyboardDefaults();
67 this.map.addControl(keyControl); 71 this.map.addControl(keyControl);
87 91
88 selectFeature: function(model, record) { 92 selectFeature: function(model, record) {
89 if (!record.get('id') || record.get('id') === '') { 93 if (!record.get('id') || record.get('id') === '') {
90 return; 94 return;
91 } 95 }
92 var feature = this.featureLayer.getFeaturesByAttribute('id', record.get('id')); 96 var feature = this.featureLayer.getFeaturesByAttribute('id', record.get('id'))[0];
93 this.map.setCenter( 97 this.map.setCenter(
94 new OpenLayers.LonLat(feature[0].geometry.x, feature[0].geometry.y)); 98 new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y));
95 this.map.zoomToScale(this.mapOptions.scales[5]); 99 this.map.zoomTo(12);
96 this.selectControl.unselectAll(); 100
97 this.selectControl.select(feature[0]); 101 if (this.selectedFeatureLayer) {
102 if (this.selectedFeatureLayer.features.lenght > 0) {
103 this.featureLayer.addFeatures(this.selectedFeatureLayer.features);
104 }
105 this.selectedFeatureLayer.addFeatures([feature]);
106 } else {
107 this.selectControl.select(feature);
108 }
109 //TODO: the text of new features is still drawn on top of the old feature's text
98 }, 110 },
99 111
100 activateDraw: function(record) { 112 activateDraw: function(record) {
101 this.locationRecord = record; 113 this.locationRecord = record;
102 if (!this.drawPoint) { 114 if (!this.drawPoint) {
136 )); 148 ));
137 } 149 }
138 150
139 // Create a new Feature Layer and add it to the map 151 // Create a new Feature Layer and add it to the map
140 if (!this.featureLayer) { 152 if (!this.featureLayer) {
141 this.featureLayer = new OpenLayers.Layer.Vector('alle Messpunkte', { 153 this.featureLayer = new OpenLayers.Layer.Vector( 'alle Messpunkte', {
142 styleMap: new OpenLayers.StyleMap({ 154 styleMap: new OpenLayers.StyleMap({
143 'default': new OpenLayers.Style(OpenLayers.Util.applyDefaults({ 155 'default': new OpenLayers.Style(OpenLayers.Util.applyDefaults({
144 externalGraphic: 'resources/lib/OpenLayers/img/marker-green.png', 156 externalGraphic: 'resources/lib/OpenLayers/img/marker-green.png',
145 graphicOpacity: 1, 157 graphicOpacity: 1,
146 pointRadius: 10, 158 pointRadius: 10,
156 labelAlign: 'rt', 168 labelAlign: 'rt',
157 fontColor: 'blue', 169 fontColor: 'blue',
158 fontWeight: 'bold' 170 fontWeight: 'bold'
159 }) 171 })
160 }), 172 }),
161 projection: new OpenLayers.Projection('EPSG:4326'), 173 projection: new OpenLayers.Projection('EPSG:3857'),
162 preFeatureInsert: function(feature) { 174 preFeatureInsert: function(feature) {
163 feature.geometry.transform(new OpenLayers.Projection('EPSG:4326'), new OpenLayers.Projection('EPSG:3857')); 175 feature.geometry.transform(new OpenLayers.Projection('EPSG:4326'),
176 new OpenLayers.Projection('EPSG:3857'));
164 } 177 }
165 }); 178 });
166 this.selectControl = new OpenLayers.Control.SelectFeature(this.featureLayer, { 179 this.selectControl = new OpenLayers.Control.SelectFeature(this.featureLayer, {
167 clickout: false, 180 clickout: false,
168 toggle: false, 181 toggle: false,
169 multiple: false, 182 multiple: false,
170 hover: false, 183 hover: false,
171 onSelect: me.selectedFeature, 184 onSelect: me.selectedFeature,
185 layers: [me.featureLayer],
172 scope: me 186 scope: me
173 }); 187 });
174 this.map.addControl(this.selectControl); 188 this.map.addControl(this.selectControl);
175 this.selectControl.activate(); 189 this.selectControl.activate();
176 } 190 }
177 this.featureLayer.removeAllFeatures(); 191 this.featureLayer.removeAllFeatures();
178 this.featureLayer.addFeatures(locationFeatures); 192 this.featureLayer.addFeatures(locationFeatures);
179 this.map.addLayer(this.featureLayer); 193 this.map.addLayer(this.featureLayer);
180 194 this.featureLayer.setZIndex(500);
181 }, 195 },
182
183 196
184 /** 197 /**
185 * @private 198 * @private
186 * Override to display and update the map view in the panel. 199 * Override to display and update the map view in the panel.
187 */ 200 */
195 }, 208 },
196 209
197 /** 210 /**
198 * Forward OpenlayersEvent to EXT 211 * Forward OpenlayersEvent to EXT
199 */ 212 */
200 selectedFeature: function() { 213 selectedFeature: function(feature) {
214 this.selectControl.unselectAll({except:feature});
201 this.fireEvent('featureselected', this, arguments); 215 this.fireEvent('featureselected', this, arguments);
202 }, 216 },
203 217
204 beforeDestroy: function() { 218 beforeDestroy: function() {
205 if (this.map) { 219 if (this.map) {

http://lada.wald.intevation.org