Openning a PostGIS shapefile using django in web app

Viewed 124

I created a django app that connects to Geoserver and PostGIS database. The intention is to create a web app using Leaflet, django and PostGIS connection. I add the data to PostGIS and import do django. However everytime appears these errors:

Object 'parsererror' Error: getJson was not called

    at Function.error (jquery.min.js:2)

    at e.converters.script json (jquery.min.js:2)

    at jquery.min.js:2

    at l (jquery.min.js:2)

    at HTMLScriptElement.i (jquery.min.js:2)

    at HTMLScriptElement.dispatch (jquery.min.js:2)

    at HTMLScriptElement.v.handle (jquery.min.js:2)

Then it gives me this error:

Uncaught ReferenceError: getJson is not defined

In the django (index.html) the shapefile is requested to Geoserver as WFS, as this:

var wfsLayer_solos = L.Geoserver.wfs("http://localhost:8080/geoserver/wfs", {
  layers: "gic:solos1_2_4326",
  style: {
    color: "black",
    fillOpacity: "0",
    opacity: "0.5",
  },
  onEachFeature: function (feature, layer) {
    layer.bindPopup('<pre>'+JSON.stringify(feature.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
  },
});
1 Answers

The error is generated from the leaflet-geoserver-request library. The error happens when you put the wrong layer name into the layers parameter. The layers parameter will only support the features, i.e. vector layers. Please also add the layer to the map as below,

wfsLayer_solos.addTo(map);
Related