D
D
danilr2019-04-25 07:02:33
JavaScript
danilr, 2019-04-25 07:02:33

Why does popup 2gis open an error?

I call the method for creating a marker and a popup on the map and immediately want to open the popup, but an error occurs, it's not clear why. Without the popup opening line - everything works and it opens when clicked as expected, but I need to open it programmatically without directly clicking on the marker.

setMarker(){
      let myDivIcon = DG.divIcon({
          iconSize: [30, 30],
          className: "marker-custom",
          html: this.setMiniMarker()
      });
      this.popupMap = DG.popup({
          className: "test-name",
          closeButton: false,
          offset: DG.point(0, 1),
          setZoomMarker: false
      }).setContent(this.setPopupMarker())

        this.marker = DG.marker(this.coordinates, { icon: myDivIcon })
            .addTo(this.map)
            .bindPopup(this.popupMap);
            console.log('marker',this.marker);
        this.onZoomEnd()
        
        this.map.setView(this.coordinates)
        this.map.openPopup(this.popupMap) // вот эта строчка вызывающая ошибку
    }

5cc136baf150a050763858.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-04-25
@danilr

Because the marker must first be added to the map - the popup itself has no coordinates, because it is tied to the marker. Either assign coordinates directly to popup.
See how it is done in your example.
https://api.2gis.ru/doc/maps/ru/examples/popups/#%...
Find the error and fix it.
The popup should be opened from the marker object, and not try to push it onto the map separately.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question