Skip to content

Commit

Permalink
Add back layers and force redraw after map style change
Browse files Browse the repository at this point in the history
  • Loading branch information
jisaacks committed Nov 10, 2016
1 parent 724e3f8 commit 4169684
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var Draw = function(options) {
ctx.api = api;

var setup = Setup(ctx);
ctx.setup = setup;

api.addTo = setup.addTo;
api.remove = setup.remove;
api.types = Constants.types;
Expand Down
18 changes: 16 additions & 2 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ module.exports = function(ctx) {
ctx.store.changeZoom();
};

events.data = function(event) {
if (event.dataType === 'style') {
const { setup, api, map, options } = ctx;
const hasLayers = !!options.styles.find(style => map.getLayer(style.id));
if (!hasLayers) {
setup.addLayers();
const featureIds = ctx.api.getSelectedIds();
const mode = ctx.api.getMode();
ctx.api.changeMode(Constants.modes.STATIC);
ctx.api.changeMode(mode, { featureIds });
}
}
};

function changeMode(modename, nextModeOptions, eventOptions = {}) {
currentMode.stop();

Expand Down Expand Up @@ -155,9 +169,9 @@ module.exports = function(ctx) {
},
addEventListeners: function() {
ctx.map.on('mousemove', events.mousemove);

ctx.map.on('mousedown', events.mousedown);
ctx.map.on('mouseup', events.mouseup);
ctx.map.on('data', events.data);

ctx.container.addEventListener('mouseout', events.mouseout);

Expand All @@ -168,9 +182,9 @@ module.exports = function(ctx) {
},
removeEventListeners: function() {
ctx.map.off('mousemove', events.mousemove);

ctx.map.off('mousedown', events.mousedown);
ctx.map.off('mouseup', events.mouseup);
ctx.map.on('data', events.data);

ctx.container.removeEventListener('mouseout', events.mouseout);

Expand Down

0 comments on commit 4169684

Please sign in to comment.