Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print/display/draw a MultiPolygon GeoJSON on a Leaflet map

I'm trying to display a GeoJSON MultiPolygon object in a Leaflet map. I get it from a PostgreSQL database as a JSON and I trnasform it to a GeoJSON.

I've validated de MultiPolygon object in GeoJSONLint and it's ok: enter image description here

But I'm not able to accomplish this in my app =(

This is my code:

       $http.get(URI_SERVICE+"buscar-clase/"+JSON.stringify(params))
            .success(function (data) {
                console.log(L.multiPolygon(data.coordinates).toGeoJSON());
                adaLayer.clearLayers();
                adaLayer = L.geoJson(L.multiPolygon(data.coordinates).toGeoJSON(), {
                    style: function () {
                        return {weight: 1, color: "#000000"}
                    }
                });
                adaLayer.addTo(map);
            }).error(function (err) {
                console.log(err);
        });

For the record, the map var is working fine, I've printed other layers of GeoJSON.

like image 902
daniegarcia254 Avatar asked May 18 '15 17:05

daniegarcia254


1 Answers

Give L.geoJSON the entire payload, not just the coordinates array. Like

        adaLayer = L.geoJson(data, {
            style: function () {
                return {weight: 1, color: "#000000"}
            }
        });
like image 181
snkashis Avatar answered Oct 20 '22 00:10

snkashis