[OpenLayers-Users] GML, Point and Change the Size of the Circle...

Andreas Hocevar ahocevar at opengeo.org
Thu Sep 4 15:28:12 EDT 2008


On Thu, Sep 4, 2008 at 6:09 PM, Kit Plummer <kitplummer at gmail.com> wrote:
> Ok, so I'm able to draw circles with size relative to the size.  How
> do I keep the circle size relative to the zoom?  Is it possible to
> have them scale automatically?

Yes it is. You can do fancy stuff with the OpenLayers styles
framework. You might want to try something like this:

var style = new OpenLayers.Style(OpenLayers.Util.applyDefaults({
    pointRadius: "${scaledSize}"
}, OpenLayers.Feature.Vector.style["default"]), {
    context: {
        scaledSize: function(feature) {
            return feature.layer.map.getResolution() * feature.attributes.size;
        }
    }
});
var styleMap = new OpenLayers.StyleMap({"default": style});

Ok, so what does this do: instead of defining the pointRadius by a
feature attribute directly (like in my previous posting), we define a
style context. In this context, we have a scaledSize function, which
returns the size from the feature's size attribute, multiplied by the
current map resolution.

For a complete example with different context functions, see
http://www.openlayers.org/dev/examples/styles-context.html.

Regards,
Andreas.



More information about the Users mailing list