繁体   English   中英

gelayerver to openlayers wfst

[英]geoserver to openlayers wfst

我想使用下面的代码将我的geoserver图层打开到开放图层中但是我无法获得正确的url格式来输入以下图层url --- localhost:8080 / geoserver / itachi / ows?service = WFS&version = 1.0。 0&请求= GetFeature&的typeName =鼬%3Awfs_geom&但MaxFeature = 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));
        });
    },

您可以使用完整的URL进行操作

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(); 重装

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM