Ushant Suman (23) [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 (260) [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 (23) [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 (260) [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 (260) [Avatar] Offline
#7
Ah sorry didn't realize you were answering his question and not asking another.

I see now smilie
Ushant Suman (23) [Avatar] Offline
#8
I was coding this application 6 months before I am shifted to a very different track but still I have set the visible false by default when the application is loaded and I bind the visiblity property of the layer through a checkbox in the layer tree.So if I set it true the layer will be loaded and the check box is ticked and the layer would be visibleto the browser.When you publish a layer like WMS service just like this:
new ol.layer.Tile({
source: new ol.source.TileWMS({

url: 'http://localhost:8080/geoserver/NaturalEarth/wms',

params: {STYLES: '','VERSION': '1.1.1', 'LAYERS': 'NaturalEarth:custom_points'}
}),
name: 'points',
visible:false


})
It would publish the layer as image in the browser and editing on data will not be possible.So I was trying to publish the layer stored in postgis as WFS so that editing on raw data can be done from front end.Although,my project demand only the display of data points along with the labels and i done this by publishing the postgis layer as wms and label is displayed by using style level descriptor of geoserver.and I did not do furthur research on that.Anyone published postgis layer as WFS can help me in this regrard