Ushant Suman (21) [Avatar] Offline
#1
Hi,

I am trying to view a Postgis layer as WFS from geoserver and I have tried something like this:

source4 =new ol.source.Vector({
loader: function (extent) {
//place here any actions on start loading layer
document.getElementById('laodingcont').innerHTML = "<font color='orange'>start loading.....</font>";
$.ajax('http://localhost:8080/geoserver/NaturalEarth/wfs', {
type: 'GET',
data: {
service: 'WFS',
version: '1.0.0',
request: 'GetFeature',
typename: 'namespace:"NaturalEarth:Wells',
outputFormat: 'application/json',
srsname: 'EPSG:4326',
bbox: extent.join(',') + ',EPSG:4326'
},
success:function(response) {
format = new ol.format.GeoJSON(),
source4.addFeatures(format.readFeatures(response));
document.getElementById('laodingcont').innerHTML = "<font color='green'>finish loading vector layer.</font>";
}

})
},
strategy: ol.loadingstrategy.bbox
});



layer4 = new ol.layer.Vector({
source: source4,
name: 'WFS',
description: 'Test.',
visible: false,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});

But I am not able to see anything in the browser.please help.I am also not geeting any error in console.

regina.leo (257) [Avatar] Offline
#2
Unfortunately don't know answer to this. Might be better to ask on GIS stack exchange if you haven't already
Ushant Suman (21) [Avatar] Offline
#3
Ok no issues
476774 (2) [Avatar] Offline
#4
In second part of code ---

layer4 = new ol.layer.Vector({
source: source4,
name: 'WFS',
description: 'Test.',
visible: false,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});

why you are set layer visible = false?
if not geeting any error in console then try this;

var layer4 = new ol.layer.Vector({
source: source4,
name: 'WFS',
description: 'Test.',
visible: true,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
regina.leo (257) [Avatar] Offline
#5
I don't see this example in the book. Is this your code and if so not clear what you are asking.

One might set visibile to false if they don't want the layer preloaded but want it to show in a layer control so user can toggle it on.

476774 (2) [Avatar] Offline
#6
Mr.Ushant asked he want to show postGIS layer in open layer 3 using geoserver WFS service. He is mentioned in question 'his code is ok but layer not showing and not any errors appears in console' . So I think if he is give layer visible option true than its appears. Simple.!

regina.leo (257) [Avatar] Offline
#7
Ah sorry didn't realize you were answering his question and not asking another.

I see now smilie