How do i Add and Remove polygons on a Google Map (version 3)?
-
I'm trying to show and remove polygons onto a google map - using v3 of the API. In my javascript, i've already got an MVCArray of some custom Lat-Longs. What I'm stuck trying to figure out is how to add these polys and then (based upon some other javascript event / user experience feedback .. like clicking on a poly (that has been rendered) ... that poly will be removed. Can someone help? Code or links to examples? I'm struggling to find some examples .. most of them usually goto some v2 code.. cheers :)
-
Answer:
In the API docs, there are a couple of simple examples of http://code.google.com/apis/maps/documentation/javascript/overlays.html#Polygons. Here's the initialize() function from the simple http://code.google.com/apis/maps/documentation/javascript/examples/polygon-simple.html example with the addition of adding an event listener to remove the polygon when clicked. function initialize() { var myLatLng = new google.maps.LatLng(24.886436490787712, -70.2685546875); var myOptions = { zoom: 5, center: myLatLng, mapTypeId: google.maps.MapTypeId.TERRAIN }; var bermudaTriangle; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 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 }); bermudaTriangle.setMap(map); // add an event listener google.maps.event.addListener(bermudaTriangle, 'click', function() { this.setMap(null); }); }
Pure.Krome at Stack Overflow Visit the source
Related Q & A:
- How do I use Microsoft Word to open a Google Drive cloud document?Best solution by Quora
- How to Display Big Data On A Google Map?Best solution by gis.stackexchange.com
- How do I add to an array from a static method?Best solution by stackoverflow.com
- How do I add Google Analytics to my Yahoo Group and Yahoo 360 Blog?Best solution by Yahoo! Answers
- How can I add a website to google search engine?Best solution by safehouseweb.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.