I am trying to load vector with the following code:
var sourceWFS = new ol.source.Vector({
loader: function(extent) {
$.ajax('http://************/geoserver/Viva/ows', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'Viva:building',
srsname: 'EPSG:4326',
bbox: extent.join(',') + ',EPSG:4326'
}
}).done(function(response) {
sourceWFS.addFeatures(formatWFS.readFeatures(response));
});
},
I don`t seem to be able to get any features. I have a suspicion that I am not setting the typename right. The data is points of buildings.
The url in the geoserver preview layer is the following:
http://************/geoserver/Viva/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Viva:building&maxFeatures=50&outputFormat=text.
I have tested loading a GeoJson layer and it works without fail from the same server and data by using the url-method.
The end goal is to add a new point with WFS-t.
I got most of my code from this example:
Update:
I have changed the ol.format.WFS like follow:
var formatWFS = ol.format.WFS({
featureNS: "http://serverURL:8080/geoserver/vivadata",
featureType: "Viva:buildingType"
});
and I get the following error in the console:
Uncaught TypeError: Cannot read property 'writeTransaction' of undefined at transactWFS
This is the block of code for transactWFS:
var transactWFS = function(mode, a) {
var node;
switch (mode) {
case 'insert':
node = formatWFS.writeTransaction([a], null, null, formatGML);
break;
case 'update':
node = formatWFS.writeTransaction(null, [a], null, formatGML);
break;
case 'delete':
node = formatWFS.writeTransaction(null, null, [a], formatGML);
break;
}
and this is my draw function:
var DrawControl = function(opt_options) {
var options = opt_options || {};
this.active = options.active || false;
var draw = new ol.interaction.Draw({
source: options.source,
type: 'Point',
geometryName: 'geom'
});
draw.on('drawstart', function(t) {
buildingLayer.set('selectable',false);
});
//Sets building properties when addBuilding-button isclicked
draw.on('drawend', function(t) {
var a = t.feature;
a.setProperties({
prim_add: document.getElementById('inpPriAddress').value,
sec_add: document.getElementById('inpSecAddress').value,
tert_add: document.getElementById('inpTerAddress').value,
build_type:document.getElementById('inpBuildingType').value,
build_mat:document.getElementById('inpBuildingMaterial').value,
build_own: document.getElementById('inpHouseOwner').value,
})
transactWFS('insert', a);
buildingLayer.set('selectable',true);
});