我正在尝试将俄勒冈州不同县的叠加层添加到谷歌地图。
我在使用 jquery 提取的 json 文件中拥有一个县的所有 latlng 数据。我遇到的问题是覆盖似乎在那里,但它是透明的。
包括一些图片来说明为什么我很确定覆盖层在那里
这是鼠标不在贝克县时的光标:
这是鼠标在贝克县上时的光标:
所以现在我想知道是什么导致了我的代码中的这种情况。
function initialize() {
var oregon = new google.maps.LatLng(43.804, -120.554);
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 7,
center: oregon,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROAD
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
countryPolygons = null;
$.getJSON("json/counties.json", function(data){
county_data = data;
county_latlng = [];
for (var i = 0; i < county_data.data.length; i++) {
var county = county_data.data[i];
for (var j = 0; j < county.latlng.length; j++) {
var latlng = county.latlng[j];
var first = parseFloat(latlng.split(",")[0]);
var second = parseFloat(latlng.split(",")[1]);
county_latlng.push(new google.maps.LatLng(first, second));
}
}
countyPolygons = new google.maps.Polygon({
paths: county_latlng,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: '#FF0000',
fillOpacity: 0.35
});
countyPolygons.setMap(map);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
counties.json 文件看起来像这样,明显缩短了。
{
"title": "Counties",
"data": [
{
"Name": "Baker",
"latlng": [
"44.65488,-118.42475",
"44.64548,-118.38275",
"44.62488,-118.34425",
"44.56938,-118.31765",
"44.53442,-118.36868",
"44.47498,-118.36365",
"44.45698,-118.39215",
"44.44968,-118.42197",
"44.41998,-118.42445",
"44.39781,-118.43485",
"44.38148,-118.41425",
"44.35345,-118.43539",
"44.28621,-118.49621",
"44.25719,-118.24407",
"44.25608,-118.23214",
"44.25608,-118.23002",
"44.27077,-118.18471",
"44.29948,-118.14044",
"44.31403,-118.12604",
"44.34918,-118.08677",
"44.37726,-118.05169",
"44.40939,-118.03151"
]
}
]
}
我看不到任何会使叠加层透明的东西。
谢谢你的帮助。