Only partially draw really long polylines
authorRichard Fairhurst <richard@systemeD.net>
Fri, 9 Nov 2018 15:50:12 +0000 (15:50 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Fri, 9 Nov 2018 15:50:12 +0000 (15:50 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/WayUI.as

index f45a2c9..2e87b7e 100644 (file)
@@ -207,6 +207,19 @@ package net.systemeD.halcyon {
                public function lat2coord(a:Number):Number      { return -(lat2latp(a)-basey)*scalefactor; }
                public function coord2lat(a:Number):Number      { return latp2lat(a/-scalefactor+basey); }
 
+               // Does a segment cross the map?
+               public function segmentCrosses(n0:Node,n1:Node):Boolean {
+                       var xmin:Number = Math.min(n0.lon,n1.lon),
+                               ymin:Number = Math.min(n0.lat,n1.lat),
+                               xmax:Number = Math.max(n0.lon,n1.lon),
+                               ymax:Number = Math.max(n0.lat,n1.lat);
+                       return ( (xmin>=edge_l && xmin<=edge_r) ||
+                                        (xmax>=edge_l && xmax<=edge_r) ||
+                                        (xmin< edge_l && xmax> edge_r) ) &&
+                                  ( (ymin>=edge_b && ymin<=edge_t) ||
+                                        (ymax>=edge_b && ymax<=edge_t) ||
+                                        (ymin< edge_b && ymax> edge_t) );
+               }
 
                // ------------------------------------------------------------------------------------------
                /** Resize map size based on current stage and height */
index cc7d070..ebbcc47 100644 (file)
@@ -175,6 +175,7 @@ package net.systemeD.halcyon {
                        for each (way in o.waysInside) {
                                if (!wayuis[way.id]) { createWayUI(way); }
                                else if (redraw) { wayuis[way.id].recalculate(); wayuis[way.id].redraw(); }
+                               else if (wayuis[way.id].partial) { wayuis[way.id].redraw(); wayuis[way.id].updateHighlights(); }
                                else wayuis[way.id].updateHighlights();//dubious
                        }
 
index 29a44e6..ed9fba7 100644 (file)
@@ -24,6 +24,8 @@ package net.systemeD.halcyon {
                public var centroid_y:Number;                           //  |
                /** Angle at each node */
                public var heading:Array=new Array();
+               /** Is this only partially drawn? */
+               public var partial:Boolean=false;
                /** vertex to draw exclusively, or not at all (used by DragWayNode) */ 
                public var drawExcept:Number;
                /** " */
@@ -155,7 +157,7 @@ package net.systemeD.halcyon {
                                // Currently this means if you highlight an object then scroll, nodes will scroll
                                // into view that should be highlighted but aren't.
                                if (settings.hoverway==false || 
-                                   settings.selectedway==false || 
+                                   settings.selectedway==false ||
                                    node.within(paint.map.edge_l, paint.map.edge_r, paint.map.edge_t, paint.map.edge_b)) {
                                    paint.setHighlight(node,settings); // Triggers redraw if required
                                }
@@ -215,7 +217,9 @@ package net.systemeD.halcyon {
             }
             heading[way.length-1] = heading[way.length-2];
 
-            pathlength *= paint.map.scalefactor;
+            pathlength *= paint.map.scalefactor; // length in pixels
+            partial = !(way.isArea()) && (pathlength>paint.map.mapwidth*6);
+
             patharea /= 2;
             if (patharea != 0 && way.isArea()) {
                 centroid_x = paint.map.lon2coord(cx / patharea / 6);
@@ -268,10 +272,29 @@ package net.systemeD.halcyon {
                        }
 
                        // Do we have to draw all nodes in the way?
+                       indexStart=0; indexEnd=Way(entity).length;
                        var hasFills:Boolean=styleList.hasFills();
-                       if (isNaN(drawOnly) || hasFills) {
-                               indexStart=0; indexEnd=Way(entity).length; 
+                       var i:uint;
+                       if (hasFills) {
+                               // draw full line
+                       } else if (partial) {
+                               // long polyline (e.g. powerline) so just draw the on-screen section
+                               var isWithin:Boolean=false;
+                               for (i=0; i<Way(entity).length-1; i++) {
+                                       if (paint.map.segmentCrosses(Way(entity).getNode(i), Way(entity).getNode(i+1) )) {
+                                               indexStart=Math.max(i-1,0); isWithin=true; break;
+                                       }
+                               }
+                               for (i=Way(entity).length-2; i>indexStart; i--) {
+                                       if (paint.map.segmentCrosses(Way(entity).getNode(i), Way(entity).getNode(i+1) )) {
+                                               indexEnd=Math.min(i+2,Way(entity).length); isWithin=true; break;
+                                       }
+                               }
+                               if (!isWithin) return true;
+                       } else if (isNaN(drawOnly)) {
+                               // draw full line
                        } else {
+                               // we only need to redraw around a dragged vertex
                                indexStart=Math.max(0,drawOnly-1);
                                indexEnd  =Math.min(drawOnly+2,Way(entity).length);
                        }
@@ -330,7 +353,7 @@ package net.systemeD.halcyon {
                                        }
                                }
                                
-                               if (styleList.textStyles[subpart] && isNaN(drawExcept)) {
+                               if (styleList.textStyles[subpart] && isNaN(drawExcept) && !partial) {
                                        var t:TextStyle=styleList.textStyles[subpart];
                                        interactive||=t.interactive;
                                        roadname=new Sprite(); addToLayer(roadname,NAMESPRITE);
@@ -352,7 +375,7 @@ package net.systemeD.halcyon {
 
                        // Draw icons
                        var r:Number;
-                       for (var i:uint = indexStart; i < indexEnd; i++) {
+                       for (i = indexStart; i < indexEnd; i++) {
                 var node:Node = Way(entity).getNode(i);
                                var nodeStateClasses:Object={};
 //                             if (i==0) { nodetags['_heading']= heading[i]; }