Geographic Information Systems Asked by user169554 on December 12, 2020
I’m building a map that uses a conditional statement to determine what data to load based on the zoom level. However, the conditional statement is only fired when the map first loads, as opposed to every time the zoom level changes. Is there a way to change the code to run on zoom load (i.e. to update every time the user zooms in or out) rather than the initial page load?
All map libraries have events which help you to find out when map zoomed, clicked and panned. For example, if you're using Leaflet.js
, map object has following listener for zoom:
var initCenter = [42.444508, -76.499491];
var initZoom = 4;
var map = L.map('map').setView(initCenter, initZoom);
map.on('zoomend', function() {
currentZoomLevel = map.getZoom();
// Do your job
});
On the other hand, you can find map events for CARTO
here.
map.on('move', {
currentZoomLevel = map.getZoom();
// Do your job
});
Answered by Arash Madadi on December 12, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP