Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want a custom vertex and polygon style for the Control.ModifyFeature. I want to keep the default fillColor of the polygon while editing it, not the blue. I thought this code will work but the blue is still there.

    var shapeStyle = {
        strokeOpacity: 1,
        strokeWidth: 1,
        fillColor: colorPoly,
        fillOpacity: 0.45,
    }

    var shapeStyle2 = {
        strokeOpacity: 1,
        strokeWidth: 1,
        fillColor: colorPoly,
        fillOpacity: 0.45,
        pointRadius: 3,
    }

    var styleMap = new OpenLayers.StyleMap({
           "default": shapeStyle,
            "vertex": shapeStyle2
    }, {extendDefault: false});

    var newShape = new OpenLayers.Layer.Vector( "Editable",{
            styleMap: styleMap 
    });

    var edit = new OpenLayers.Control.ModifyFeature(newShape,
         {
            title: "Modify Feature",
            displayClass: "olControlModifyFeature",
            styleMap: "default",
            vertexRenderIntent: "vertex"
    });

colorPoly is the variable containing the #color_code.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

ModifyFeature control doesn't have styleMap property. Style of edited feature comes from "select" render intent of layer's styleMap. So you should modify "select" instead "default".

Style of selected polygon and vertices are the different things and configures separately using vertexRenderIntent and virtualStyle properties of ModifyFeature control. For example:

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

var virtual = {
    strokeColor: "#00ff00",
    fillColor: "#00ff00",
    strokeOpacity: 1,
    strokeWidth: 2,
    pointRadius: 5,
    graphicName: "triangle"
};

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(vectors, {vertexRenderIntent: "vertex", virtualStyle: virtual}));
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.