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

Alexandre Dube adube at mapgears.com
Mon Dec 15 08:55:31 EST 2008


Hi Jan,

I also had this problem and resolved it by adding theses lines :

rules = [new OpenLayers.Rule({
symbolizer: {strokeColor:"red",strokeWidth: 2},
elseFilter: true
})];
styles.styles["default"].addRules(rules);

Hope this helps,

Alexandre


Jan van der Ven wrote:
> 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
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list