gpt4 book ai didi

google-maps-api-3 - 有没有办法使覆盖对象不可点击?

转载 作者:行者123 更新时间:2023-12-02 12:01:29 27 4
gpt4 key购买 nike

我正在开发我的这个项目,需要通过单击来定义纬度/经度元素,并最终找到了一种方法来做到这一点,但刚刚发现,已经预定义的元素会干扰源定义的新覆盖元素以下。所以我看了又看,搜索,谷歌搜索,但无法找到任何有用的信息:有没有办法使谷歌地图覆盖不可点击?

我正在使用自定义函数来获取单击事件的纬度和经度并放置预定义的圆形覆盖对象。但是,如果我已经预定义了覆盖元素,则无法单击它们顶部来设置新的覆盖元素。 IE。我需要使它们不可交互或不可点击,或者只是将它们设置在不同的层上,这样它们就不会干扰新元素的点击事件。

这是我使用的JS:

<script type="text/javascript">
var map;
var markersArray = []; //the array for the newly defined objects

function initMap()
{
var latlng = new google.maps.LatLng(41, 29);
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

// add a click event handler to the map object
google.maps.event.addListener(map, "click", function(event)
{
// place a marker
placeMarker(event.latLng);

});

// I've predefined a couple of markers just to see how it works with already defined elements and discovered this interference that I mentioned above
var mar1 = new google.maps.LatLng(40.9653, 29.3705);
var marker1 = new google.maps.Circle({
center: mar1,
radius: 2500,
fillColor: "#FF0000",
strokeWeight: 0,
fillOpacity: 0.35,
map: map
});
var mar2 = new google.maps.LatLng(40.9664, 29.3252);
var marker2 = new google.maps.Circle({
center: mar2,
radius: 2500,
fillColor: "#FF0000",
strokeWeight: 0,
fillOpacity: 0.35,
map: map
});
marker1.setMap(map);
marker2.setMap(map);

}

function placeMarker(location) {
// first remove all new markers if there are any, so that we define one new at a time
deleteOverlays();

var new_marker = new google.maps.Circle({
center: location,
radius: 2500,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 0,
fillColor: "#FF0000",
fillOpacity: 0.35,
//position: location,
map: map
});

// add marker in markers array
markersArray.push(new_marker);

}

// Deletes all markers in the array by removing references to them
function deleteOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
}

</script>

fiddle

最佳答案

设置{clickable: false} in the CircleOptions .

    var new_marker = new google.maps.Circle({
center: location,
radius: 2500,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 0,
fillColor: "#FF0000",
fillOpacity: 0.35,
clickable: false, // <=====================
map: map
});

Modified jsfiddle

关于google-maps-api-3 - 有没有办法使覆盖对象不可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14033568/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com