好的,這裏是我的解決方案。希望它能幫助別人!
它適用於jQuery,谷歌地圖V3。
這是HTML:
<body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="js/GM_LoadMap.js"></script>
Your map:<br/>
<div id="map" style="width: 600px; height: 400px"></div>
</body>
JS/GM_LoadMap.js:
var infoWindow;
$("body").ready(function() {load()});
$("body").unload(function() {GUnload();});
/************************************************************************************
* Métode d'inici
************************************************************************************/
function load() {
var domMap = $("#map")[0];
var myLatLng = new google.maps.LatLng(0,0);
var myOptions = {
zoom: 5,
center: myLatLng,
mapTypeControlOptions: {
mapTypeIds: ['TControl']
}
};
var map = new google.maps.Map(domMap, myOptions);
createBlankCanvas(map, 600, 400);
addPolyForm(map);
}
要創建空白圖像背景:
function createBlankCanvas(map, width, height) {
var minZoomLevel = 0;
var maxZoomLevel = 18;
// Crea un fons en blanc
var ubicaciones = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
return "";
},
tileSize: new google.maps.Size(width, height),
maxZoom:maxZoomLevel,
minZoom:minZoomLevel,
isPng: true,
name: 'Ubicaciones',
opacity: 0.5
});
map.mapTypes.set('TControl', ubicaciones);
map.setMapTypeId('TControl');
map.setZoom(5);
}
要顯示多晶硅形式:
function addPolyForm(map) {
var bermudaTriangle;
var triangleCoords = [
new google.maps.LatLng(0,0),
new google.maps.LatLng(0, 1),
new google.maps.LatLng(1, 0.5)
];
bermudaTriangle = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: "#FF0000",
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
// Add a listener for the click event
google.maps.event.addListener(bermudaTriangle, 'click', showArrays);
infowindow = new google.maps.InfoWindow();
}
要顯示的信息窗口:
function showArrays(event) {
// Since this Polygon only has one path, we can call getPath()
// to return the MVCArray of LatLngs
var vertices = this.getPath();
var contentString = "<b>Triangle de les Bermudes:</b><br />";
contentString += "Posici&ocaute seleccionada: <br />" + event.latLng.lat() + "," + event.latLng.lng() + "<br />";
// Iterate over the vertices.
for (var i=0; i < vertices.length; i++) {
var xy = vertices.getAt(i);
contentString += "<br />" + "Coordenada: " + i + "<br />" + xy.lat() +"," + xy.lng();
}
// Replace our Info Window's content and position
infowindow.setContent(contentString);
infowindow.setPosition(event.latLng);
infowindow.open(map);
}
這是偉大的!謝謝,現在我正在學習http://code.google.com/intl/ca/apis/maps/documentation/javascript/overlays.html。 現在,我怎麼擦除背景?發生在我身上的一件事是製作一個白色覆蓋層......但這意味着加載地圖並加載覆蓋層......任何簡單的方法? 再次感謝您的幫助 – Miquel