From 5c860be87705fe55e3ca66d95687178d51cb1482 Mon Sep 17 00:00:00 2001 From: Rowan Hogan Date: Sun, 14 Jun 2015 12:37:37 +1000 Subject: [PATCH] Moved minimap gpx layer methods to the background gpx layer handlers --- js/id/renderer/background.js | 3 +++ js/id/ui/background.js | 6 +++--- js/id/ui/map_in_map.js | 18 +++++------------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 3e5d4b5f6..45a355369 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -142,6 +142,7 @@ iD.Background = function(context) { reader.onload = function(e) { gpxLayer.geojson(toGeoJSON.gpx(toDom(e.target.result))); + iD.ui.MapInMap.gpxLayer.geojson(toGeoJSON.gpx(toDom(e.target.result))); background.zoomToGpxLayer(); dispatch.change(); }; @@ -167,6 +168,7 @@ iD.Background = function(context) { background.toggleGpxLayer = function() { gpxLayer.enable(!gpxLayer.enable()); + iD.ui.MapInMap.gpxLayer.enable(!iD.ui.MapInMap.gpxLayer.enable()); dispatch.change(); }; @@ -263,6 +265,7 @@ iD.Background = function(context) { if (gpx) { d3.text(gpx, function(err, gpxTxt) { gpxLayer.geojson(toGeoJSON.gpx(toDom(gpxTxt))); + iD.ui.MapInMap.gpxLayer.geojson(toGeoJSON.gpx(toDom(gpxTxt))); dispatch.change(); }); } diff --git a/js/id/ui/background.js b/js/id/ui/background.js index a2b876abb..3a674d66c 100644 --- a/js/id/ui/background.js +++ b/js/id/ui/background.js @@ -255,9 +255,9 @@ iD.ui.Background = function(context) { var controls = content.append('div') .attr('class', 'controls-list'); - var label = controls.append('label'); + var minimapLabel = controls.append('label'); - label.classed('minimap-toggle', true) + minimapLabel.classed('minimap-toggle', true) .append('input') .attr('type', 'checkbox') .on('change', function() { @@ -267,7 +267,7 @@ iD.ui.Background = function(context) { d3.event.preventDefault(); }); - label.append('span') + minimapLabel.append('span') .text(t('background.toggle_minimap')); var adjustments = content.append('div') diff --git a/js/id/ui/map_in_map.js b/js/id/ui/map_in_map.js index f2500be59..04a287650 100644 --- a/js/id/ui/map_in_map.js +++ b/js/id/ui/map_in_map.js @@ -2,8 +2,10 @@ iD.ui.MapInMap = function(context) { var key = '/'; function map_in_map(selection) { + var backgroundLayer = iD.TileLayer(), - gpxLayer = iD.GpxLayer(context), + dispatch = d3.dispatch('change'), + gpxLayer = iD.GpxLayer(context, dispatch), overlayLayer = iD.TileLayer(), projection = iD.geo.RawMercator(), zoom = d3.behavior.zoom() @@ -14,6 +16,8 @@ iD.ui.MapInMap = function(context) { zDiff = 6, // by default, minimap renders at (main zoom - 6) tStart, tLast, tCurr, kLast, kCurr, tiles, svg, gpx, timeoutId; + iD.ui.MapInMap.gpxLayer = gpxLayer; + function ztok(z) { return 256 * Math.pow(2, z); } function ktoz(k) { return Math.log(k) / Math.LN2 - 8; } @@ -278,18 +282,6 @@ iD.ui.MapInMap = function(context) { if (drawn.full === true) redraw(); }); - function toDom(x) { - return (new DOMParser()).parseFromString(x, 'text/xml'); - } - - var q = iD.util.stringQs(location.hash.substring(1)); - var gpx = q.gpx; - if (gpx) { - d3.text(gpx, function(err, gpxTxt) { - gpxLayer.geojson(toGeoJSON.gpx(toDom(gpxTxt))); - queueRedraw(); - }); - } redraw(); var keybinding = d3.keybinding('map-in-map')