Dankzij de antwoorden in https://forum.pdok.nl/t/welke-library-handigste-om-nl-data-te-tonen/1993 heb ik besloten om Leaflet te gebruiken als mijn mapping engine.
Maar het lukt me nog niet om mijn PostGIS data op de kaart te tonen.
Ik gebruik .NET Core met EF Core om te communiceren met mijn PostGIS database. Na heel veel gedoe is het me gelukt een valid GeoJSON (volgens http://geojsonlint.com/) uit mijn controller te krijgen, zie mijn vraag op SO: serialization - Serialize data from PostGIS to JSON - Stack Overflow
Mijn REST service produceert nu deze GeoJSON:
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"id":"1",
"geometry":{
"type":"Point",
"coordinates":[
523064.716597462,
191390.015
]
},
"properties":{
"id":1,
"use":false,
"locationId":"KNP_1"
}
},
{
"type":"Feature",
"id":"2",
"geometry":{
"type":"Point",
"coordinates":[
519349.860113963,
170162.249352578
]
},
"properties":{
"id":2,
"use":false,
"locationId":"CP_6"
}
}
]
}
en mijn Leaflet code is:
var RD = new L.Proj.CRS( 'EPSG:28992','+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +no_defs',
{
resolutions: [3440.640, 1720.320, 860.160, 430.080, 215.040, 107.520, 53.760, 26.880, 13.440, 6.720, 3.360, 1.680, 0.840, 0.420, 0.210],
bounds: L.bounds([-285401.92, 22598.08], [595401.9199999999, 903401.9199999999]),
origin: [-285401.92, 22598.08]
}
);
var map = new L.Map('map-canvas', {
crs: RD
});
map.attributionControl.setPrefix('');
L.tileLayer('https://geodata.nationaalgeoregister.nl/tiles/service/tms/1.0.0/opentopoachtergrondkaart/EPSG:28992/{z}/{x}/{y}.png', {
tms: true,
attribution: 'OpenTopo © PDOK',
}).addTo(map);
L.geoJson('http://localhost:5000/api/data/',
{
attribution: 'Mine'
}
).addTo(map);
map.setView(new L.LatLng(52.7080, 5.7618), 7);
Maar ik blijf de foutmelding:
Uncaught Error: Invalid GeoJSON object.
at Ft (leaflet.js:5)
at e.addData (leaflet.js:5)
at e.initialize (leaflet.js:5)
at new e (leaflet.js:5)
at Object.Xt (leaflet.js:5)
at Leaflet-demo.html?_ijt=kf6v0itfcubnsao4rlvfr19:58
Ft @ leaflet.js:5
addData @ leaflet.js:5
initialize @ leaflet.js:5
e @ leaflet.js:5
Xt @ leaflet.js:5
krijgen.
Er moet toch wel iemand zijn die iets soortgelijks heeft gedaan: PostGIS-data via .NET Core REST service op een Leaflet-kaart tonen?
Ik heb het gevoel dat mijn opzet veel ingewikkelder is dan nodig.
Wie heeft nog wat suggesties?