javascript - 地理服务器到 openlayers wfst
问题描述
我想使用下面的代码将我的地理服务器层带入开放层但是我无法获得正确的 url 格式来输入以下层 url --- localhost:8080/geoserver/itachi/ows?service=WFS&version=1.0。 0&request=GetFeature&typeName=itachi%3Awfs_geom&maxFeatures=50
var sourceWFS = new ol.source.Vector({
loader: function (extent) {
$.ajax('https://gsx.geolytix.net/geoserver/geolytix_wfs/ows', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'wfs_geom',
srsname: 'EPSG:3857',
bbox: extent.join(',') + ',EPSG:3857'
}
}).done(function (response) {
sourceWFS.addFeatures(formatWFS.readFeatures(response));
});
},
解决方案
您也许可以使用完整的网址来做到这一点
var sourceWFS = new ol.source.Vector({
url: 'http://localhost:8080/geoserver/itachi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=itachi%3Awfs_geom&maxFeatures=50',
format: formatWFS
});
但是如果您需要更改预测(例如,数据在 EPSG:4326 中返回并且视图是 EPSG:3857),您将需要使用加载器
var sourceWFS = new ol.source.Vector({
loader: function () {
$.ajax('http://localhost:8080/geoserver/itachi/ows', {
type: 'GET',
data: {
service: 'WFS',
version: '1.0.0',
request: 'GetFeature',
typename: 'itachi:wfs_geom',
maxFeatures: '50'
}
}).done(function (response) {
sourceWFS.addFeatures(formatWFS.readFeatures(response),{
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
});
},
strategy: ol.loadingstrategy.all
});
如果可以更新数据,您将需要调用sourceWFS.refresh();
重新加载
推荐阅读
- node.js - 我可以在 Heroku 上使用基于文件的数据库吗?
- c++11 - `final` 是否违反 ODR?
- mercurial - 仅列出 hg 清单中的工作目录文件和目录?
- firebase - 如何使用 Flutter 在 FireStore 中创建集合中的文档
- z3 - Dafny,将序列切片分配给数组
- git - Git:我在存储库中创建了一个存储库,现在我只想要一个大存储库
- javascript - usemin dev() 无法处理 .js 文件
- c# - 如何让一个类充当数组?
- java - 如何在我的 Spring Boot Security OAuth2 应用程序中仅为某些类启用 OAuth2?
- javascript - Javascript:typeof 表示“函数”,但不能作为函数调用