Problem with rotated points renderer VML (IE <9)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with rotated points renderer VML (IE <9)

jezaustin
Hi,
Was having some trouble with rotating externalGraphics with the VML renderer. The String "NaN" was winding up in style.rotation, which ruined the width and height calculations.

A simple amendment to OpenLayers/Renderer/VML.js sorts it out, so I wanted to share the diff but couldn't be bothered registering with the bug tracker. So here it is:

--- a/lib/OpenLayers/Renderer/VML.js
+++ b/lib/OpenLayers/Renderer/VML.js
@@ -354,7 +354,7 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
      */
     graphicRotate: function(node, xOffset, yOffset, style) {
         var style = style || node._style;
-        var rotation = style.rotation || 0;
+        var rotation = parseFloat(style.rotation) || 0;
         
         var aspectRatio, size;
         if (!(style.graphicWidth && style.graphicHeight)) {
@@ -430,7 +430,7 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
         // do the rotation again on a box, so we know the insertion point
         var centerPoint = new OpenLayers.Geometry.Point(-xOffset, -yOffset);
         var imgBox = new OpenLayers.Bounds(0, 0, width, height).toGeometry();
-        imgBox.rotate(style.rotation, centerPoint);
+        imgBox.rotate(parseFloat(style.rotation) || 0, centerPoint);
         var imgBounds = imgBox.getBounds();
 
         node.style.left = Math.round(

Thanks, Jez Austin.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with rotated points renderer VML (IE <9)

Marc Jansen-2
Hi Jez,

would you be so kind and turn this into a pull request over at
http://github.com/openlayers/openlayers ?

This way reviewing can happen way easier. Thanks for your work so far,

Marc



On 12.04.2013 19:26, jezaustin wrote:

> Hi,
> Was having some trouble with rotating externalGraphics with the VML
> renderer. The String "NaN" was winding up in style.rotation, which ruined
> the width and height calculations.
>
> A simple amendment to OpenLayers/Renderer/VML.js sorts it out, so I wanted
> to share the diff but couldn't be bothered registering with the bug tracker.
> So here it is:
>
>
>
> Thanks, Jez Austin.
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-with-rotated-points-renderer-VML-IE-9-tp5046463.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev


--

   Dipl.-Geogr. Marc Jansen
   — Anwendungsentwickler —

   terrestris GmbH & Co. KG
   Pützchens Chaussee 56
   53227 Bonn

   Tel:   +49 (0)228 / 96 28 99 -53
   Fax:   +49 (0)228 / 96 28 99 -57

   Email: [hidden email]
   Web:   http://www.terrestris.de

   Amtsgericht Bonn, HRA 6835, Komplementärin: terrestris Verwaltungs-
   gesellschaft mbH, vertreten durch: Hinrich Paulsen, Till Adams

_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with rotated points renderer VML (IE <9)

jezaustin
Hi Marc,
thanks, I've done that.

Jez.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with rotated points renderer VML (IE <9)

jezaustin
Hi
pull request was closed because the string "NaN" is a silly value for rotation to have. I consider the proper value NaN to be a reasonable value, but I notice that when a style's context method returns the value NaN, it gets coerced to a string when the token is interpolated.

So either
  a) add documentation clarifying that the application's context methods must guarantee not to return NaN,
  b) OpenLayers.Style.createLiteral detects the string "NaN" and returns the value NaN instead.
  c) OpenLayers.String.format detects when the template is entirely composed of one token, and in that case avoid coercing to a string.

I think a) is suboptimal, and if that's the decision is should be documented.
b) is a bit hacky but probably low risk, unless anyone's application relies on receiving the string "NaN"!
c) is the most appealing solution, but since OpenLayers.String.format is in wider use it is higher risk.

Which of these solutions is preferred?

thanks, Jez.