comparison app/view/panel/Map.js @ 638:d21048cbdbb3

Added controllers for map and location form and handle new locations.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 17 Mar 2015 14:33:13 +0100
parents def8def373e8
children 477379250512
comparison
equal deleted inserted replaced
637:8acb3123b46c 638:d21048cbdbb3
8 Ext.define('Lada.view.panel.Map', { 8 Ext.define('Lada.view.panel.Map', {
9 extend: 'Ext.panel.Panel', 9 extend: 'Ext.panel.Panel',
10 alias: 'widget.map', 10 alias: 'widget.map',
11 11
12 record: null, 12 record: null,
13 locationRecord: null,
13 14
14 /** 15 /**
15 * @cfg 16 * @cfg
16 * OpenLayers map options. 17 * OpenLayers map options.
17 */ 18 */
101 this.map.addControl(this.selectControl); 102 this.map.addControl(this.selectControl);
102 this.selectControl.activate(); 103 this.selectControl.activate();
103 }, 104 },
104 105
105 selectedFeature: function(feature) { 106 selectedFeature: function(feature) {
106 var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id); 107 if (feature.attributes.id &&
107 this.up('window').down('locationform').setRecord(record); 108 feature.attributes.id !== '') {
108 this.up('window').down('ortform').down('combobox').setValue(record.id); 109 var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id);
110 this.up('window').down('locationform').setRecord(record);
111 this.up('window').down('locationform').setReadOnly(true);
112 this.up('window').down('ortform').down('combobox').setValue(record.id);
113 }
114 else {
115 this.up('window').down('locationform').setRecord(this.locationRecord);
116 this.up('window').down('locationform').setReadOnly(false);
117 }
109 }, 118 },
110 119
111 selectFeature: function(id) { 120 selectFeature: function(id) {
112 var feature = this.featureLayer.getFeaturesByAttribute('id', id); 121 var feature = this.featureLayer.getFeaturesByAttribute('id', id);
113 this.map.setCenter( 122 this.map.setCenter(
114 new OpenLayers.LonLat(feature[0].geometry.x, feature[0].geometry.y)); 123 new OpenLayers.LonLat(feature[0].geometry.x, feature[0].geometry.y));
115 this.map.zoomToScale(this.mapOptions.scales[5]); 124 this.map.zoomToScale(this.mapOptions.scales[5]);
116 this.selectControl.unselectAll(); 125 this.selectControl.unselectAll();
117 this.selectControl.select(feature[0]); 126 this.selectControl.select(feature[0]);
127 },
128
129 activateDraw: function(record) {
130 this.locationRecord = record;
131 if (!this.drawPoint) {
132 this.drawPoint = new OpenLayers.Control.DrawFeature(this.featureLayer,
133 OpenLayers.Handler.Point);
134 this.map.addControl(this.drawPoint);
135 }
136 this.drawPoint.activate();
137 this.drawPoint.events.register('featureadded', this, this.featureAdded);
138 },
139
140 featureAdded: function(features) {
141 this.locationRecord.set('latitude', features.feature.geometry.y);
142 this.locationRecord.set('longitude', features.feature.geometry.x);
143 this.drawPoint.deactivate();
144 this.selectControl.unselectAll();
145 this.selectControl.select(features.feature);
146 console.log(arguments);
118 }, 147 },
119 148
120 /** 149 /**
121 * @private 150 * @private
122 * Override to display and update the map view in the panel. 151 * Override to display and update the map view in the panel.

http://lada.wald.intevation.org