I'm currently doing a Proof Of Concept involving OpenLayers and I'm facing an issue.
I follow this official sample to try to load a map with raster and WFS layers : http://openlayers.org/en/latest/examples/vector-wfs.html
I can make this sample works fine with EPSG:4326, I take exactly the same code, only things changed are :
- vectorSource.url = taking my WFS
- raster.Source = OMS instead of BingMaps
- EPSG:4326 instead of EPSG:3857 from the sample
Here is the JavaScript code :
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function (extent) {
return 'http://localhost:8090/geoserver/ANF/ows?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=ANF:PARC_BIODEM_SP&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
layers: [raster, vector],
target: document.getElementById('map'),
view: new ol.View({
center: [6.13, 49.845],
projection: 'EPSG:4326',
minZoom: 10,
maxZoom: 28,
zoom: 10
})
});
Now, I want to display the map in EPSG:2169.
When I set the new projection to the WFS layer (vectorSource), it doesn't display it anymore on the map. And when I set the new projection to the map view itself, the HTML page stays white, and the debugger says an error : "ol.js:68 Uncaught TypeError: Cannot read property 'H' of undefined"
This is the JavaScript code I would like to have, but that is not working :
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function (extent) {
return 'http://localhost:8090/geoserver/ANF/ows?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=ANF:PARC_BIODEM_SP&' +
'outputFormat=application/json&srsname=EPSG:2169&' +
'bbox=' + extent.join(',') + ',EPSG:2169';
},
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
layers: [raster, vector],
target: document.getElementById('map'),
view: new ol.View({
center: [6.13, 49.845],
projection: 'EPSG:2169',
minZoom: 10,
maxZoom: 28,
zoom: 10
})
});
My WFS layer comes from GeoServer, and data from an Oracle database, and I'm sure that the data are well available in EPSG:2169. GeoServer says that the native SRC is EPSG:2169, and an OpenLayers preview (always from GeoServer) shows well the layer.
Any idea of why my WFS looks like well working from GeoServer in EPSG:2169 (OpenLayers preview), but not in my web page with OpenLayers ? Am I missing something ?
Many thanks !