Skip to content

Instantly share code, notes, and snippets.

@demiurg
Last active March 30, 2018 16:03
Show Gist options
  • Save demiurg/e3ddc7fe95323b33cff24b868c7386f0 to your computer and use it in GitHub Desktop.
Save demiurg/e3ddc7fe95323b33cff24b868c7386f0 to your computer and use it in GitHub Desktop.
function handleMousemove(vmap){
var self = this;
self.event = null;
self.highlight = function(e){
console.log(self.event);
if (self.event != e){
return;
}
var features = vmap.queryRenderedFeatures(e.point, {
layers: ['regions']
});
// Change the cursor style as a UI indicator.
vmap.getCanvas().style.cursor = features.length ? 'pointer' : '';
// Remove things if no feature was found.
if (!features.length) {
return;
}
var feature = features[0];
vmap.setFilter(
'regions-highlight',
['==', 'id', feature.properties.id]
);
}
self.handler = function(e){
self.event = e;
setTimeout(function(){
self.highlight(e);
}, 1000);
}
return self.handler;
}
map.on('mousemove', handleMousemove(map));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment