diff app/view/panel/Map.js @ 1051:981339d774b8

merged stammdatengrids to default.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 01 Mar 2016 14:12:39 +0100
parents 1bd4c0709bd6
children 65ea1c2a8c98
line wrap: on
line diff
--- a/app/view/panel/Map.js	Mon Feb 29 15:10:17 2016 +0100
+++ b/app/view/panel/Map.js	Tue Mar 01 14:12:39 2016 +0100
@@ -14,9 +14,15 @@
 Ext.define('Lada.view.panel.Map', {
     extend: 'Ext.panel.Panel',
     alias: 'widget.map',
+    name: 'map',
 
     record: null,
     locationRecord: null,
+    externalOrteStore: false,
+    /*
+     * if externalOrteStore is true, the mappanel will not load the orte
+     * store on it's own; it expects an already loaded store instead
+     */
 
     /**
      * @cfg
@@ -62,7 +68,6 @@
         keyControl.activate();
         this.bodyStyle = {background: '#fff'};
         this.initData();
-        this.tbar = Ext.create('Lada.view.widget.MapToolbar');
         this.addEvents('featureselected');
         this.callParent(arguments);
     },
@@ -73,58 +78,15 @@
      */
     initData: function() {
         var me = this;
-        this.locationFeatures = [];
-        this.locationStore = Ext.data.StoreManager.get('locations');
-        for (var i = 0; i < this.locationStore.count(); i++) {
-            this.locationFeatures.push(new OpenLayers.Feature.Vector(
-                new OpenLayers.Geometry.Point(
-                    this.locationStore.getAt(i).get('longitude'),
-                    this.locationStore.getAt(i).get('latitude')
-                ),
-                {
-                    id: this.locationStore.getAt(i).get('id'),
-                    bez: this.locationStore.getAt(i).get('bezeichnung')
-                }
-            ));
+
+        if (!this.externalOrteStore) {
+            this.locationStore = Ext.data.StoreManager.get('orte');
+            this.addLocations(locationStore);
         }
-        this.featureLayer = new OpenLayers.Layer.Vector('vector_' + this.map.name, {
-            styleMap: new OpenLayers.StyleMap({
-                'default': new OpenLayers.Style(OpenLayers.Util.applyDefaults({
-                    externalGraphic: 'resources/lib/OpenLayers/img/marker-green.png',
-                    graphicOpacity: 1,
-                    pointRadius: 10,
-                    label: '${bez}',
-                    labelAlign: 'rt',
-                    fontColor: 'green',
-                    fontWeight: 'bold'
-                }, OpenLayers.Feature.Vector.style['default'])),
-                'select': new OpenLayers.Style({
-                    externalGraphic: 'resources/lib/OpenLayers/img/marker-blue.png',
-                    pointRadius: 15,
-                    label: '${bez}',
-                    labelAlign: 'rt',
-                    fontColor: 'blue',
-                    fontWeight: 'bold'
-                })
-            })
-        });
-        this.featureLayer.addFeatures(this.locationFeatures);
-        this.map.addLayer(this.featureLayer);
-
-        this.selectControl = new OpenLayers.Control.SelectFeature(this.featureLayer, {
-            clickout: false,
-            toggle: false,
-            multiple: false,
-            hover: false,
-            onSelect: me.selectedFeature,
-            scope: me
-        });
-        this.map.addControl(this.selectControl);
-        this.selectControl.activate();
     },
 
-    selectFeature: function(id) {
-        var feature = this.featureLayer.getFeaturesByAttribute('id', id);
+    selectFeature: function(model, record) {
+        var feature = this.featureLayer.getFeaturesByAttribute('id', record.get('id'));
         this.map.setCenter(
             new OpenLayers.LonLat(feature[0].geometry.x, feature[0].geometry.y));
         this.map.zoomToScale(this.mapOptions.scales[5]);
@@ -151,6 +113,65 @@
         this.selectControl.select(features.feature);
     },
 
+    addLocations: function(locationStore) {
+        var me = this;
+        locationFeatures = [];
+
+        // Iterate the Store and create features from it
+        for (var i = 0; i < locationStore.count(); i++) {
+            locationFeatures.push(new OpenLayers.Feature.Vector(
+                new OpenLayers.Geometry.Point(
+                    locationStore.getAt(i).get('longitude'),
+                    locationStore.getAt(i).get('latitude')
+                ),
+                {
+                    id: locationStore.getAt(i).get('id'),
+                    bez: locationStore.getAt(i).get('ortId')
+                }
+            ));
+        }
+
+        // Create a new Feature Layer and add it to the map
+        if (!this.featureLayer) {
+            this.featureLayer = new OpenLayers.Layer.Vector('vector_' + this.map.name, {
+                styleMap: new OpenLayers.StyleMap({
+                    'default': new OpenLayers.Style(OpenLayers.Util.applyDefaults({
+                        externalGraphic: 'resources/lib/OpenLayers/img/marker-green.png',
+                        graphicOpacity: 1,
+                        pointRadius: 10,
+                        label: '${bez}',
+                        labelAlign: 'rt',
+                        fontColor: 'green',
+                        fontWeight: 'bold'
+                    }, OpenLayers.Feature.Vector.style['default'])),
+                    'select': new OpenLayers.Style({
+                        externalGraphic: 'resources/lib/OpenLayers/img/marker-blue.png',
+                        pointRadius: 15,
+                        label: '${bez}',
+                        labelAlign: 'rt',
+                        fontColor: 'blue',
+                        fontWeight: 'bold'
+                    })
+                })
+            });
+            this.selectControl = new OpenLayers.Control.SelectFeature(this.featureLayer, {
+                clickout: false,
+                toggle: false,
+                multiple: false,
+                hover: false,
+                onSelect: me.selectedFeature,
+                scope: me
+            });
+            this.map.addControl(this.selectControl);
+            this.selectControl.activate();
+        }
+        this.featureLayer.removeAllFeatures();
+        this.featureLayer.addFeatures(locationFeatures);
+        this.map.addLayer(this.featureLayer);
+
+    },
+
+
     /**
      * @private
      * Override to display and update the map view in the panel.

http://lada.wald.intevation.org