简体   繁体   中英

how to trigger click from external link on google.map.data.feature not on marker

I want to trigger click event from external link on google.map.data.feature.

My code looks something like this

function init(query){

  map = new google.maps.Map(document.getElementsByClassName('map')[0], {
    zoom: 12,
    center: {
      lat: 17.3850,
      lng: 78.4867
    }
  });

map.data.setStyle(feature=>{
    return {url:`image`, scaledSize: new google.maps.Size(32,32)}
})
map.data.addListener('click', clickEventOnMapData);
map.data.loadGeoJson(`some url`);

}

I have clickEventOnMapData written which is opening up a window on click of markers.

Now I have an external button on click of which I want to trigger the same clickEventOnMap for the particular data.feature.

Code for that is

function openWindow(lsqid){
  map.data.forEach((feature)=>{
    if(feature.getProperty('lsqid') === lsqid){

      google.maps.event.trigger(feature, 'click');
    }
  });
}

Now from above I get the feature on which I want to trigger click event. But I am unable to trigger the click event on the particular feature. Additionally any error is also not displayed on console.

I apprantly did it via

function openWindow(lsqid){
  map.data.forEach((feature)=>{
    if(feature.getProperty('lsqid') === lsqid){

      clickEventOnMapData({feature});
    }
  });
}

and it worked :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM