I looked at this example to load a layer into my map. I get a response from my geoserver in geoJSON format. But still, the layer is not showing on my map. I also zoomed out to check for reprojection issues. No error is thrown in console.
When I parse my response in http://geojsonlint.com/ the response is:
Line 1: old-style crs member is not recommended
Line 1: Polygons and MultiPolygons should follow the right-hand rule
But http://geojson.io shows the geoJSON fine.
My Code:
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://192.168.66.110:8080/geoserver/gis/ows?service=WFS&version=1.1.0&request=GetFeature&typeName=gis:tbl_krs&outputFormat=application/json&srsname=EPSG:4326&'+
'bbox=' + extent.join(',') + ',EPSG:3857';
},
strategy: ol.loadingstrategy.bbox
});
var wfsLayer = new ol.layer.Image({
source: new ol.source.ImageVector({
source: vectorSource
})
})
map.addLayer(wfsLayer)
wfsLayer.setVisible(true);
Also my map and view settings:
var view = new ol.View({
center: ol.proj.fromLonLat([10, 51]),
zoom: 6
});
var map = new ol.Map({
target: 'map',
view: view,
controls: ol.control.defaults().extend([
new ol.control.Zoom(),
//new ol.control.FullScreen(),
//new ol.control.ZoomSlider(),
new ol.control.LayerSwitcher({
tipLabel: 'Layer Switcher'
}),
//new ol.control.OverviewMap(),
new ol.control.ScaleLine()
]),
layers: [baselayers, toplayers]
});
Response snippet with &srsname=EPSG:3857
:
{
"type": "FeatureCollection",
"totalFeatures": 402,
"features": [{
"type": "Feature",
"id": "tbl_krs.155",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[729476.78514853, 6399530.92085941],
[730019.30907858, 6400235.09490534],
[729750.34332383, 6401154.79413948],
[732440.10602656, 6404204.80738186],
[734470.17505526, 6403726.40499375],
[735141.6145631, 6404055.5354657],
[736018.53227221, 6405097.25241155],
[736425.08527793, 6405666.89631325],
[736099.05752955, 6406241.17954547],
[734876.82520048, 6406485.23386293],
[734452.09336458, 6407838.53494448],
[738103.00414279, 6409743.87439966],
[741458.74796937, 6415323.4007552],
[742925.10037322, 6421025.93818922],
[744970.38199679, 6421488.71771255],
[746284.45642492, 6420160.14779568],
[746381.92207616, 6420014.33618437],
[748759.03462201, 6413394.73771304],
[750198.42322968, 6408846.9377395],
[750145.83936406, 6407601.8344375],
[747610.81232342, 6406668.48474281],
[745235.97782396, 6404472.83499567],
[746748.34292771, 6403300.16004243],
[749183.2598718, 6401116.61335638],
[747061.97817989, 6398076.58747616],
[745423.93817996, 6396189.48940849],
[739740.91688288, 6394589.86928475],
[736242.45634245, 6394315.09502095],
[735958.35722326, 6394805.50239602],
[735501.96048888, 6397678.32572755],
[731921.89800399, 6395833.91169814],
[730488.39371686, 6396786.80690645],
[730086.93440624, 6397467.86745722],
[729476.78514853, 6399530.92085941]
]
]
]
},
"geometry_name": "the_geom",
"properties": {
"krs": "Trier",
"sumarea_3": 0,
"sumarea_5": 0,
"bl": "Rheinland-Pfalz",
"sumarea_1": 0,
"sumarea_1_": 2404,
"sumarea_3_": 1713,
"sumarea_5_": 663
}
}],
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::3857"
}
}
}
EDIT:
I can see the layer by using this code, but that's not what I need:
var wfsVectorLayer = new ol.layer.Vector({
source: vectorSource
});
map.addLayer(wfsVectorLayer)
wfsVectorLayer.setVisible(true);
EDIT 2:
wfsLayer.getSource().getSource().getFeatures()
is returning my features too.
Should I create a ticket at OpenLayers' github at this point?