Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API with polygon

(excuse me for my bad english) the tops of my polygon are stored into my database (latitude, longitude). so I recovered the latitude and longitude in a table and then I draw my polygon. my problem is that with 3 tops it works fine, but when it is more then 3 it gives this result:

Map

this is my code :

success: function(data) {
                             //   alert(data); 
                    var tableauPointsPolygone = new Array ();                          
                    var j=0;
                    var somme=0;
                    $.each(data, function(i, item) {
                                tableauPointsPolygone.push(new google.maps.LatLng(item.latitude, item.longitude));
                                somme+= parseInt(item.valeur);
                                j++;
                                addMarker(item.latitude,item.longitude,item.adr);
                                center = bounds.getCenter();
                                map.fitBounds(bounds);
                    // alert(item.latitude);
});
var monPolygone = new google.maps.Polygon();
monPolygone.setPaths( tableauPointsPolygone );
monPolygone.setMap( map );
if (somme/j<5)
monPolygone.setOptions({strokeWeight: 3,strokeColor: '#582900' ,fillColor: '#1FA055'});
else
monPolygone.setOptions({strokeWeight: 3,strokeColor: '#582900' ,fillColor: '#A91101'});
                                },
like image 873
Nadk Avatar asked Mar 27 '14 22:03

Nadk


People also ask

What is polygon mapping?

Polygon mapping is the cartographic display of regularly or irregularly shaped polygons and their attributes. Typically, this capability includes shading, symbology and numeric labeling, as well as other map cosmetic functions for generating alphanumeric labeling of polygons.


1 Answers

The problem I see is the arrangement of polygon vertices. In case if 3 the order of point is not essential its triangle but in case of 4 and more you have to sort the points and then push into array.

Here is a helpful question about convex (non-concave) polygon

like image 200
natchkebiailia Avatar answered Sep 24 '22 19:09

natchkebiailia