我正在研究我的这个项目,需要通过点击来定义lat/lng元素,并最终找到一种方法,但刚刚发现,已经预定义的元素会干扰下面的源定义的新叠加元素.所以我查看,搜索,搜索,谷歌搜索,但无法找到任何有用的信息:有没有办法使谷歌地图叠加不可点击?
我正在使用自定义函数来获取点击事件的纬度和经度,并放置预定义的圆形叠加对象.但是,如果我已经预定义了叠加元素,我就无法点击它们来设置新的叠加元素.即我需要使它们不可交互或不可点击,或者只是将它们设置在不同的层上,这样它们就不会干扰新元素的点击事件.
这是我使用的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>
Run Code Online (Sandbox Code Playgroud)
所以我希望它足够清楚我想要的东西.如果你想我可以将它上传到我的主机,使其更直观,更容易看到我的意思.
祝大家圣诞快乐!
干杯!
在CircleOptions中设置{clickable:false}.
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
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1237 次 |
| 最近记录: |