I like this example of the boroughs of Amsterdam:
Boroughs of Amsterdam wfs in leaflet
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
}
}