I'm writing because I attempted almost all the tries suggested in any other Q/A on this thread. I have this vector points layer on my local GeoServer and i'm trying to plot my points on a OSM base map through OpenLayers. My script (very basic) is the following:
<!DOCTYPE html>
<html>
<head>
<title>Wfs Map</title>
<link rel="stylesheet" href="https://openlayers.org/en/v5.1.3/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v5.1.3/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: ol.proj.transform([15.66, 42.97], 'EPSG:4326', 'EPSG:3857'),
zoom: 7
})
});
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
url:'http://localhost:8080/geoserver/wfs?service=wfs&version=2.0.0&request=GetFeature&typeNames=barriere:barriere2&outputFormat=json',
format: new ol.format.GeoJSON({dataProjection: 'EPSG:3857'})
})
});
map.addLayer(vector);
</script>
</body>
</html>
Everything that I obtain is the OSM layer and no points. The original sdr of the layer is 4326.
The strange thing (unexplicble to me) is that if I place the same .json file in my github sandbox and I use:
url: 'https://raw.githubusercontent.com/annalisapg/sandbox/master/barriere2_wfs.json',
the points appear. So, in your opinion, what's wrong between the script, the layer and my geoserver installation?