Avoid asking DOM if layers are classed disabled in map.editable

`map.editable` is hot code because it's called frequently by the `isHiddenX`
tests in `features.js`.  It's much more efficient to just ask the osm layer
whether it is enabled, than to use D3 to find that layer in the DOM and check
whether it's classed `disabled`
This commit is contained in:
Bryan Housel
2019-04-22 22:12:42 -04:00
parent 0636401ab6
commit 7dce4bb161
2 changed files with 6 additions and 6 deletions

View File

@@ -887,16 +887,16 @@ export function rendererMap(context) {
map.editable = function() {
var osmLayer = surface.selectAll('.data-layer.osm');
if (!osmLayer.empty() && osmLayer.classed('disabled')) return false;
var layer = context.layers().layer('osm');
if (!layer || !layer.enabled()) return false;
return map.zoom() >= context.minEditableZoom();
};
map.notesEditable = function() {
var noteLayer = surface.selectAll('.data-layer.notes');
if (!noteLayer.empty() && noteLayer.classed('disabled')) return false;
var layer = context.layers().layer('notes');
if (!layer || !layer.enabled()) return false;
return map.zoom() >= context.minEditableZoom();
};

View File

@@ -48,9 +48,9 @@ export function svgOsm(projection, context, dispatch) {
}
drawOsm.enabled = function(_) {
drawOsm.enabled = function(val) {
if (!arguments.length) return enabled;
enabled = _;
enabled = val;
if (enabled) {
showLayer();