D
D
danilr2019-12-23 19:45:37
JavaScript
danilr, 2019-12-23 19:45:37

How to add double click handler to 2gis popup?

mounted(){
    DG.then(() => {
      this.map = DG.map('map-developer', {
        center: [55.00545, 82.96038],
        zoom: 14,
        zoomControl: false,
        minZoom: 11,
        fullscreenControl: false,
        scrollWheelZoom: false
      });
    this.markers = DG.featureGroup();

    for (var i = 0; i < this.residentials.length; i++) {
      const myDivIcon = DG.divIcon({
        className: "marker-custom",
        html: `<div class="marker-wrapper marker-active" data-id="${this.residentials[i].id}">
                <div class="marker-content">
                  <div class="marker-title">${this.residentials[i].name}</div>
                  <div class="marker-address">${this.residentials[i].address}</div>
                  <div class="marker-decor"></div>
                </div>
              </div>`
      });
      const popupContent = `<div class="marker-wrapper popup-marker" data-id="${this.residentials[i].id}">
                              <div class="marker-content">
                                <div class="marker-title">${this.residentials[i].name}</div>
                                <div class="marker-address">${this.residentials[i].address}</div>
                                <div class="marker-decor"></div>
                              </div>
                            </div>`

      const popupMap = DG.popup({ // для стилизации попапа нужно перебивать стоковые стили 2гис!
        className: "test-name", // пустой класс для удаления стокового класса со стилями 2гис
        closeButton: false,
        offset: DG.point(0 ,10) // отступ ножки, в Px, находится подбором
      }).setContent(popupContent).on('dblclick', (e) => { console.log('qqqqqqqqqqqqqq');});

      DG.marker([this.residentials[i].latitude, this.residentials[i].longitude], { icon: myDivIcon })
      .addTo(this.markers)
      .bindPopup(popupMap).on('click', (event) => {
        console.log('click: ');
        if (event.originalEvent.target.closest("[data-id]")) {
            const residentialId = Number(   
              event.originalEvent.target.closest("[data-id]").dataset.id
            );
            const route = this.residentials.find(rc => rc.id === residentialId).route;
            this.$emit('click-marker', route);
          }
        // this.map.setView([event.latlng.lat, event.latlng.lng]);
      }).on('dblclick', (event => {
        console.log('dblclick: ', dblclick);

      }))

    }

    DG.control.zoom({position: 'topright'}).addTo(this.map);

    this.markers.addTo(this.map);
    this.map.fitBounds(this.markers.getBounds());
    });
  }

Here I tried to hang a double click handler on the popup, but it does not work. If you just do 'click', then everything works:
.setContent(popupContent).on('dblclick', (e) => { console.log('qqqqqqqqqqqqqq');});

How do you do a double click anyway?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
n1ksON, 2019-12-23
@danilr

Roughly speaking it should look like this:

$('.setContent').click(function() {
    $('.setContent').click(function() {
        console.log('123');
    });
});

jQuery should have a working version. On pure JS, I think you can handle it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question