Externalising code from Javascript Initialize function does not work?
I am trying to build polygons with Google maps V3 but I got this problem: when I put my piece of code in my initialize function, it works ... but when I externalise it, it does not work.
This is my code:
function AddSecteurs() {
var Secteur ;
var SecteurCoords = [
new google.maps.LatLng(47.216770, -1.553879 ),
new google.maps.LatLng(47.516770, -1.563879 ),
new google.maps.LatLng(47.216770, -1.574579 ),
new google.maps.La开发者_C百科tLng(47.216770, -1.5744179),
new google.maps.LatLng(47.216770, -1.584579 ),
new google.maps.LatLng(47.236770, -1.574579 ),
new google.maps.LatLng(47.229770, -1.574579 )];
Secteur = new google.maps.Polygon({
paths: SecteurCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35,
});
Secteur.setMap(map);
}
It seems you're missing the map
variable in your function.
Just declare it as a parameter:
function AddSecteurs(map) ...
And pass it to the new function from the Initialize
function:
AddSecteur(map);
精彩评论