[OpenLayers-Users] change layer style on zooming

Bart van den Eijnden bartvde at opengeo.org
Mon Nov 5 08:17:11 PST 2012


Check out: http://dev.openlayers.org/releases/OpenLayers-2.12/examples/styles-context.html

that should give you a clue on how to handle this.

Best regards,
Bart

-- 
Bart van den Eijnden
OpenGeo - http://opengeo.org
Expert service straight from the developers.



On Nov 5, 2012, at 5:12 PM, eriktronic <etimmers at gmail.com> wrote:

> 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.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20121105/81a4fe4b/attachment.html>


More information about the Users mailing list