[OpenLayers-Users] change layer style on zooming

eriktronic etimmers at gmail.com
Mon Nov 5 08:12:10 PST 2012


As I could not find an clear answer anywhere on google, I subscribed here to
hopefully get some help from you.

I build a map containing a lot of feature points, shown as small dots. As I
zoom out I would like the circles to shrink, otherwise the underlying
OpenStreetMap is completely lost. I tried doing so by applying a default
style and adding a function to the event 'zoomend'. See this small example:


var geoJson = {...}; // some geojson object
var style = { 'pointRadius': 3, 'color': '#000000', 'fillColor': '#ffffff'
};
var map = new OpenLayers.map('map');
var layer = new OpenLayers.Vector.Layer('layer', {'style': style} );
var format = new OpenLayers.Format.GeoJSON({
    'internalProjection': new OpenLayers.Projection("EPSG:900913"),
    'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
layer.addFeatures(format.read(geoJson));
map.addLayer(layer);
map.events.register('zoomend', layer, function(event) {
  var zoom = event.object.getZoom();

  if (zoom > 13)
    style.fillColor = '#ff0000'; // red (R)
  else
    style.fillColor = '#ffffff'; // white (W)

  // adding the next line solves the problem, 
  // but to me it makes no sense
  // as the layer will be redrawn twice
  // in this case
  this.redraw();
});


This example gives each zoom level either
red (R) or white (W) features:


Apparently, changing the style will only be applied in the next zoom level,
as the features have already been processed.
For me this is undesired, is there any way to change the style AFTER zooming
and BEFORE applying the style / redrawing the features?

Many thanks in advance!

Regards,
Erik



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/change-layer-style-on-zooming-tp5014035.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list