nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

index.js (1650B)


      1 import L from 'leaflet';
      2 import './style.css';
      3 
      4 function stopContainerEvents(container) {
      5     L.DomEvent.disableClickPropagation(container);
      6     L.DomEvent.disableScrollPropagation(container);
      7     L.DomEvent.on(container, 'mousemove contextmenu', L.DomEvent.stop);
      8 }
      9 
     10 L.Control.include({
     11     _stopContainerEvents: function() {
     12         stopContainerEvents(this._container);
     13     }
     14 });
     15 
     16 function makeButton(containerClass, title, iconClass, noControlClass) {
     17     let cls = 'leaflet-bar leaflet-control-single-button';
     18     if (!noControlClass) {
     19         cls += ' leafletControl';
     20     }
     21     if (containerClass) {
     22         cls += ' ' + containerClass;
     23     }
     24     const container = L.DomUtil.create('div', cls);
     25     stopContainerEvents(container);
     26     const link = L.DomUtil.create('a', null, container);
     27     link.href = '#';
     28     L.DomEvent.on(link, 'click', L.DomEvent.preventDefault);
     29     if (title) {
     30         link.title = title;
     31     }
     32     const icon = L.DomUtil.create('div', iconClass, link);
     33     return {container, link, icon};
     34 }
     35 
     36 function makeButtonWithBar(containerClass, title, iconClass) {
     37     let cls = 'leaflet-control button-with-bar';
     38     if (containerClass) {
     39         cls += ' ' + containerClass;
     40     }
     41     const container = L.DomUtil.create('div', cls);
     42     const {container: buttonContainer, link, icon} = makeButton(null, title, iconClass, true);
     43     container.appendChild(buttonContainer);
     44 
     45     const barContainer = L.DomUtil.create('div', 'leaflet-bar bar', container);
     46     stopContainerEvents(barContainer);
     47     return {container, buttonContainer, link, icon, barContainer};
     48 }
     49 
     50 export {stopContainerEvents, makeButton, makeButtonWithBar};