[OpenLayers-Users] Edit circles not showing when styleMap is specified

Jan van der Ven j.vanderven at magion.nl
Mon Dec 15 07:32:21 EST 2008


Dear list,



I have a map to which I add nine vector layers (all polygons). The layers
all should have their own color for rendering the features. I have too many
features to put them all in one layer, and use an attribute to style them.

The code I have for this is as follows:
  /**
   * Add the GeoJSON Layers
   **/
  function addGeoJSONLayers()
  {
    for(i=0; i<nLayers; i++)
    {
      var styles = new OpenLayers.StyleMap({
        "default": new OpenLayers.Style({
           fillColor:stateColors[i],
           strokeColor:stateColors[i],
           strokeWidth:2,
           fillOpacity:0.4
        })
      });
      var laag = new OpenLayers.Layer.GML(stateNames[i], url + "html/kml/" +
stateNames[i] + ".geojson", {format:OpenLayers.Format.GeoJSON, projection:
new OpenLayers.Projection("EPSG:28993"), resolutions:ress, visibility:false,
styleMap:styles});
      laag.events.on({"featuremodified": onFeatureModified});
      map.addLayer(laag);

      // These are the ones the user may work with
      selectControls[i]=new OpenLayers.Control.SelectFeature(laag,{onSelect:
onFeatureSelect, onUnselect:onFeatureUnselect, toggleKey:"ctrlKey",
multipleKey:"shiftKey", hover:false, toggle:false, clickout:false,
multiple:true, box:false});
      map.addControl(selectControls[i]);
    }
  }

I know only the topmost layer has an 'active' selectControl.

There is a button that the user can click to go from "select" mode to "edit"
mode. This essentially turns off all selectControls and creates and
activates a ModifyFeature control for the top layer:
      modifyControl = new
OpenLayers.Control.ModifyFeature(map.getLayersByName(stateNames[top])[0],
{mode:OpenLayers.Control.ModifyFeature.RESHAPE});
      map.addControl(modifyControl);
      modifyControl.activate();

The problem is that if the styleMap entry is present when creating the
layer, the edit handles (the circles) do not become visible and the mouse
cursor does not changes when moving to the corners of the polygon. But, if I
comment out the styleMap, like so:

      var laag = new OpenLayers.Layer.GML(stateNames[i], url + "html/kml/" +
stateNames[i] + ".geojson", {format:OpenLayers.Format.GeoJSON, projection:
new OpenLayers.Projection("EPSG:28993"), resolutions:ress, visibility:false
/*, styleMap:styles*/});

It works as expected.

My questions are:
1) Is this the right way to set the color for a layer?
2) If so, why would that influence the ModifyFeature control?
3) What can I do to fix this?

Thanks in advance.

Kind regards,



Jan van der Ven





More information about the Users mailing list