Я пытаюсь загрузить некоторые функции из Geoserver в векторный слой в Openlayers 3.9.0.не может добавлять функции к слою WFS
var url = 'http://localhost:5550/geoserver/mymap/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mymap:layer&'+'outputFormat=application/json&maxFeatures=50';
var projection = ol.proj.get('EPSG:3857');
var extent = [2297128.5, 4618333, 2459120.25, 4763120];
var amir = new ol.source.Vector({
format: new ol.format.GeoJSON(),
loader: function (extent) {
$.ajax(url, {type: 'GET'})
.done(loadFeatures)
.fail(function() {alert("error");});
},
strategy: ol.loadingstrategy.bbox
});
function loadFeatures(response) {
formatWFS = new ol.format.WFS();
var features = formatWFS.readFeatures(response);
amir.addFeatures(features);
//-----------OR---------------------
var features = amir.readFeatures(response);
amir.addFeatures(features);
}
var fill = new ol.style.Fill({
color: 'rgba(0,0,0,0.2)'
});
var stroke = new ol.style.Stroke({
color: 'rgba(0,0,0,0.4)'
});
var circle = new ol.style.Circle({
radius: 6,
fill: fill,
stroke: stroke
});
jake = new ol.layer.Vector({
source: amir,
style: new ol.style.Style({
fill: fill,
stroke: stroke,
image: circle
})
});
В loadFeatures
функции, если я использую
formatWFS = new ol.format.WFS();
var features = formatWFS.readFeatures(response);
amir.addFeatures(features);
я Uncaught AssertionError: Failure: Unknown source type
указывающие на линию OpenLayers, что проливает ошибки и к этой линии моего кода var features = formatWFS.readFeatures(response);
.
Если я использую
var features = amir.readFeatures(response);
amir.addFeatures(features);
я Uncaught TypeError: sourceVector.readFeatures is not a function
указывая на var features = amir.readFeatures(response);
.
Запрос на WFS выглядит нормально, с OK 200 status
. Если я возьму URL-адрес запроса, отправленный Geoserver, и открою его на новой вкладке, я получу необработанный GeoJSON, как {"type":"FeatureCollection","totalFeatures":422,"features":[{"type":"Feature","id":"layer.709","geometry":{"type":"Point","coordinates":[2391735.8907621,4695330.8039257005]},"geometry_name":"l_geom","properties":{"l_name":"Leeron"}},....//next feature
Итак, его FeatureCollection
не просто массив. Не то, чтобы я знаю, как справиться с этим
Я не понимаю, почему установить ol.format.WFS
, а не просто читать/добавлять функции. Я не знаю, как отлаживать и добавлять функции на свой уровень.
Пожалуйста, см [ «Должны ли вопросы включают„метки“в их названиях?»] (Http://meta.stackexchange.com/questions/19190/should -questions-include-tags-in-their-titles), где консенсус «нет, они не должны»! –