2
* Copyright (C) 2007-2008 Camptocamp
4
* This file is part of MapFish Client
6
* MapFish Client is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* MapFish Client is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with MapFish Client. If not, see <http://www.gnu.org/licenses/>.
21
* @requires widgets/data/FeatureStoreMediator.js
22
* @requires OpenLayers/Layer/Vector.js
25
Ext.namespace('mapfish.widgets', 'mapfish.widgets.data');
28
* Class: mapfish.widgets.data.LayerStoreMediator
30
* This class is to be used when one wants to insert, remove, and
31
* update features in a grid as a result of features being inserted,
32
* removed, modified in a vector layer.
36
* var layer = new OpenLayers.Layer.Vector("vector");
37
* var store = new Ext.data.Store({
38
* reader: new mapfish.widgets.data.FeatureReader(
39
* {}, [{name: "name", type: "string"}]
42
* var mediator = new mapfish.widgets.data.LayerStoreMediator({
45
* filter: function(feature) {
46
* return feature.state != OpenLayers.State.UNKNOWN;
53
* Constructor: mapfish.widgets.data.LayerStoreMediator
54
* Create an instance of mapfish.widgets.data.LayerStoreMediator.
57
* config - {Object} A config object used to set the layer
58
* store mediator's properties (see below for the list
59
* of supported properties), and configure it with the
60
* Ext store; see the usage example above.
63
* {<mapfish.widgets.data.LayerStoreMediator>}
65
mapfish.widgets.data.LayerStoreMediator = function(config){
66
var store = config.store;
67
// no need to place the store in the instance
69
Ext.apply(this, config);
71
OpenLayers.Console.error(
72
"layer is missing in config");
74
this.featureStoreMediator = new mapfish.widgets.data.FeatureStoreMediator({
77
if (this.autoActivate) {
82
mapfish.widgets.data.LayerStoreMediator.prototype = {
85
* {<OpenLayers.Layer.Vector>} The vector layer.
91
* {Function} a filter function called for each feature to be
92
* inserted, the feature is passed as an argument to the function,
93
* if it returns true the feature is inserted into the store,
94
* otherwise the feature is not inserted.
99
* APIProperty: autoActivate
100
* {Boolean} True if the mediator must be activated as part of
101
* its creation, false otherwise; if false then the mediator must
102
* be explicitely activate using the activate method; defaults
114
* Property: featureStoreMediator
115
* {<mapfish.widgets.data.featureStoreMediator>} An internal
116
* feature store mediator for manually adding features to the
119
featureStoreMediator: null,
122
* APIMethod: activate
123
* Activate the mediator.
126
* {Boolean} - False if the mediator was already active, true
129
activate: function() {
131
this.layer.events.on({
132
featuresadded: this.update,
133
featuresremoved: this.update,
134
featuremodified: this.update,
144
* APIMethod: deactivate
145
* Deactivate the mediator.
148
* {Boolean} - False if the mediator was already deactive, true
151
deactivate: function() {
153
this.layer.events.un({
154
featuresadded: this.update,
155
featuresremoved: this.update,
156
featuremodified: this.update,
166
* Called when features are added, removed or modified. This
167
* function empties the store, loops over the features in
168
* the layer, and for each feature calls the user-defined
169
* filter function, if the return value of the filter function
170
* evaluates to true the feature is added to the store.
173
this.featureStoreMediator.addFeatures(
175
{append: false, filter: this.filter});