> function init() {
> ...
> var map = new ...
>
> 'map' is local in scope to the function. After the function has
> completed, 'map' is no longer accessible. Events run onclick are run
> long after the function has
> completed.http://groups.google.com/group/google-maps-api/search?group=google-ma...
But it works fine without the custom map. Why?
function init() {
...
var map = new GMap2(document.getElementById("map"));
var customTileLayers = [new GTileLayer(...)];
customTileLayers[0].getTileUrl = customGetTileUrl;
var customMap = new GMapType(customTileLayers, new
GMercatorProjection(12)...);
//---------------------- test w/o customMap
-------------------------
// map.addMapType(customMap);
// map.setCenter(new GLatLng(0, 0), 3, customMap);
map.setCenter(new GLatLng(0, 0), 3);
//-------------------------------------------------------------------------------
// I will skip explanation up to this point. It is just a routine
for custom map.
GEvent.addListener(map, "click", function(overlay, latlng) {
var lat = latlng.lat();
var lon = latlng.lng();
var latOffset = 10;
var lonOffset = 10;
var polygon = new GPolygon([
new GLatLng(lat, lon - lonOffset),
new GLatLng(lat + latOffset, lon),
new GLatLng(lat, lon + lonOffset),
new GLatLng(lat - latOffset, lon),
new GLatLng(lat, lon - lonOffset)], "#f33f00", 5);
map.addOverlay(polygon);
});
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.