Начинаю изучать OpenLayers. Задача элементарная – есть база PostGIS/PostgreSQL, есть Geoserver с опубликованными слоями из этой базы, задача - редактировать эти слои через веб. Разобрался как слои отображать (WFS_T), как редактировать, но проблема в следующем – когда скрипт отправляет транзакцию, в ответ приходит следующее (смотрю firebug-ом):
Код: Выделить всё
<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://localhost:82/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="NoApplicableCode">
<ows:ExceptionText>No such feature type http://localhost:82/geoserver/cite:boundary-points</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
Сам пост запрос:
Код: Выделить всё
<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Insert>
<boundary-points xmlns="http://localhost:82/geoserver/cite">
<geometry>
<MultiPoint xmlns="http://www.opengis.net/gml">
<pointMember>
<Point>
<pos>131.0723876953125 46.3897705078125</pos>
</Point>
</pointMember>
</MultiPoint>
</geometry>
</boundary-points>
</Insert>
</Transaction>
Код: Выделить всё
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css\ol.css" type="text/css">
<script src="Scripts\ol.js" type="text/javascript"></script>
<script src="Scripts\jQuery_2.2.3.js" type="text/javascript"></script>
<title>OL редактор</title>
<style type="text/css">
.edit {
width: auto;
background: #ccc;
padding: 5px;
padding-right: 20px;
border: solid 1px black;
float: left;
}
</style>
</head>
<body>
<DIV id="customControl" class="edit">
<input type="button" id="customControlCreate" value="create"/>
<input type="button" id="customControlEdit" value="edit"/>
<input type="button" id="customControlDelete" value="delete"/>
<input type="button" id="customControlSave" value="save"/>
</DIV>
<div id="map"></div>
<script type="text/javascript">
var bounds = [130.39465, 42.2933078,
139.0329652, 48.4645449];
var interaction;
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:82/geoserver/cite/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=cite:boundary-polygon&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(69,139,116, 1.0)',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(102, 205, 170, 1.0)'
})
})
});
var projection = new ol.proj.Projection({
code: 'EPSG:4326',
units: 'degrees',
axisOrientation: 'neu'
});
var view = new ol.View({
zoom: 12
});
var map = new ol.Map({
layers: [vector],
target: 'map',
view: new ol.View({
projection: projection
})
});
map.addLayer(
new ol.layer.Vector({
source:
new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:82/geoserver/cite/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=cite:water-line&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
}),
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(30, 144, 255, 1.0)',
width: 2
})
})
})
);
var fill = new ol.style.Fill({
color: 'rgba(205, 102, 29, 0.4)'
});
var stroke = new ol.style.Stroke({
color: '#8b4513',
width: 1.25
});
var point = new ol.layer.Vector({
source:
new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:82/geoserver/cite/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=cite:boundary-points&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
}),
style: new ol.style.Style({
image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
}),
fill: fill,
stroke: stroke
})
})
map.addLayer(point);
map.getView().fit(bounds, map.getSize());
var dirty = {};
var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML({
featureNS: 'http://localhost:82/geoserver/cite',
featureType: 'boundary-points',
srsName: 'EPSG:4326'
});
//
var transactWFS = function (p, f) {
switch (p) {
case 'insert':
node = formatWFS.writeTransaction([f], null, null, formatGML);
break;
case 'update':
node = formatWFS.writeTransaction(null, [f], null, formatGML);
break;
case 'delete':
node = formatWFS.writeTransaction(null, null, [f], formatGML);
break;
}
s = new XMLSerializer();
str = s.serializeToString(node);
$.ajax('http://localhost:82/geoserver/cite/wfs', {
type: 'POST',
dataType: 'xml',
processData: false,
contentType: 'text/xml',
data: str
}).done();
}
//text/xml
//
$('#customControlCreate').on('click', function () {
interaction = new ol.interaction.Draw({
type: 'MultiPoint',
source: point.getSource()
});
map.addInteraction(interaction);
interaction.on('drawend', function(e) {
transactWFS('insert',e.feature);
});
});
</script>
</body>