Trigger click event on marker programmatically - ArcGIS

621 Views Asked by At

I am showing some markers using latitude and longitude, but there is a navigation drawer view, where I can click on the location.

So if I click on any particular location from the drawer, how can I trigger the click event on the associated marker?

Is there any way I can trigger the location item click from drawer to trigger marker click?

 let marker = new Graphic({
  geometry: {
    longitude: item.longitude,
    latitude: item.latitude,
    type: 'point',
    spatialReference: { wkid: 3857 },
  },
  symbol: this._Constants.MARKER_FLAT,

  popupTemplate: {
    title: item.name,
    content: function () {
      var div = document.createElement('div');
      div.innerHTML = `<p>Testing</p>`;
      return div;
    },
  },
});

marker.setAttribute('id', String(item.id));
marker.setAttribute('name', String(item.name));

this.mapView.graphics.add(marker);
this.marker = marker;

This Is how I plot the markers

I have tried this approach, but the emit event is returning false.

 if (
  // this.mapView.emit('click', {  // tried this as well
  this.mapView.map.emit('click', {
    mapPoint: this.marker,
  })
 ) {
  console.log('Triggered');
 } else {
  console.log('NOT Triggered');
 }
1

There are 1 best solutions below

0
On

If the purpose of your "trigger a click event" is specifically to make the popup display for your "this.marker", then you can use view.popup.open to trigger/open the popup.

The view.popup.open can take several inputs, including a location to look for features or to display a popup without a specific feature. There are several code snippets at https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#open

Based on your code:

view.popup.open({
  location: this.marker.geometry, // location of the click on the view
  fetchFeatures: true // display the content for the selected feature if a popupTemplate is defined.
});

See also https://gis.stackexchange.com/questions/433141/trigger-click-event-on-existing-map-marker/433501 :)