[OpenLayers-Dev] SVG external graphic preserves aspect ratio

Alberto Romeu aromeu at prodevelop.es
Wed Apr 11 15:02:28 EDT 2012


Hi,

I'm trying to apply a SVG external graphic to a points layer. What I 
need is that the graphic size will be scale dependant and not preserve 
the aspect ratio.

What I've found is whatever graphicHeight and graphicWidth I set to the 
externalGraphic, the SVG is rendered preserving the aspect ratio... If I 
use png the graphic is drawn correctly.

The style definition I'm using is very simple:

         var style = new OpenLayers.Style(OpenLayers.Util.applyDefaults({
             graphicWidth: 100 ,
             graphicHeight: 600 ,
             externalGraphic: 'img/petrolero.svg',
             fill: false,
             stroke: false,
             pointRadius: 0,
             rotation: "${rotation}",
             fillOpacity: 1
         }, OpenLayers.Feature.Vector.style["default"]));

         var styleMap = new OpenLayers.StyleMap({"default": style, 
"select": style});


         layer = new OpenLayers.Layer.Vector('Points', {
             styleMap: styleMap
         });


Anyway, I've published an example [1] of what's happening. The green 
boats are PNG being scaled correctly, the brown ones are SVG not being 
scaled correctly as they preserve the aspect ratio, both have the same 
graphicHeight and graphicWidth. Sometimes when the layer is loaded the 
SVG is drawn correctly but when a zoom is applied then happens the 
aspect ratio issue...

Am I missing something? Is there a way to use SVG in the way I need?

Best regards.

[1] http://gis.prodevelop.es/openlayers/svg.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20120411/f568adbf/attachment.html


More information about the Dev mailing list