3

Is it possible to consume the GeoJSON from Geoserver as a 'dynamic' service in a Leaflet application?

So far I have only seen how to consume a static GeoJSON file.

Being able to construct GeoJSON from what GeoServer publishes means we can publish PostGIS data to a Leaflet app without having to re-build a GeoJSON file.

The URL from GeoServer looks like this:

http://servername:8080/geoserver/dps/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=dps:Schools_Current&maxFeatures=50&outputFormat=application%2Fjson

...and the GeoJSON itself looks like this (for a single feature):

{"type":"FeatureCollection","totalFeatures":221,"features":[{"type":"Feature","id":"Schools_Current.521","geometry":{"type":"Point","coordinates":[-105.02726842,39.66184512]},"geometry_name":"geom","properties":{"school_name":"DSST: College View High School","abbreviation":"DSST:CV HS  ","elem":0,"mid":0,"high":1,"schnum":521,"classification":"Charter                  ","school_level":"High                     ","current_config":"9-10      ","final_config":"9-12      ","b_elem":0,"b_mid":0,"b_high":0,"label_x":-105.025346737628,"label_y":39.6620286090456}
  • Just have a look at my answer to another question: gis.stackexchange.com/a/130553/45041 and the jsfiddle: jsfiddle.net/expedio/8r1ncv6a . Does this work for you, too? – Thomas B Jan 27 '17 at 20:18
  • @ThomasB there is some logic in one of those answers that looks promising... I'll test on Monday! – DPSSpatial Jan 28 '17 at 15:23
  • @ThomasB I was able to reproduce your jsfiddle example, and all looks straightforward enough, but getting a really weird error in console: "SyntaxError: expected expression, got '<'[Learn More] ows:1" --- no idea what that means?~!?! But maybe this is due to a cross origin policy error...? – DPSSpatial Feb 13 '17 at 22:47
  • 1
    @ThomasB ahhh got it to work... great solution in your JSFiddle... did you want to add the JSFIddle example to your other answer? That was the solution to this question... thank you again!!! – DPSSpatial Feb 15 '17 at 20:13
  • 1
    @AndreSilva thanks for the reminder - I had forgotten to figure out how to post the solution given how I ended up using it. But i'll dig around this week. – DPSSpatial Feb 24 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.