沒關係,這是我有。我使用smarty來填充座標,從mysql中獲取,我的小應用程序在英國地圖上繪製了300多個多邊形,用於縣界。我已經設法做到了這一點,並按照我的意願着色。現在我有一個問題,我不能得到任何信息框顯示。谷歌地圖api v3無法獲取信息框顯示在動態創建的多邊形
多一點信息,counties_zone的原因是,有些地區有島嶼打破了多邊形制造混亂。所以我必須將它們分區以正確地關閉多邊形。
我的smarty變量的其餘部分應該很自我解釋。
<script>
var map;
var infoWindow;
function initialize() {
var mapOptions={
zoom: 6,
center: new google.maps.LatLng(54.049976288319, - 2.8110410026615),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map=new google.maps.Map(document.getElementById('googleMap'),
mapOptions);
var counties={
};
{foreach $counties as $county => $area}
{foreach $area as $zone => $coords}
counties["{$county}_{$zone}"]=new google.maps.Polygon({
paths: [
{foreach $coords as $coord}
new google.maps.LatLng({$coord.0}, {$coord.1}),
{/foreach}
],
strokeColor: "#0000ff",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#{$coord.2}",
fillOpacity: 0.6
});
counties["{$county}_{$zone}"].setMap(map);
infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(counties["{$county}_{$zone}"], 'click', showInfoCounty);
{/foreach}
{/foreach}
}
function showInfoCounty(event) {
var contentString="<b>County</b><br />";
contentString+="County name";
// thhis works.
console.log(contentString);
// this works
this.setOptions({ fillColor: "#000000" });
// this doesnt work.
// Replace our Info Window's content and position
infowindow.setContent(contentString);
infowindow.setPosition(event.latLng);
infowindow.open(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
非常感謝您,我真的不認爲這會非常簡單!我現在只需要定位它,但這就是它的樂趣,我陷入了循環圈! – Chris