From 17fb2f64e5976c981f288c18407a6a7709a8282a Mon Sep 17 00:00:00 2001 From: Sajjad Anwar Date: Mon, 27 Oct 2014 14:26:46 -0400 Subject: [PATCH] Configurable minimum editable zoom --- API.md | 15 ++++++++++++++- js/id/behavior/edit.js | 2 +- js/id/id.js | 10 ++++++++++ js/id/renderer/map.js | 6 +++--- js/id/ui/notice.js | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 38c68f7dd..d9026c309 100644 --- a/API.md +++ b/API.md @@ -141,4 +141,17 @@ var iD = iD() .taginfo(iD.taginfo().endpoint('url')) .imagery(customImagery); -``` +``` + +### Minimum Editable Zoom + +The minimum zoom at which iD enters the edit mode is configured using the `iD().minEditableZoom()` accessor. The default value is 16. To change this initialise iD as + +```js + +var iD = iD(). + .minEditableZoom(zoom_level) + +``` + +This should be set with caution for performance reasons. The OpenStreetMap API has a limitation of 50000 nodes per request. \ No newline at end of file diff --git a/js/id/behavior/edit.js b/js/id/behavior/edit.js index 83d1060cf..7e3b6d405 100644 --- a/js/id/behavior/edit.js +++ b/js/id/behavior/edit.js @@ -1,7 +1,7 @@ iD.behavior.Edit = function(context) { function edit() { context.map() - .minzoom(16); + .minzoom(context.minEditableZoom()); } edit.off = function() { diff --git a/js/id/id.js b/js/id/id.js index 37c1940ba..982673a42 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -30,6 +30,16 @@ window.iD = function () { } }; + /* Accessor for setting minimum zoom for editing features. */ + + var minEditableZoom = 16; + context.minEditableZoom = function(_) { + if (!arguments.length) return minEditableZoom; + minEditableZoom = _; + connection.tileZoom(_); + return context; + }; + var history = iD.History(context), dispatch = d3.dispatch('enter', 'exit'), mode, diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index d5826faf5..36bdb9622 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -162,7 +162,7 @@ iD.Map = function(context) { iD.ui.flash(context.container()) .select('.content') .text(t('cannot_zoom')); - return setZoom(16, true); + return setZoom(context.minEditableZoom(), true); } projection @@ -342,7 +342,7 @@ iD.Map = function(context) { map.zoomTo = function(entity, zoomLimits) { var extent = entity.extent(context.graph()), zoom = map.extentZoom(extent); - zoomLimits = zoomLimits || [16, 20]; + zoomLimits = zoomLimits || [context.minEditableZoom(), 20]; map.centerZoom(extent.center(), Math.min(Math.max(zoom, zoomLimits[0]), zoomLimits[1])); }; @@ -406,7 +406,7 @@ iD.Map = function(context) { }; map.editable = function() { - return map.zoom() >= 16; + return map.zoom() >= context.minEditableZoom(); }; map.minzoom = function(_) { diff --git a/js/id/ui/notice.js b/js/id/ui/notice.js index b11ed3e3d..10205f783 100644 --- a/js/id/ui/notice.js +++ b/js/id/ui/notice.js @@ -5,7 +5,7 @@ iD.ui.Notice = function(context) { var button = div.append('button') .attr('class', 'zoom-to notice') - .on('click', function() { context.map().zoom(16); }); + .on('click', function() { context.map().zoom(context.minEditableZoom()); }); button.append('span') .attr('class', 'icon zoom-in-invert');