>From your description of what you want to do, it doesn't sound like what you want to do is create a new map every time someone clicks your polygon. That would not only be unintuitive but you'd have load time concerns and you wouldn't be able to carry much over from map to map. What I'd do if I understand you correctly is create an array with all of your polygons in it, then create one map. Apply/draw the first polygon during your Initialize function and set a global index variable to "0". Then in your polygon click event function, un-draw (set map: to null) your current polygon, increment your index variable, then draw your next polygon. This will be much faster for the user and the code. -- That is of course, if I understood what you wanted to do initially properly.
On Mar 22, 11:46 am, Erwin Dicker <[email protected]> wrote: > but one thing.... > > var map; > > google.maps.event.addDomListener(bermudaORANJE, 'click', function() { > > bermudaYELLO1.setMap(null); > bermudaORANJE.setMap(null); > bermudaGREEN.setMap(map); > map.setCenter(bermudaGREENcenter) > map.setZoom(6); > > }); > > //constructor > function initialize() { > > map = new > google.maps.Map(document.getElementById("map_canvas"), > myOptions); > > bermudaRED.setMap(map); > } > > in the click event i call function() the map, it make new one again... > > if i remove new i don't see anything.. > global variable.. triad: > (1)var map; > (2)var window.map; > (3) var map= new > google.maps.Map(document.getElementById("map_canvas"), > myOptions); > > nothing works.. > > gr. > > On 22 mrt, 08:20, kashey <[email protected]> wrote: > > > > > first> function initialize() { > > > var map = new > > > here you define LOCAL variable for function "initialize" > > use "var window.map" or just remove "var" from here and define var map > > somethere in the top of script > > > and then toy create NEW MAP( again - NEW MAP ) in click event. > > remove that lines where. > > > On 22 ÍÁÒ, 02:02, Erwin Dicker <[email protected]> wrote: > > > > well i'm doing something wrong.. > > > > i traid to make this a global variable: var map = new > > > google.maps.Map(document.getElementById("map_canvas"), > > > > if i don't put that line in the > > > google.maps.event.addDomListener(bermudaTriangle, 'click', function() > > > { > > > i get a error... > > > > what happend when i click on the polygoon it make's a new map... > > > what i wanna do is... click polygoon it goes away and you get the > > > other polygoon... > > > the final version is.. when you zoom in the redpolygoon goes away and > > > you get the yello polygoon > > > > <script type="text/javascript"> > > > š š var myLatLng = new google.maps.LatLng(24.886436490787712, > > > -70.2685546875); > > > š š var myOptions = { > > > š š š zoom: 5, > > > š š š center: myLatLng, > > > š š š mapTypeId: google.maps.MapTypeId.ROADMAP > > > š š }; > > > > š š var map; > > > š š var bermudaTriangle; > > > > š š var bb2 = new google.maps.LatLng(22.886436490787712, > > > -68.2685546875); > > > > š š var triangleCoords = [ > > > š š š š new google.maps.LatLng(25.774252, -80.190262), > > > š š š š new google.maps.LatLng(18.466465, -66.118292), > > > š š š š new google.maps.LatLng(32.321384, -64.75737), > > > š š š š new google.maps.LatLng(25.774252, -80.190262) > > > š š ]; > > > > š š // Construct the polygon > > > š š bermudaTriangle = new google.maps.Polygon({ > > > š š š paths: triangleCoords, > > > š š š strokeColor: "#FF0000", > > > š š š strokeOpacity: 0.8, > > > š š š strokeWeight: 2, > > > š š š fillColor: "#FF0000", > > > š š š fillOpacity: 0.35 > > > š š }); > > > > google.maps.event.addDomListener(bermudaTriangle, 'click', function() > > > { > > > > // if i don't do this i get a error :S i have to make a new map :s... > > > some how it won't get the info out of var > > > // > > > š š var map = new > > > google.maps.Map(document.getElementById("map_canvas"), > > > š š š š myOptions); > > > > š š var triangleCoords = [ > > > š š š š new google.maps.LatLng(22.774252, -78.190262), > > > š š š š new google.maps.LatLng(16.466465, -64.118292), > > > š š š š new google.maps.LatLng(30.321384, -62.75737), > > > š š š š new google.maps.LatLng(22.774252, -78.190262) > > > š š ]; > > > > š š // Construct the polygon > > > š š bermudaTriangle = new google.maps.Polygon({ > > > š š š paths: triangleCoords, > > > š š š strokeColor: "#FFFF00", > > > š š š strokeOpacity: 0.8, > > > š š š strokeWeight: 2, > > > š š š fillColor: "#FFFF00", > > > š š š fillOpacity: 0.35 > > > š š }); > > > > //here i get the error when i don't put google.maps.map in it > > > š šbermudaTriangle.setMap(map); > > > š map.setCenter(bb2) > > > > }); > > > > š function initialize() { > > > > š š var map = new > > > google.maps.Map(document.getElementById("map_canvas"), > > > š š š š myOptions); > > > > š šbermudaTriangle.setMap(map); > > > š } > > > > </script> -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" 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-js-api-v3?hl=en.
