Отключить всплывающее окно при использовании инструмента измерения в листовке - PullRequest
0 голосов
/ 31 мая 2018

Я использую плагин измерения в листовке, но когда я пытаюсь измерить между маркерами, всплывающее окно мешает, есть ли способ это исправить?Я прочитал что-то о нечетных кликах, я пытался использовать это безрезультатно.

$(".leaflet-control-measure").click(function() {
  var oddClick = $(this).data("oddClick");
 $(this).data("oddClick", !oddClick);
 if (!oddClick) {
   map.off('click', popup);
 } else {
    map.on('click', popup);
 }
 });

enter image description here

   popup logic- I am reading from a database, the popup is called from python in a for loop, and rendered using the jinja2 template
 var markers= L.markerClusterGroup({
      disableClusteringAtZoom: 15,
      minZoom : 2

  });


  {% for item in markers %}


   var resortIcon = L.icon({
       iconUrl: '{{ item[3] }}',
      iconSize: [25, 25],
      popupAnchor: [0,-15]
    });

   var marker{{ item[0] }} = L.marker({{ item[5:] }}, {icon: resortIcon});
   var popup = "<table height='90'><tr><td>{{ item[1] }}</td></tr><tr><td 
 align='center'><b><i>{{ item[4] }}</b></i></td></tr><tr><td align='center'> 
   <a href='www.google.com' onmouseover='More info'><img src='../icon/contract.svg' height=30 width=30 /></a></td></tr></table>";
  marker{{ item[0] }}.bindPopup(popup);
  markers.addLayer(marker{{ item[0] }});
  map.addLayer(markers)


  {% endfor %}

1 Ответ

0 голосов
/ 01 июня 2018

Если я вас правильно понимаю, вы хотите, чтобы всплывающие окна не появлялись, если вы измеряете.Я ни в коем случае не являюсь экспертом в листовке , так как я никогда не использовал ее раньше, но, просматривая некоторые документы, кажется, что это может быть вашим лучшим вариантом.

По сути, вы можете привязать обработчик событий к событию popupopen на каждом маркере, а внутри этого обработчика вы можете немедленно закрыть всплывающее окно, если выполнены определенные условия (т. Е. Включен «режим измерения»).

Вот как это будет работать:

var startingCoords = [40.07573, -105.401047];
var markerCoords = [
  startingCoords,
  [40.512318, -105.665104],
  [39.825169, -104.994123],
];
var map = L.map('map').setView(startingCoords, 8);
var enablePopups = document.getElementById("enablePopups");
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

function onPopupOpen(e) {
  // check if you it is okay for the popup to open - if not, close it.
  if (!enablePopups.checked) {
    // "this" refers to the marker object of the marker that was clicked on, whereas
    // e.target will refer to the DOM element itself
    this.closePopup();
  }
}

// loop to create each marker
markerCoords.forEach(function (coords) {
  var marker = L.marker(coords).addTo(map).bindPopup('Location at [' + coords + ']');
  // use .bind(marker) so we can access the marker itself via "this" inside the onPopupOpen
  // handler. That way, we don't have to keep an array of markers as a reference - each one
  // is self-referencing.
  marker.on("popupopen", onPopupOpen.bind(marker));
});
#map {
  width: 500px;
  height: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"></script>
Enable Popups ? <input type="checkbox" checked id="enablePopups" />
<p>Click on a marker with "enable popups" checked vs unchecked - you can manually disable the popups based on a condition</p>
<div id="map"> </div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...