D
D
danilr2019-04-18 13:22:37
JavaScript
danilr, 2019-04-18 13:22:37

How to pause between adding markers to a 2GIS map?

I want to make a delay between adding markers to a 2gis map in 200ms, tell me how to do this?
Here is the method that creates these markers:

setMarkers(rcs){

      rcs.forEach(residential => {
          let myDivIcon = DG.divIcon({
            iconSize: [30, 30],
            className: "marker-custom",
            html: this.setMiniMarker(residential)
          });

          this.popupMap = DG.popup({
            className: "test-name",
            closeButton: false,
            offset: DG.point(0, 1),
            setZoomMarker: false
          }).setContent(this.setPopupMarker(residential));

          this.coordinates = [residential.latitude, residential.longitude];
          DG.marker(this.coordinates, { icon: myDivIcon })
            .addTo(this.markers)
            .bindPopup(this.popupMap);
        });

        this.markers.addTo(this.map);

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

        this.markers.on("click", event => {
          //при наведении.mouseover, click на маркер
          if (event.originalEvent.target.closest("[data-id]")) {
            let residentialId = Number(
              event.originalEvent.target.closest("[data-id]").dataset.id
            );
            this.setResidentialId(residentialId);

            // добавление класса с задержкой для ожидания создания данных
            if (this.countFunctionMarker === 0) {
              setTimeout(() => (this.isOpenRc = true), 200);
            } else {
              this.isOpenRc = true;
            }
            this.countFunctionMarker++;

          }     
        });
    },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-04-18
@danilr

rcs.forEach((residential, i) => {

  ...

  setTimeout(() => {
    DG.marker([ residential.latitude, residential.longitude ], { icon: myDivIcon })
      .addTo(this.markers)
      .bindPopup(this.popupMap);
  }, i * 200);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question