D
D
danilr2019-04-16 10:08:25
JavaScript
danilr, 2019-04-16 10:08:25

How to pass an event (e) and some parameter to the method?

The component has a method, instead of this.residentials, it is necessary to substitute the corresponding values ​​that I must pass there. An event is transmitted (necessary, you can’t remove it) and you need to somehow forward my array, But how to do this?

onZoomEnd(e) {
      const { oldZoom } = this,
        newZoom = this.map.getZoom();

      const template =
        oldZoom > this.switchOnZoom && newZoom <= this.switchOnZoom
          ? this.setMiniMarker
          : oldZoom <= this.switchOnZoom && newZoom > this.switchOnZoom
          ? this.setZoomMarker
          : null;
      if (template) {
        Object.values(this.markers._layers).forEach((marker, i) => {
          marker._icon.innerHTML = template(this.residentials[i]);
        });
      }
    },

mounted() {
    this.markers = DG.featureGroup();
    this.popups = DG.featureGroup();

    this.map = DG.map("map", {
      center: [54.98, 82.89],
      zoom: 13,
      minZoom: 7,
      zoomControl: false,
      fullscreenControl: false
    });
    
      this.dataRequest.then(response => {
        this.setMarkers(this.residentials)
        console.log(this.residentials);
        
        this.map.on("zoomstart", this.onZoomStart);
        this.map.on("zoomend", this.onZoomEnd);
        
      })
      .catch(error => console.log(error));

  },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2019-04-16
@danilr

Moved from comments to answers
-------------------------------------------
Call the method So:
And the modified method code:

onZoomEnd(residentials) {
  const { oldZoom } = this,
    newZoom = this.map.getZoom();

  const template =
    oldZoom > this.switchOnZoom && newZoom <= this.switchOnZoom
      ? this.setMiniMarker
      : oldZoom <= this.switchOnZoom && newZoom > this.switchOnZoom
      ? this.setZoomMarker
      : null;
  if (template) {
    Object.values(this.markers._layers).forEach((marker, i) => {
      marker._icon.innerHTML = template(residentials[i]);
    });
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question