[OpenLayers-Dev] SVG external graphic preserves aspect ratio

Harris Hudson hhudson at katmandu.org
Thu Apr 12 05:03:29 EDT 2012


Hi,

You might want to try changing your crucero.svg file in your
example and modify the main <svg> element (at line 4) and add
the preserveAspectRatio="none" attribute.

Eg;  <svg preserveAspectRatio="none" version="1.1" ...

Regards,

Harris.

> 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
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>



More information about the Dev mailing list