Search the Community
Showing results for tags 'polygon'.
-
Hi all, I am working on a webapplication. I have a google map, where I add polygons from an array. I loop through that array and add the polygons to the map. I also need to add an 'click' event listener to the polygon to make it editable. This is what I am doing: var polygons = data; // array holding json objects. Each object is a polyline for(var i=0; i<polygons.length; i++) { var polygon = polygons[i]; var points = []; for(var j=0; j<polygon[1].points.length; j++) { var item = new google.maps.LatLng(polygon[1].points[j].lat, polygon[1].points[j].lng); points.push(item); } var dbpolygon=new google.maps.Polygon({ path: points, strokeColor: polygon[0].type, strokeOpacity: 0.4, strokeWeight: 2, fillColor: polygon[0].type, fillOpacity: 0.4, editable: false }); dbpolygon.setMap(map); google.maps.event.addListener(dbpolygon, 'click', function() { setSelection(dbpolygon); }); } Problem The polygons are all drawing correctly. However the problem is that when I try to click on a polygon it always selects the last index. it is like it is only clicking on the last polygon added. I think when I add a new listener it overrides the old one. How can I add a listener for each polygon added in order to alert the correct index? Thank you
-
Hi all, Thank you for viewing my post. In my application I allow users to draw shapes on google maps using google maps api v3. I dont know how to store the polygons in MySQL? Im new to google maps api and dont have a clue. Please help. I was thinking should I store each point seperately in a database field or store the whole polygon as json? This is what I have so far. I have created a json object that stores all the verticles in a list. I was thinking of saving this whole json in one database field? This is the code used to contruct the array: var vertices = selectedShape.getPath(); // MVCArray var pointsArray = []; //list of polyline points for (var i =0; i < vertices.getLength(); i++) { var xy = vertices.getAt(i); //LatLang for a polyline var item = { "lat" : xy.lat(), "lng":xy.lng()}; pointsArray.push(item); } var polygon = {"points" : pointsArray}; This is the constructed json result: {"points": [ {"lat": 51.51814351604911, "lng": -0.14479637145996094 }, { "lat": 51.51830374452608, "lng": -0.13861656188964844}, { "lat": 51.516194024429446, "lng": -0.13968944549560547} ]} Should I have the whole thing in one field? Is it better to save each vertices (lat and lng) in a seperate row, so for the above polygon there will be 3 rows? Kind regards, Imran
- 7 replies
-
- google maps api
- polygon
-
(and 2 more)
Tagged with: