I want to reproject my local-geoJson file in epsg:28992 to the OSM EPSG:4326 in OpenLayers. I have the feeling I am close to the solution but I don't know what the next step is. I've tried and looked for multiple examples here at SO but I've the feeling I'm missing a certain line of code somewhere.
For now the code below shows me my local gjson file at null-island. How do I tell Open Layer to reproject it to the Netherlands?
thanks in advance.
<html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.0/proj4.js"></script>
<script src="http://epsg.io/28992.js"></script>
<!-- Include OpenLayers -->
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/build/ol.js"></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/css/ol.css"
/>
<style>
html, body, #map {
margin: 0;
height: 75%;
width: 75%;
font-family: sans-serif;
background-color: #04041b;
}
</style>
<title>A simple web app</title>
</head>
<body>
<div id="map"></div>
<script>
// create an empty OpenLayers map
var map = new ol.Map({
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
// create OpenStreetMap base layer
var baseMap = new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'http://{a-c}.tile.osm.org/{z}/{x}/{y}.png',
attributions: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
})
});
map.addLayer(baseMap);
/*
//reproject
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON({
defaultDataProjection: 'EPSG:4326',
featureProjection: 'EPSG:28992'
})).readFeatures(geojsonObject)
});
//reproject
*/
//LocalJson
var geojsonSource = new ol.source.Vector({
format: new ol.format.GeoJSON(
),
projection: 'EPSG:28992',
url: 'PS2019_buurt.geo.json'
});
var geojsonStyle = new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 0, 0, 0.6)' // red
}),
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 0, 1)' // black
})
});
var geojsonLayer = new ol.layer.Vector({
source: geojsonSource,
style: geojsonStyle
});
map.addLayer(geojsonLayer);
//LocalJson
</script>
</body>
</html>