From 6087aae21f77c7963e83114bf22d5749be38cf1b Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Sun, 22 Mar 2020 10:57:17 -0700 Subject: [PATCH] Remove map convenience functions of context --- modules/behavior/draw.js | 2 +- modules/behavior/draw_way.js | 2 +- modules/behavior/lasso.js | 2 +- modules/behavior/paste.js | 2 +- modules/core/context.js | 8 -------- modules/core/history.js | 4 ++-- modules/modes/add_note.js | 2 +- modules/modes/drag_node.js | 6 +++--- modules/modes/drag_note.js | 2 +- modules/modes/move.js | 6 +++--- modules/modes/rotate.js | 2 +- modules/modes/select.js | 2 +- modules/operations/circularize.js | 2 +- modules/operations/delete.js | 2 +- modules/operations/disconnect.js | 2 +- modules/operations/extract.js | 2 +- modules/operations/move.js | 2 +- modules/operations/orthogonalize.js | 2 +- modules/operations/reflect.js | 2 +- modules/operations/rotate.js | 2 +- modules/svg/labels.js | 2 +- modules/ui/init.js | 2 +- modules/ui/sections/raw_membership_editor.js | 2 +- modules/ui/zoom.js | 18 +++++++----------- 24 files changed, 34 insertions(+), 46 deletions(-) diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index f8b211bad..7a5afb0f2 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -152,7 +152,7 @@ export function behaviorDraw(context) { d3_event.preventDefault(); d3_event.stopPropagation(); - var currSpace = context.mouse(); + var currSpace = context.map().mouse(); if (_disableSpace && _lastSpace) { var dist = geoVecLength(_lastSpace, currSpace); if (dist > tolerance) { diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 2d52d9311..709e0a86b 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -129,7 +129,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph) { loc = targetLoc; } else if (targetNodes) { // snap to way - a line target with `.nodes` - var choice = geoChooseEdge(targetNodes, context.mouse(), context.projection, _drawNode.id); + var choice = geoChooseEdge(targetNodes, context.map().mouse(), context.projection, _drawNode.id); if (choice) { loc = choice.loc; } diff --git a/modules/behavior/lasso.js b/modules/behavior/lasso.js index 46e5ff4e4..4dc40720f 100644 --- a/modules/behavior/lasso.js +++ b/modules/behavior/lasso.js @@ -34,7 +34,7 @@ export function behaviorLasso(context) { context.surface().call(lasso); } - lasso.p(context.mouse()); + lasso.p(context.map().mouse()); } diff --git a/modules/behavior/paste.js b/modules/behavior/paste.js index 22d743c98..5976bd4f0 100644 --- a/modules/behavior/paste.js +++ b/modules/behavior/paste.js @@ -16,7 +16,7 @@ export function behaviorPaste(context) { d3_event.preventDefault(); var baseGraph = context.graph(); - var mouse = context.mouse(); + var mouse = context.map().mouse(); var projection = context.projection; var viewport = geoExtent(projection.clipExtent()).polygon(); diff --git a/modules/core/context.js b/modules/core/context.js index ba0161278..6d5b469f1 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -512,14 +512,6 @@ export function coreContext() { } _map = rendererMap(context); - context.mouse = _map.mouse; - context.extent = _map.extent; - context.pan = _map.pan; - context.zoomIn = _map.zoomIn; - context.zoomOut = _map.zoomOut; - context.zoomInFurther = _map.zoomInFurther; - context.zoomOutFurther = _map.zoomOutFurther; - context.redrawEnable = _map.redrawEnable; Object.values(services).forEach(service => { if (service && typeof service.init === 'function') { diff --git a/modules/core/history.js b/modules/core/history.js index d0bd896cd..46dc56257 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -549,7 +549,7 @@ export function coreHistory(context) { if (missing.length && osm) { loadComplete = false; - context.redrawEnable(false); + context.map().redrawEnable(false); var loading = uiLoading(context).blocking(true); context.container().call(loading); @@ -576,7 +576,7 @@ export function coreHistory(context) { if (err || !missing.length) { loading.close(); - context.redrawEnable(true); + context.map().redrawEnable(true); dispatch.call('change'); dispatch.call('restore', this); } diff --git a/modules/modes/add_note.js b/modules/modes/add_note.js index 81112e85a..a468a3a52 100644 --- a/modules/modes/add_note.js +++ b/modules/modes/add_note.js @@ -30,7 +30,7 @@ export function modeAddNote(context) { osm.replaceNote(note); // force a reraw (there is no history change that would otherwise do this) - context.pan([0,0]); + context.map().pan([0,0]); context .selectedNoteID(note.id) diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index c6022f579..3f5221b68 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -51,7 +51,7 @@ export function modeDragNode(context) { function startNudge(entity, nudge) { if (_nudgeInterval) window.clearInterval(_nudgeInterval); _nudgeInterval = window.setInterval(function() { - context.pan(nudge); + context.map().pan(nudge); doMove(entity, nudge); }, 50); } @@ -207,7 +207,7 @@ export function modeDragNode(context) { } } else if (targetNodes) { // snap to way - a line target with `.nodes` - edge = geoChooseEdge(targetNodes, context.mouse(), context.projection, end.id); + edge = geoChooseEdge(targetNodes, context.map().mouse(), context.projection, end.id); if (edge) { loc = edge.loc; } @@ -379,7 +379,7 @@ export function modeDragNode(context) { ); } else if (target && target.type === 'way') { - var choice = geoChooseEdge(context.graph().childNodes(target), context.mouse(), context.projection, entity.id); + var choice = geoChooseEdge(context.graph().childNodes(target), context.map().mouse(), context.projection, entity.id); context.replace( actionAddMidpoint({ loc: choice.loc, diff --git a/modules/modes/drag_note.js b/modules/modes/drag_note.js index 11a40d3fb..ed5fbba17 100644 --- a/modules/modes/drag_note.js +++ b/modules/modes/drag_note.js @@ -27,7 +27,7 @@ export function modeDragNote(context) { function startNudge(nudge) { if (_nudgeInterval) window.clearInterval(_nudgeInterval); _nudgeInterval = window.setInterval(function() { - context.pan(nudge); + context.map().pan(nudge); doMove(nudge); }, 50); } diff --git a/modules/modes/move.js b/modules/modes/move.js index d91a85d4f..e6a7b78ba 100644 --- a/modules/modes/move.js +++ b/modules/modes/move.js @@ -59,7 +59,7 @@ export function modeMove(context, entityIDs, baseGraph) { fn = context.overwrite; } - var currMouse = context.mouse(); + var currMouse = context.map().mouse(); var origMouse = context.projection(_origin); var delta = geoVecSubtract(geoVecSubtract(currMouse, origMouse), nudge); @@ -71,7 +71,7 @@ export function modeMove(context, entityIDs, baseGraph) { function startNudge(nudge) { if (_nudgeInterval) window.clearInterval(_nudgeInterval); _nudgeInterval = window.setInterval(function() { - context.pan(nudge); + context.map().pan(nudge); doMove(nudge); }, 50); } @@ -87,7 +87,7 @@ export function modeMove(context, entityIDs, baseGraph) { function move() { doMove(); - var nudge = geoViewportEdge(context.mouse(), context.map().dimensions()); + var nudge = geoViewportEdge(context.map().mouse(), context.map().dimensions()); if (nudge) { startNudge(nudge); } else { diff --git a/modules/modes/rotate.js b/modules/modes/rotate.js index 53080a27b..419dd2796 100644 --- a/modules/modes/rotate.js +++ b/modules/modes/rotate.js @@ -74,7 +74,7 @@ export function modeRotate(context, entityIDs) { } - var currMouse = context.mouse(); + var currMouse = context.map().mouse(); var currAngle = Math.atan2(currMouse[1] - _pivot[1], currMouse[0] - _pivot[0]); if (typeof _prevAngle === 'undefined') _prevAngle = currAngle; diff --git a/modules/modes/select.js b/modules/modes/select.js index accb768c7..edefddd23 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -159,7 +159,7 @@ export function modeSelect(context, selectedIDs) { if (entity && entity.geometry(context.graph()) === 'relation') { _suppressMenu = true; } else { - var point = context.mouse(); + var point = context.map().mouse(); var viewport = geoExtent(context.projection.clipExtent()).polygon(); if (point && geoPointInPolygon(point, viewport)) { diff --git a/modules/operations/circularize.js b/modules/operations/circularize.js index bca8a36d2..f3cad4600 100644 --- a/modules/operations/circularize.js +++ b/modules/operations/circularize.js @@ -67,7 +67,7 @@ export function operationCircularize(selectedIDs, context) { return 'multiple_blockers'; } return actionDisableds[0]; - } else if (_extent.percentContainedIn(context.extent()) < 0.8) { + } else if (_extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large'; } else if (someMissing()) { return 'not_downloaded'; diff --git a/modules/operations/delete.js b/modules/operations/delete.js index 1e698a085..7ce5ec03f 100644 --- a/modules/operations/delete.js +++ b/modules/operations/delete.js @@ -72,7 +72,7 @@ export function operationDelete(selectedIDs, context) { operation.disabled = function() { - if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { + if (extent.area() && extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large'; } else if (someMissing()) { return 'not_downloaded'; diff --git a/modules/operations/disconnect.js b/modules/operations/disconnect.js index eabd849e7..fc93d32df 100644 --- a/modules/operations/disconnect.js +++ b/modules/operations/disconnect.js @@ -84,7 +84,7 @@ export function operationDisconnect(selectedIDs, context) { if (reason) return reason; } - if (disconnectingWayID && extent.percentContainedIn(context.extent()) < 0.8) { + if (disconnectingWayID && extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large.single'; } else if (disconnectingWayID && someMissing()) { return 'not_downloaded'; diff --git a/modules/operations/extract.js b/modules/operations/extract.js index 2e6d3043f..6aa040754 100644 --- a/modules/operations/extract.js +++ b/modules/operations/extract.js @@ -66,7 +66,7 @@ export function operationExtract(selectedIDs, context) { return reason; } else if (geometry === 'vertex' && selectedIDs.some(context.hasHiddenConnections)) { return 'connected_to_hidden'; - } else if (extent && extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { + } else if (extent && extent.area() && extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large'; } diff --git a/modules/operations/move.js b/modules/operations/move.js index 1f9de7748..df8fe55a0 100644 --- a/modules/operations/move.js +++ b/modules/operations/move.js @@ -26,7 +26,7 @@ export function operationMove(selectedIDs, context) { operation.disabled = function() { - if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { + if (extent.area() && extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large'; } else if (someMissing()) { return 'not_downloaded'; diff --git a/modules/operations/orthogonalize.js b/modules/operations/orthogonalize.js index ed3eaf834..b6740990a 100644 --- a/modules/operations/orthogonalize.js +++ b/modules/operations/orthogonalize.js @@ -90,7 +90,7 @@ export function operationOrthogonalize(selectedIDs, context) { } return actionDisableds[0]; } else if (_type !== 'corner' && - _extent.percentContainedIn(context.extent()) < 0.8) { + _extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large'; } else if (someMissing()) { return 'not_downloaded'; diff --git a/modules/operations/reflect.js b/modules/operations/reflect.js index bba82651c..f64e937be 100644 --- a/modules/operations/reflect.js +++ b/modules/operations/reflect.js @@ -44,7 +44,7 @@ export function operationReflect(selectedIDs, context, axis) { // don't cache this because the visible extent could change operation.disabled = function() { - if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { + if (extent.area() && extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large'; } else if (someMissing()) { return 'not_downloaded'; diff --git a/modules/operations/rotate.js b/modules/operations/rotate.js index 7fd8a7b83..6d64784cc 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -26,7 +26,7 @@ export function operationRotate(selectedIDs, context) { operation.disabled = function() { - if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { + if (extent.area() && extent.percentContainedIn(context.map().extent()) < 0.8) { return 'too_large'; } else if (someMissing()) { return 'not_downloaded'; diff --git a/modules/svg/labels.js b/modules/svg/labels.js index 64446d994..3b9a44f17 100644 --- a/modules/svg/labels.js +++ b/modules/svg/labels.js @@ -703,7 +703,7 @@ export function svgLabels(projection, context) { layers.selectAll('.nolabel') .classed('nolabel', false); - var mouse = context.mouse(); + var mouse = context.map().mouse(); var graph = context.graph(); var selectedIDs = context.selectedIDs(); var ids = []; diff --git a/modules/ui/init.js b/modules/ui/init.js index a08d81d67..7d6a028fc 100644 --- a/modules/ui/init.js +++ b/modules/ui/init.js @@ -354,7 +354,7 @@ export function uiInit(context) { return function() { if (d3_select('.combobox').size()) return; d3_event.preventDefault(); - context.pan(d, 100); + context.map().pan(d, 100); }; } diff --git a/modules/ui/sections/raw_membership_editor.js b/modules/ui/sections/raw_membership_editor.js index 54ccecfc7..8633d13f0 100644 --- a/modules/ui/sections/raw_membership_editor.js +++ b/modules/ui/sections/raw_membership_editor.js @@ -145,7 +145,7 @@ export function uiSectionRawMembershipEditor(context) { }); } else { - context.intersects(context.extent()).forEach(function(entity) { + context.intersects(context.map().extent()).forEach(function(entity) { if (entity.type !== 'relation' || entity.id === entityID) return; var value = baseDisplayLabel(entity); diff --git a/modules/ui/zoom.js b/modules/ui/zoom.js index e986a5532..e83de81dd 100644 --- a/modules/ui/zoom.js +++ b/modules/ui/zoom.js @@ -11,45 +11,41 @@ import { tooltip } from '../util/tooltip'; export function uiZoom(context) { + var zooms = [{ id: 'zoom-in', icon: 'plus', title: t('zoom.in'), - action: context.zoomIn, + action: zoomIn, key: '+' }, { id: 'zoom-out', icon: 'minus', title: t('zoom.out'), - action: context.zoomOut, + action: zoomOut, key: '-' }]; - function zoomIn() { d3_event.preventDefault(); - context.zoomIn(); + context.map().zoomIn(); } - function zoomOut() { d3_event.preventDefault(); - context.zoomOut(); + context.map().zoomOut(); } - function zoomInFurther() { d3_event.preventDefault(); - context.zoomInFurther(); + context.map().zoomInFurther(); } - function zoomOutFurther() { d3_event.preventDefault(); - context.zoomOutFurther(); + context.map().zoomOutFurther(); } - return function(selection) { var button = selection.selectAll('button') .data(zooms)