[OpenLayers-Users] Fwd: Fill an OpenLayers.Geometry.LinearRing

Ruben Oliveira mail.roliveira at gmail.com
Fri Aug 23 04:15:13 PDT 2013


---------- Forwarded message ----------
From: Ruben Oliveira <mail.roliveira at gmail.com>
Date: Fri, Aug 23, 2013 at 10:39 AM
Subject: Re: [OpenLayers-Users] Fill an OpenLayers.Geometry.LinearRing
To: Juergen.Dankoweit at t-online.de


Hi Jürgen,

Thank you so much for your reply.
I got it working with your suggestion but I had to change this line:

pf.attributes = {strokecolor: "#123456", fillcolor: "#654321"};

to

pf.*style* = {stroke*C*olor: "#123456", fill*C*olor: "#654321"};

Anyway, I realize that now, the layer's render intent definition is not
working anymore. My expectation was that, although each feature vectors has
their own style definitions, once it got selected, the layer's selected
render intent would apply.

So here's my code, more detailed:

// create a select control
var selectControl = new OpenLayers.Control.SelectFeature(
 [],
 {clickout: true, toggle: false, multiple: false, hover: false, toggleKey:
"ctrlKey", multipleKey: "shiftKey"}
);

// create a layer and add it to map
// ////////////////////////////////////////////////////////////////////////
var layer_style = new OpenLayers.StyleMap({
            "select": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
            *fillColor: "#626262",*
            strokeColor: "#111111"},
OpenLayers.Feature.Vector.style["select"]))
        });


var vectorLayer = new OpenLayers.Layer.Vector("layer", {
 styleMap: layer_style,
 renderers: ['SVG', 'VML', 'Canvas']
});

 vectorLayer.events.on({"featureselected": function(e) {
  console.log(e.feature);
 }});

map.addLayer(vectorLayer); // map was created previously

// then I add a select control

map.addControl(selectControl);
selectControl.activate();
selectControl.setLayer(vectorLayer); // make layer "controllable"

// create the vector feature
var fv = new OpenLayers.Feature.Vector(linearRing); // lineaRing is an
instance of OpenLayers.Geometry.LinearRing created elsewere, not relevant
to this case
fv.style = {strokeColor: "#00FF00",* fillColor: "#0000FF"*, fillOpacity:
0.5}; // this works as expected

// add feature to layer
vectorLayer.addFeatures([fv]);



Because the layers styleMap states a render select intent to make fillColor:
"#626262" I was expecting the vector feature to have this fill color once
selected, but instead it remains as fillColor: "#0000FF"


Have any ideas how to specify a render intent to the Feature.Vector? I
tried to do it like this:

fv.style = new OpenLayers.StyleMap({
            "default": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
             fillColor: "#FF0000",
             strokeColor: "#919191",
             fillOpacity: 0.5
             }, OpenLayers.Feature.Vector.style["default"])),
            "select": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
             fillColor: "#00FF00",
             strokeColor: "yellow",
             fillOpacity: 0.5}, OpenLayers.Feature.Vector.style["select"]))
        });

But it appears that the OpenLayers.Feature.Vector object doesn't
accept an OpenLayers.StyleMap
object.


Thanks again.
Ruben


On Thu, Aug 22, 2013 at 6:50 PM, Jürgen Dankoweit <
Juergen.Dankoweit at t-online.de> wrote:

> Hello Ruben,
>
> Am 22.08.2013 19:34, schrieb mail.roliveira at gmail.com:
> > How can I set the fill and stroke colors of
> > a OpenLayers.Geometry.LinearRing
> > <
> http://dev.openlayers.org/docs/files/OpenLayers/Geometry/LinearRing-js.html#OpenLayers.Geometry.LinearRing
> >?
> >
> > I tried this way but no success:
> >
> > var linearRing = new OpenLayers.Geometry.LinearRing(pointArray);
> >
> > var feature = new OpenLayers.Feature.Vector(linearRing, {}, {fillColor:
> > "#00FF00"})
> >
> > feature is latter added to an OpenLayers.Layer.Vector layer.
> >
> > Is I set the style of the layer, I can paint the linearRing, but I have
> > several linearRings added on the same layer, and I want to have
> > individual fill on each one of the linearRings.
>
> In your styleMap-definition you have to define some placeholders. Look
> here:
>
> var sm = new OpenLayers.StyleMap({
>  stroke: true,
>  strokeColor: "\${strokecolor}",
>  fill: true,
>  fillColor: "\$fillcolor}
> });
> layer = new OpenLayers.Layer.Vector("LinearRings", {
>  styleMap: sm, ...});
>
> You have to use this like in the following example:
>
> var pf = new OpenLayers.Feature.Vector(...);
> if (pf) {
>  pf.attributes = {strokecolor: "#123456", fillcolor: "#654321"};
>  layer.addFeatures([pf]);
> }
>
> Best regards
>
> Juergen
>
> --
> Meine stets unfertige Homepage: www.dankoweit.de
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>



-- 
Melhores cumprimentos / Best regards,*
Ruben Oliveira*



-- 
Melhores cumprimentos / Best regards,*
Ruben Oliveira*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130823/fc8216e6/attachment.html>


More information about the Users mailing list