我想在用戶雙擊圖像的某個部分時顯示突出顯示的圓圈。例如,如果圖像是城市的地圖,並且他們雙擊座標:(X,Y),我希望突出顯示的圓的中心位於(X,Y),並且半徑會根據它們點擊。如何在雙擊時創建圖像的突出顯示?
這是我到目前爲止有:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function showMap(){
var mapOptions = {
zoom: 19,
center: new google.maps.LatLng(x, y),//let z, y be some coord
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDoubleClickZoom: true,
disableDefaultUI: true,
zoomControl: false,
draggable: false,
scrollwheel: false
}
map = new google.maps.Map(document.getElementById("myMap"),
mapOptions);
google.maps.event.addListener(map, 'dblclick', doubleClicked);
}
function doubleClicked(e){//highlight the area with a circle
//alert("lat: " + e.latLng.lat() + "\nlong: " + e.latLng.lng());
}
</script>
HTML
<div id="myMap" ></div>
CSS
#myMap {
margin-left: auto;
margin-right: auto;
width: 1200px;
height: 800px
}
解決方案與@Aamir薩瓦爾幫助:
var circle = new google.maps.Circle({
strokeColor: '#FFFFFF',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map,
center: {lat: X, lng: Y}
radius: 10
});
哪裏是將要點擊的圖像當前的代碼? – Eddie
其地圖或我的地圖 –
所以基本上圓的半徑是點擊和雙擊,對吧? – Eddie