Leaflet/Leaflet — pull request #2977 by yohanboniface (2014-10-26 20:13:07+00:00)
Title: Fix array of array of LatLngs toGeoJSON edge case

In master branch, MultiPolygon and Polygon are both managed by the Polygon class, and in the process of exporting to GeoJSON we now have a "guess" step, to know if we need to export to a Polygon or a MultiPolygon.

Here is in summary the [GeoJSON specs](http://geojson.org/geojson-spec.html#polygon):
- a Polygon is an *array of LinearRing coordinate arrays*, so something like `[[…], […]]`; the first of those arrays being the exterior ring of the Polygon, and the optional others being the holes
- a MultiPolygon is an *array of Polygon coordinate arrays*, which is an array of one or more Polygon as just defined, so something like `[[[…], […]], [[…], […]]]`

So, sadly, we don't have an exact one to one match between GeoJSON specs and Leaflet internal. There is an edge case: Leaflet allows to create a simple polygon with an array of LatLngs, while this would be, strictly speaking, an invalid GeoJSON coordinates value; instead, the minimal form of a Polygon according to GeoJSON specs would be *an array with an array of LatLngs*.

Corollary, this very simple GeoJSON Polygon (i.e. not multi, no hole, but strict GeoJSON structure, with an array of arrays of LatLngs) was wrongly output as a MultiPolygon. This PR fixes that.

Before:
```javascript
> JSON.stringify(L.polygon([[[1,2], [2,2], [2,1]]]).toGeoJSON())
'{"type":"Feature","properties":{},"geometry":{"type":"MultiPolygon","coordinates":[[[[2,1],[2,2],[1,2],[2,1]]]]}}'
```
After:
```javascript
> JSON.stringify(L.polygon([[[1,2], [2,2], [2,1]]]).toGeoJSON())
'{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[2,1],[2,2],[1,2],[2,1]]]}}'
```

I've also added more test cases, to be sure I'm not breaking other edge cases.

Thanks for reviewing :)