A
A
Alexander Loginov-Solonitsyn2016-08-11 14:45:59
JavaScript
Alexander Loginov-Solonitsyn, 2016-08-11 14:45:59

How to add custom controls to a map in leaflet.js?

Good afternoon everyone. The essence of the question -
how can you add your controls to the map and make them clickable?
It follows from the documentation that any controls are recommended to be added via L.control.
ok, I'm writing

// Кнопка центра
let center = L.control({
  position: 'topright'
});
center.onAdd = function(map) {
  let center = L.DomUtil.create('div', 'map-control-button center-button');
  return center;
};
center.addTo(map);

, and now how to hang a callback on this, for example, on click? Because I didn't find how to do it.
ps. Of course, you can make this button separately, then put a click on it, at which it will be executed
map.setView([51.505, -0.09]);
, but it seems to me that this is not the best solution. At least this solution can be used when the map control is outside the map. And here is something else.
Thanks for the help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question