[英]Google Maps API Map Click Event doesn't work when clicked on an overlay geojson layer
I've implemented a click event on the map using 我已使用以下方法在地图上实现了click事件
google.maps.event.addListener(map, 'click', mapclick);
and everything is working fine. 而且一切正常。
I've also added a geojson layer on map. 我还在地图上添加了geojson图层。 So, the problem is when I click on the overlay geojson layer (which is a polygon layer actually), the map click event not fired.
因此,问题是当我单击覆盖的geojson图层(实际上是多边形图层)时,未触发地图单击事件。 Hence, my question is what should I do so that map click event also work when I click on an overlay layer on map?
因此,我的问题是,当我单击地图上的叠加层时,如何使地图单击事件也起作用?
It's not clear what you mean by "geojson layer" , but when you mean a Data-layer there are 2 options: 不清楚“ geojson层”是什么意思,但是当您表示数据层时 ,有2种选择:
when you don't need the click-event to be triggered for the feature(eg polygon) 当您不需要为要素(例如多边形)触发点击事件时
set the clickable-option of the layer to false: 将图层的clickable-option设置为false:
map.data.setStyle({clickable:false});
when the click-event should be triggered for both, map and feature 地图和地图项均应触发点击事件的时间
trigger the event for the map programmatically: 以编程方式触发地图事件:
map.data.addListener('click',function(e){ google.maps.event.trigger(this.getMap(),'click',e); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.