From 83030bed54307a1b114d3d8ef360ab0f7140e33b Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 25 Jul 2014 23:54:01 -0400 Subject: [PATCH] test visibility of gpx coords instead of just comparing extents. --- js/id/renderer/background.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 291248a82..f548d3606 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -149,10 +149,14 @@ iD.Background = function(context) { background.zoomToGpxLayer = function() { if (background.hasGpxLayer()) { - var gpx = d3.geo.bounds(gpxLayer.geojson()); + var viewport = context.map().extent().polygon(), + coords = _.reduce(gpxLayer.geojson().features, function(coords, feature) { + var c = feature.geometry.coordinates; + return _.union(coords, feature.geometry.type === 'Point' ? [c] : c); + }, []); - if (!context.map().extent().intersects(gpx)) { - context.map().extent(gpx); + if (!iD.geo.polygonIntersectsPolygon(viewport, coords)) { + context.map().extent(d3.geo.bounds(gpxLayer.geojson())); } } };