dinsdag 6 juli 2010

Adding Grid Strategy to the mix

Last week I started on adding the Grid Strategy developed by Eric Lemoine in an OpenLayers sandbox to the mix of the GEOZET application. Eric developed the Strategy 2 years ago, when there was no Cluster Strategy as yet, so my challenge was to get the Grid Strategy to work together nicely with the Cluster Strategy. Getting it to work with the Protocol.WFS was a very simple change, however getting it to work together with the Cluster Strategy was a bigger challenge.

The reason we want to use the Grid Strategy is that for performance reasons later on we might want to add caching (e.g. through Squid), and I found it too risky to incorporate the grid strategy at the end of the project.

I started off adding an HTTP GET interface for Protocol.WFS, since POST isn't cacheable through Squid. It can be found here:


Then I started to use Eric's code.


The biggest issue I encountered was that the grid strategy just adds the features to the layer as they come in. This did not work well for the cluster strategy, so I needed to find out when the grid strategy was done, and then only add the features to the layer for them to play well together. I ended up making a few changes to accomplish this:

For the Grid class:
  • add a counter property and set it to 0 in the initGrid function
  • set the counter to 0 in the moveGrid function
  • increase the counter in a few places in the code, i.e. just before the createTile call in initGrid, in shiftRow just before the moveTo call, in shiftColumn just before the moveTo call.
For the Stratregy.Grid class:
  • add a count property and initialize it to 0
  • change the redraw variable's default to false if not provided in moveTo
  • add featureMap function here, Eric added this to Layer.Vector instead but I was lazy to adapt yet another file
  • in the draw function, increase this.strategy.count, and check if this.strategy.count equals this.strategy.grid.counter, if so we are done and we add the features to the layer.
  • where the BBOX filter is created, we give this.bounds for the value, and not the Geometry Rectangle, so it can play well with the Protocol.WFS
  • in the refresh function, set force to false so the grid can decide based on the bounds
That is how I basically got things to work together. However, it might be a bit too specific for general use.

Geen opmerkingen:

Een reactie posten