Time for action – parsing GeoJSON
You might want to query GeoServer and parse features in jQuery. We're just parsing a JSON string.
Go to the Layer Preview screen and click on the dropdown for All Formats for the
topp:states
layer.Select the GeoJSON option or get the output directly using the following URL. Note that to limit the results, we are using the
featureid
parameter. We'll talk about filters in another chapter.http://localhost:8080/geoserver/topp/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=topp:states&featureid=states.1,states.2,states.3&maxFeatures=50&outputFormat=json
Save this output in a text file called
states.json
.Parse with jQuery. The following is a snippet of the code example included in this chapter:
<script> $.getJSON('states.json', function(data) { $.each(data.features, function(key, val) { $('body').append('properties.STATE_NAME ' + val.properties.STATE_NAME + 'geometry.coordinates ' + val.geometry.coordinates); }); }); }); ...