6

(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'});
                                },
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Nadk
  • 173
  • 2
  • 3
  • 9
  • I'm not sure what your definition of *tops* is and I don't see a problem with the polygon (because I don't see a question). – Erik Philips Mar 27 '14 at 23:09
  • thanks for your reply,i mean with tops corner or vertices. The problem is that it's not a polygon, it doesn't cover the whole surface. – Nadk Mar 27 '14 at 23:24
  • 1
    Where does your data come from? What is the data for the polygon in question? Seems to me the vertices just need to be reordered. – geocodezip Mar 27 '14 at 23:35
  • i have a table on my database named "capteur" where i stock all the point. but i have no idea how to reorder it lol – Nadk Mar 27 '14 at 23:51
  • i added to my requet "order by longitude" and that work fine. thanks for your add – Nadk Mar 28 '14 at 08:08
  • @geocodezip you might post your comment as an answer. – GameAlchemist Apr 14 '14 at 15:25

1 Answers1

1

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

Community
  • 1
  • 1
natchkebiailia
  • 611
  • 4
  • 18