Tuesday, 12 June 2018

openlayers 2 - How to change the vertex style for editing?


When I use drag feature, then the circles on the polygon edge has the same style. For example, this OpenLayers site.


I need to change it, I mean they need to be a different color.


What is their (cycles) style attribute?



Answer




You should use vertexRenderIntent property of ModifyFeature control. For example:


var vertexStyle = {
strokeColor: "#ff0000",
fillColor: "#ff0000",
strokeOpacity: 1,
strokeWidth: 2,
pointRadius: 3,
graphicName: "cross"
}


var styleMap = new OpenLayers.StyleMap({
"default": OpenLayers.Feature.Vector.style['default'],
"vertex": vertexStyle
}, {extendDefault: false});

var layer = new OpenLayers.Layer.Vector('features', {styleMap: styleMap});
map.addControl(new OpenLayers.Control.ModifyFeature(layer, {vertexRenderIntent: "vertex"}));

At result we have the following style:


enter image description here



No comments:

Post a Comment