[OpenLayers-Commits] r11813 - sandbox/tschaub/canvas/lib/OpenLayers/Renderer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Mar 30 17:55:38 EDT 2011


Author: tschaub
Date: 2011-03-30 14:55:37 -0700 (Wed, 30 Mar 2011)
New Revision: 11813

Modified:
   sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js
Log:
Guard against geometries with NaN coordinate values (fix for #3222).

Modified: sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js
===================================================================
--- sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js	2011-03-30 21:53:58 UTC (rev 11812)
+++ sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js	2011-03-30 21:55:37 UTC (rev 11813)
@@ -351,39 +351,40 @@
     drawPoint: function(geometry, style, featureId) {
         if(style.graphic !== false) {
             var pt = this.getLocalXY(geometry);
-            
-            if (style.externalGraphic) {
-                this.drawExternalGraphic(pt, style, featureId);
-            } else {
-                var p0 = pt[0];
-                var p1 = pt[1];
-                var twoPi = Math.PI*2;
-                var radius = style.pointRadius;
-                if(style.fill !== false) {
-                    this.setCanvasStyle("fill", style);
-                    this.canvas.beginPath();
-                    this.canvas.arc(p0, p1, radius, 0, twoPi, true);
-                    this.canvas.fill();
-                    if (this.hitDetection) {
-                        this.setHitContextStyle("fill", featureId, style);
-                        this.hitContext.beginPath();
-                        this.hitContext.arc(p0, p1, radius, 0, twoPi, true);
-                        this.hitContext.fill();
+            var p0 = pt[0];
+            var p1 = pt[1];
+            if (!isNaN(p0) && !isNaN(p1)) {
+                if (style.externalGraphic) {
+                    this.drawExternalGraphic(pt, style, featureId);
+                } else {
+                    var twoPi = Math.PI*2;
+                    var radius = style.pointRadius;
+                    if(style.fill !== false) {
+                        this.setCanvasStyle("fill", style);
+                        this.canvas.beginPath();
+                        this.canvas.arc(p0, p1, radius, 0, twoPi, true);
+                        this.canvas.fill();
+                        if (this.hitDetection) {
+                            this.setHitContextStyle("fill", featureId, style);
+                            this.hitContext.beginPath();
+                            this.hitContext.arc(p0, p1, radius, 0, twoPi, true);
+                            this.hitContext.fill();
+                        }
                     }
-                }
-                
-                if(style.stroke !== false) {
-                    this.setCanvasStyle("stroke", style);
-                    this.canvas.beginPath();
-                    this.canvas.arc(p0, p1, radius, 0, twoPi, true);
-                    this.canvas.stroke();
-                    if (this.hitDetection) {
-                        this.setHitContextStyle("stroke", featureId, style);
-                        this.hitContext.beginPath();
-                        this.hitContext.arc(p0, p1, radius, 0, twoPi, true);
-                        this.hitContext.stroke();
+
+                    if(style.stroke !== false) {
+                        this.setCanvasStyle("stroke", style);
+                        this.canvas.beginPath();
+                        this.canvas.arc(p0, p1, radius, 0, twoPi, true);
+                        this.canvas.stroke();
+                        if (this.hitDetection) {
+                            this.setHitContextStyle("stroke", featureId, style);
+                            this.hitContext.beginPath();
+                            this.hitContext.arc(p0, p1, radius, 0, twoPi, true);
+                            this.hitContext.stroke();
+                        }
+                        this.setCanvasStyle("reset");
                     }
-                    this.setCanvasStyle("reset");
                 }
             }
         }
@@ -441,16 +442,20 @@
         var len = components.length;
         context.beginPath();
         var start = this.getLocalXY(components[0]);
-        context.moveTo(start[0], start[1]);
-        for (var i=1; i<len; ++i) {
-            var pt = this.getLocalXY(components[i]);
-            context.lineTo(pt[0], pt[1]);
+        var x = start[0];
+        var y = start[1];
+        if (!isNaN(x) && !isNaN(y)) {
+            context.moveTo(start[0], start[1]);
+            for (var i=1; i<len; ++i) {
+                var pt = this.getLocalXY(components[i]);
+                context.lineTo(pt[0], pt[1]);
+            }
+            if (type === "fill") {
+                context.fill();
+            } else {
+                context.stroke();
+            }
         }
-        if (type === "fill") {
-            context.fill();
-        } else {
-            context.stroke();
-        }        
     },
     
     /**



More information about the Commits mailing list