[OpenLayers-Dev] Creating shadowed or stroked and filled lines

Eric Lemoine eric.lemoine at camptocamp.com
Tue Nov 24 00:10:49 EST 2009


On Monday, November 23, 2009, fredarters <fredarters at gmail.com> wrote:
>
> I am drawing lines on openlayers for a project.  Using a prior map client I
> would draw a line with a 1px black border around a 2px colored line using a
> stroke and fill values.
>
> However, in openlayers the fill values for the style of a line are only used
> for polygons, not lines.  I attempted to achieve the same effect by drawing
> two separate lines on the same path, a black line 4px wide and a color line
> 2px wide.  For some reason, only the 2px color line shows up on the map.  If
> I pause the rendering between the two lines, they both render but as soon as
> I zoom or pan the map the first (4px black) line dissapears and only the
> second 2px color line remains rendered.
>
> Any idea why that might be happening or have a better idea how to achieve
> that effect?
>
> I am doing something like this:
>
>         // first line
>         var lineBg = new OpenLayers.Geometry.LineString(points);
>
>         var theStyleBg =  {
>             strokeColor: '#000000',
>             strokeWidth: 4,
>             strokeLinecap: 'round'
>         };
>
>         var featureBg = new OpenLayers.Feature.Vector(lineBg, null,
> theStyleBg);
>         featureBg.id = 'linebg';
>         this.pathLayer.addFeatures([featurebg]);
>
>         // second line
>         var line = new OpenLayers.Geometry.LineString(points);
>
>         var theStyle =  {
>             strokeColor: '#eedd00',
>             strokeWidth: 2,
>             strokeLinecap: 'round'
>         };
>
>         var feature = new OpenLayers.Feature.Vector(line, null, theStyle);
>         feature.id = 'line';
>         this.pathLayer.addFeatures([feature]);


Hi. Your lines share the same point objects, this might be the problem.

Cheers,

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com



More information about the Dev mailing list