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

Jan van der Ven j.vanderven at magion.nl
Mon Dec 15 09:22:51 EST 2008


Dear Alexandre,


Thanks for the quick reply.

I tried it out right away, and modified the code as shown below:

  function addGeoJSONLayers()
  {
    for(i=0; i<nLayers; i++)
    {
      mystyles = new OpenLayers.StyleMap(
        {
          "default": new OpenLayers.Style({
          })
        });

      myrules = new OpenLayers.Rule({symbolizer:{fillColor:stateColors[i],
strokeColor:stateColors[i], strokeWidth:2, fillOpacity:0.4},
elseFilter:true});
      mystyles.styles["default"].addRules(myrules);
      var laag = new OpenLayers.Layer.GML(stateNames[i], biskurl +
"html/kml/" + stateNames[i] + ".geojson", {format:OpenLayers.Format.GeoJSON,
projection: new OpenLayers.Projection("EPSG:28993"), resolutions:ress,
visibility:false, styleMap:mystyles });
[...]

Unfortunately, the behavior still is that the handles do not appear.

Kind regards,


Jan
 

-----Original Message-----
From: Alexandre Dube [mailto:adube at mapgears.com] 
Sent: Monday, December 15, 2008 14:56
To: j.vanderven at magion.nl
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] Edit circles not showing when styleMap is
specified

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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.176 / Virus Database: 270.9.16/1842 - Release Date: 14-12-2008
12:28




More information about the Users mailing list