diff 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
line wrap: on
line diff
--- a/app/view/panel/Map.js	Tue Mar 17 10:21:29 2015 +0100
+++ b/app/view/panel/Map.js	Tue Mar 17 14:33:13 2015 +0100
@@ -10,6 +10,7 @@
     alias: 'widget.map',
 
     record: null,
+    locationRecord: null,
 
     /**
      * @cfg
@@ -103,9 +104,17 @@
     },
 
     selectedFeature: function(feature) {
-        var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id);
-        this.up('window').down('locationform').setRecord(record);
-        this.up('window').down('ortform').down('combobox').setValue(record.id);
+        if (feature.attributes.id &&
+            feature.attributes.id !== '') {
+            var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id);
+            this.up('window').down('locationform').setRecord(record);
+            this.up('window').down('locationform').setReadOnly(true);
+            this.up('window').down('ortform').down('combobox').setValue(record.id);
+        }
+        else {
+            this.up('window').down('locationform').setRecord(this.locationRecord);
+            this.up('window').down('locationform').setReadOnly(false);
+        }
     },
 
     selectFeature: function(id) {
@@ -117,6 +126,26 @@
         this.selectControl.select(feature[0]);
     },
 
+    activateDraw: function(record) {
+        this.locationRecord = record;
+        if (!this.drawPoint) {
+            this.drawPoint = new OpenLayers.Control.DrawFeature(this.featureLayer,
+                OpenLayers.Handler.Point);
+            this.map.addControl(this.drawPoint);
+        }
+        this.drawPoint.activate();
+        this.drawPoint.events.register('featureadded', this, this.featureAdded);
+    },
+
+    featureAdded: function(features) {
+        this.locationRecord.set('latitude', features.feature.geometry.y);
+        this.locationRecord.set('longitude', features.feature.geometry.x);
+        this.drawPoint.deactivate();
+        this.selectControl.unselectAll();
+        this.selectControl.select(features.feature);
+        console.log(arguments);
+    },
+
     /**
      * @private
      * Override to display and update the map view in the panel.

http://lada.wald.intevation.org