Skip to content

Commit

Permalink
Treat osm layer like other vector layers and give it a toggle
Browse files Browse the repository at this point in the history
(closes #2904)
  • Loading branch information
bhousel committed Sep 19, 2017
1 parent 8a384a9 commit 5a8709b
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 36 deletions.
4 changes: 4 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ en:
description: Map Data
key: F
data_layers: Data Layers
layers:
osm:
tooltip: Map data from OpenStreetMap
title: OpenStreetMap data
fill_area: Fill Areas
map_features: Map Features
autohidden: "These features have been automatically hidden because too many would be shown on the screen. You can zoom in to edit them."
Expand Down
6 changes: 6 additions & 0 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@
"description": "Map Data",
"key": "F",
"data_layers": "Data Layers",
"layers": {
"osm": {
"tooltip": "Map data from OpenStreetMap",
"title": "OpenStreetMap data"
}
},
"fill_area": "Fill Areas",
"map_features": "Map Features",
"autohidden": "These features have been automatically hidden because too many would be shown on the screen. You can zoom in to edit them."
Expand Down
5 changes: 4 additions & 1 deletion modules/renderer/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function rendererMap(context) {
isRedrawScheduled = false;
window.cancelIdleCallback(pendingRedrawCall);
}

function map(selection) {

_selection = selection;
Expand Down Expand Up @@ -756,6 +756,9 @@ export function rendererMap(context) {


map.editable = function() {
var osmLayer = surface.selectAll('.data-layer-osm');
if (!osmLayer.empty() && osmLayer.classed('disabled')) return false;

return map.zoom() >= context.minEditableZoom();
};

Expand Down
61 changes: 56 additions & 5 deletions modules/svg/osm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,61 @@
export function svgOsm() {
return function drawOsm(selection) {
var layers = selection.selectAll('.layer-osm')
.data(['areas', 'lines', 'hit', 'halo', 'label']);
export function svgOsm(projection, context, dispatch) {
var enabled = true;

layers.enter()

function drawOsm(selection) {
selection.selectAll('.layer-osm')
.data(['areas', 'lines', 'hit', 'halo', 'label'])
.enter()
.append('g')
.attr('class', function(d) { return 'layer-osm layer-' + d; });
}


function showLayer() {
var layer = context.surface().selectAll('.data-layer-osm');
layer.interrupt();

layer
.classed('disabled', false)
.style('opacity', 0)
.transition()
.duration(250)
.style('opacity', 1)
.on('end interrupt', function () {
dispatch.call('change');
});
}


function hideLayer() {
var layer = context.surface().selectAll('.data-layer-osm');
layer.interrupt();

layer
.transition()
.duration(250)
.style('opacity', 0)
.on('end interrupt', function () {
layer.classed('disabled', true);
dispatch.call('change');
});
}


drawOsm.enabled = function(_) {
if (!arguments.length) return enabled;
enabled = _;

if (enabled) {
showLayer();
} else {
hideLayer();
}

dispatch.call('change');
return this;
};


return drawOsm;
}
111 changes: 81 additions & 30 deletions modules/ui/map_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ export function uiMapData(context) {
}


function clickGpx() {
toggleLayer('gpx');
}


function clickMapillaryImages() {
toggleLayer('mapillary-images');
if (!showsLayer('mapillary-images')) {
Expand Down Expand Up @@ -191,27 +186,77 @@ export function uiMapData(context) {
}


function drawOsmItem(selection) {
var osm = layers.layer('osm'),
showsOsm = osm.enabled();

var ul = selection
.selectAll('.layer-list-osm')
.data(osm ? [0] : []);

// Exit
ul.exit()
.remove();

// Enter
var ulEnter = ul.enter()
.append('ul')
.attr('class', 'layer-list layer-list-osm');

var liEnter = ulEnter
.append('li')
.attr('class', 'list-item-osm');

var labelEnter = liEnter
.append('label')
.call(tooltip()
.title(t('map_data.layers.osm.tooltip'))
.placement('top')
);

labelEnter
.append('input')
.attr('type', 'checkbox')
.on('change', function() { toggleLayer('osm'); });

labelEnter
.append('span')
.text(t('map_data.layers.osm.title'));

// Update
ul = ul
.merge(ulEnter);

ul.selectAll('.list-item-osm')
.classed('active', showsOsm)
.selectAll('input')
.property('checked', showsOsm);
}


function drawGpxItem(selection) {
var gpx = layers.layer('gpx'),
hasGpx = gpx && gpx.hasGpx(),
showsGpx = hasGpx && gpx.enabled();

var gpxLayerItem = selection
var ul = selection
.selectAll('.layer-list-gpx')
.data(gpx ? [0] : []);

// Exit
gpxLayerItem.exit()
ul.exit()
.remove();

// Enter
var enter = gpxLayerItem.enter()
var ulEnter = ul.enter()
.append('ul')
.attr('class', 'layer-list layer-list-gpx')
.attr('class', 'layer-list layer-list-gpx');

var liEnter = ulEnter
.append('li')
.classed('list-item-gpx', true);
.attr('class', 'list-item-gpx');

enter
liEnter
.append('button')
.attr('class', 'list-item-gpx-extent')
.call(tooltip()
Expand All @@ -224,12 +269,13 @@ export function uiMapData(context) {
})
.call(svgIcon('#icon-search'));

enter
liEnter
.append('button')
.attr('class', 'list-item-gpx-browse')
.call(tooltip()
.title(t('gpx.browse'))
.placement((textDirection === 'rtl') ? 'right' : 'left'))
.placement((textDirection === 'rtl') ? 'right' : 'left')
)
.on('click', function() {
d3.select(document.createElement('input'))
.attr('type', 'file')
Expand All @@ -240,33 +286,33 @@ export function uiMapData(context) {
})
.call(svgIcon('#icon-geolocate'));

var labelGpx = enter
var labelEnter = liEnter
.append('label')
.call(tooltip().title(t('gpx.drag_drop')).placement('top'));
.call(tooltip()
.title(t('gpx.drag_drop'))
.placement('top')
);

labelGpx
labelEnter
.append('input')
.attr('type', 'checkbox')
.on('change', clickGpx);
.on('change', function() { toggleLayer('gpx'); });

labelGpx
labelEnter
.append('span')
.text(t('gpx.local_layer'));


// Update
gpxLayerItem = gpxLayerItem
.merge(enter);
ul = ul
.merge(ulEnter);

gpxLayerItem
ul.selectAll('.list-item-gpx')
.classed('active', showsGpx)
.selectAll('label')
.classed('deemphasize', !hasGpx)
.selectAll('input')
.property('disabled', !hasGpx)
.property('checked', showsGpx);

gpxLayerItem
.selectAll('label')
.classed('deemphasize', !hasGpx);
}


Expand Down Expand Up @@ -324,11 +370,16 @@ export function uiMapData(context) {


function update() {
dataLayerContainer.call(drawMapillaryItems);
dataLayerContainer.call(drawGpxItem);
dataLayerContainer
.call(drawOsmItem)
.call(drawMapillaryItems)
.call(drawGpxItem);

fillList
.call(drawList, fills, 'radio', 'area_fill', setFill, showsFill);

fillList.call(drawList, fills, 'radio', 'area_fill', setFill, showsFill);
featureList.call(drawList, features, 'checkbox', 'feature', clickFeature, showsFeature);
featureList
.call(drawList, features, 'checkbox', 'feature', clickFeature, showsFeature);
}


Expand Down

0 comments on commit 5a8709b

Please sign in to comment.