0

I like this example of the boroughs of Amsterdam:

Boroughs of Amsterdam wfs in leaflet

https://geodata.nationaalgeoregister.nl/wijkenbuurten2014/ows?service=WFS&version=2.0.0&request=GetFeature&outputFormat=application/json&srsName=EPSG:4326&typeName=wijkenbuurten2014:cbs_buurten_2014&maxFeatures=1&outputformat=application/json

But how is it possible that I'm trying to change the WFS with my own geoserver services, and it doesn't work? I've enabled geojsonp in the past. I tried to find and delete the properties that are not there.

        var geojson = L.geoJson(null,
            {
                style: getStyle,
                onEachFeature: onEachFeature
            }
        ).addTo(map);

        var url = 'https://geodata.nationaalgeoregister.nl/wijkenbuurten2014/ows?';

        // These parameters are identical for all GeoJSON-requests:
        var params = 'service=WFS&version=2.0.0&request=GetFeature&outputFormat=application/json&srsName=EPSG:4326&';

        // These parameters have to be modified per GeoJSON-request
        // Request the neighbourhood map 2014:
        params += 'typeName=wijkenbuurten2014:cbs_buurten_2014&';

        // Just the attributes: personenautos_per_huishouden en geometrie
        params += 'propertyName=buurtnaam,personenautos_per_huishouden,geom&';

        // Just the neighbourhoods within the municipality of Amsterdam
        params += 'cql_filter=gemeentenaam \= \'Amsterdam\'';

        // Ajax without jQuery ;-)
        var xhr = new XMLHttpRequest();
        xhr.open('GET', encodeURI(url + params));
        xhr.onload = function() {
            if (xhr.status === 200) {
                geojson.addData(JSON.parse(xhr.responseText));
            } else {
                alert('Request failed.  Returned status of ' + xhr.status);
            }
        };
        xhr.send();

        function getStyle(features) {
            var rate = features.properties.personenautos_per_huishouden;
            return {
                    color: '#fff',
                    fillColor: getColour(rate),
                    weight: 0.8,
                    opacity: 1,
                    fillOpacity: 0.9
                }
        }

        function getColour(d) {
            var colour,
            colorScale = chroma
                .scale('YlOrBr')
                .domain([0,1.5]);
            if (d < 0) {
                colour = '#eee'
            } else {
                colour = colorScale(d).hex()
            }
            return colour;
        }

--and my unworking code:

        var geojson = L.geoJson(null,
            {
                style: getStyle,
                onEachFeature: onEachFeature
            }
        ).addTo(map);

        var url = 'http://vdlibraries.fr/geoserver/france/ows?';

        // These parameters are identical for all GeoJSON-requests:
        var params = 'service=WFS&version=1.0.0&request=GetFeature&outputFormat=application/json&srsName=EPSG:4326&';

        // These parameters have to be modified per GeoJSON-request
        // Request the neighbourhood map 2014:
        params += 'typeName=france%3ATM_WORLD_BORDERS_SIMPL-0.3';

        // Just the attributes: personenautos_per_huishouden en geometrie
  //      params += 'propertyName=buurtnaam,personenautos_per_huishouden,geom&';

        // Just the neighbourhoods within the municipality of Amsterdam
     //   params += 'cql_filter=gemeentenaam \= \'Amsterdam\'';

        // Ajax without jQuery ;-)
        var xhr = new XMLHttpRequest();
        xhr.open('GET', encodeURI(url + params));
        xhr.onload = function() {
            if (xhr.status === 200) {
                geojson.addData(JSON.parse(xhr.responseText));
            } else {
                alert('Request failed.  Returned status of ' + xhr.status);
            }
        };
        xhr.send();

        function getStyle(features) {
            var rate = features.properties.iso2;
            return {
                    color: '#fff',
                    fillColor: '#fff',
                    weight: 0.8,
                    opacity: 1,
                    fillOpacity: 0.9
                }
        }

My attempt

World borders services I wish to add

http://vdlibraries.fr/geoserver/france/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=france%3ATM_WORLD_BORDERS_SIMPL-0.3&maxFeatures=1&outputFormat=application%2Fjson

1
  • @TomazicM ok, I just added the relevant services adresses, the rest may not be relevant
    – Vincent Dc
    Commented Jul 16, 2021 at 19:31

1 Answer 1

1

There was a letter missing or too much, but I found what was the problem, it was : that it was required to allow WFS services in the Workspace settings, right into Geoserver. It works now.

Geoserver Workspaces

the working code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.