[OpenLayers-Dev] [vector-behavior] proposal for changes

Eric Lemoine eric.c2c at gmail.com
Tue Jul 15 04:16:22 EDT 2008


Hello

I'd like to bring a few changes to the vector-behavior code. Before
making these changes, I wanted to describe them and give everyone a
chance to speak up. Here they are:

 * remove update() and commit() from the strategy API. Just like
controls and handlers, strategies are activated/deactivated through
activate()/deactivate().

 * remove property 'strategy' from Layer.Vector, strategies are set in
the 'strategies' properties (Array)

 * make Layer.Vector responsible for creating, destroying, activating
and deactivating its strategies. (a) Today Layer.Vector.setMap()
activates the strategies but never deactivates them; instead,
Layer.Vector should override removeMap() and deactivates the
strategies in there. (b) To make Layer.Vector responsible for creating
and destroying the strategies, Strategy classes as opposed to Strategy
instances must be passed to the Layer.Vector constructor, I would go
with:

new OpenLayers.Layer.Vector({
    strategies: [{
            class: OpenLayers.Strategy.BBOX,
            options: {ratio: 4}
        }, {
            class: OpenLayers.Strategy.Save
    }]
});

 * make Layer.Vector responsible for creating and destroying its
protocol. In the same way as above, a Protocol class as opposed to a
Protocol instance is passed to the Layer.Vector constructor:

new OpenLayers.Layer.Vector({
    strategies: [{
            class: OpenLayers.Strategy.BBOX,
            options: {ratio: 4}
        }, {
            class: OpenLayers.Strategy.Save
    }],
    protocol: OpenLayers.Protocol.HTTP,
    protocolOptions: {url: /path/to/service}
});

 * remove the setLayer() method from the Strategy base class.
Vector.Layer will do something like that:

for (var i = 0; i < this.strategies.length; i++) {
    var strategy = new this.strategies[i].class({
        layer: this,
        ...
    });
}

 * make Layer.Vector responsible for creating/destroying the format
instance. Again, a format class as opposed to a format instance is
passed to the Layer.Vector constructor.

 * remove the setFormat() method from the Protocol class. The format
instance is passed at protocol creating using new
OpenLayers.Protocol({format: format}).

Thoughts?

Thanks,

--
Eric



More information about the Dev mailing list