1

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');
 }
0

1 Answer 1

0
+100

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.
    });
2
  • 1
    Thanks, @Bjorn, I think I was looking at this requirement from a different perspective, click and click events, I should have spent more time on the documentation. Thanks for your help, I definitely helped. Totally appreciate it. Commented Jun 14, 2022 at 6:07
  • 1
    I don't have enough reputation to upvote, but anyways marking answer as accepted and giving you the bounty points Commented Jun 14, 2022 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.