2
* Copyright (C) 2007 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 OpenLayers/Strategy.js
22
* @requires core/Strategy.js
26
* Class: mapfish.Strategy.ProtocolListener
27
* A strategy that listens to "crudfinished" and "clear" events triggered
28
* by a <mapfish.Protocol.TriggerEventDecorator> protocol, upon receiving
29
* a "crudfinished" event and if the request is of type "read", the
30
* strategy adds the received features to the layer, upon receiving a
31
* "clear" event, the strategy destroys the features in the layer. A
32
* <mapfish.Protocol.TriggerEventDecorator> protocol must be
33
* configured in the layer for this strategy to work as expected.
37
* var layer = new OpenLayers.Layer.Vector(
38
* "some layer name", {
39
* protocol: new mapfish.Protocol.TriggerEventDecorator(someProtocol),
40
* strategies: [new mapfish.Strategy.ProtocolListener({append: true})]
46
* - <OpenLayers.Strategy>
48
mapfish.Strategy.ProtocolListener = OpenLayers.Class(OpenLayers.Strategy, {
52
* {Boolean} If false, existing layer features are destroyed
53
* before adding newly read features. Defaults to false.
58
* APIProperty: recenter
59
* {Boolean} If true, map is recentered to features extent.
65
* Constructor: mapfish.Strategy.ProtocolListener
66
* Create a new ProtocolListener strategy.
69
* options - {Object} Optional object whose properties will be set on the
72
initialize: function(options) {
73
OpenLayers.Strategy.prototype.initialize.apply(this, [options]);
78
* Set up strategy with regard to adding features to the layer when
79
* receiving crudfinished events and destroying the layer features
80
* when receiving clear events.
83
* {Boolean} The strategy was successfully activated.
85
activate: function() {
86
if (this.layer.protocol.CLASS_NAME != "mapfish.Protocol.TriggerEventDecorator") {
87
OpenLayers.Console.error([
88
"This strategy is to be used with a layer whose protocol ",
89
"is an instance of mapfish.Protocol.TriggerEventDecorator"].join('')
93
var activated = OpenLayers.Strategy.prototype.activate.call(this);
95
this.layer.protocol.events.on({
96
"crudfinished": this.onCrudfinished,
97
"clear": this.onClear,
106
* Tear down strategy.
109
* {Boolean} The strategy was successfully deactivated.
111
deactivate: function() {
112
var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this);
114
this.layer.protocol.events.un({
115
"crudfinished": this.onCrudfinished,
116
"clear": this.onClear,
124
* Method: onCrudfinished
125
* Callback function called on protocol crudfinished event.
128
* options - {<OpenLayers.Response>} Protocol response
130
onCrudfinished: function(response) {
131
if (response.requestType == "read") {
132
this.addFeatures(response.features);
137
* Method: addFeatures
138
* Adds the read features to the layer
141
* options - {<OpenLayers.Response>} Protocol response
143
addFeatures: function(features) {
145
this.layer.destroyFeatures();
147
if (features && features.length > 0) {
148
this.layer.addFeatures(features);
150
this.layer.map.zoomToExtent(this.layer.getDataExtent());
157
* Callback function called on protocol clear event.
159
onClear: function() {
160
this.layer.destroyFeatures();
163
CLASS_NAME: "mapfish.Strategy.ProtocolListener"
b'\\ No newline at end of file'