• OL实现属性查询的功能


    属性查询是很平常的一个功能,在这里实现的查询功能还是结合WFS服务的filter完成,用到的filter是new ol.format.filter.equalTo('name', value),filter就是完成各种过滤去查询数据,可以满足基本的查询需求。用了好长时间的geoserver感觉虽然没法像arcserver那么方便,但是基本的功能都可以实现,毕竟是开源的。

    一、主要函数

    //属性查询
                function Query(value) {
                    // 创建一个请求
                    var featureRequest = new ol.format.WFS().writeGetFeature({
                        srsName: 'EPSG:4326',//坐标系
                        featureNS: 'http://www.opengeospatial.net/cite',// 注意这个值必须为创建工作区时的命名空间URI
                        featurePrefix: 'cite',//工作区的命名
                        featureTypes: ['bou2_4p '],//所要访问的图层
                        maxFeatures: 5000,
                        outputFormat: 'application/json',
                        filter: new ol.format.filter.equalTo('name', value)
                    });
    
                    // 发送请求
                    fetch('http://localhost:8080/geoserver/wfs', {
                        method: 'POST',
                        body: new XMLSerializer().serializeToString(featureRequest)
                    }).then(function (response) {
                        return response.json();
                    }).then(function (json) {
                        var features = new ol.format.GeoJSON().readFeatures(json);
                        vectorSource.addFeatures(features);
                    });
                }

    二、来张效果图

  • 相关阅读:
    Count on a tree
    图论1 1009
    DP2 1008
    DP1 1008
    NOIP 模拟 1006
    2019 CSP-S 初赛退役记
    9.13——TEST NOIP模拟测试
    [洛谷P2387][NOI2014]魔法森林
    [洛谷P2596][ZJOI2006]书架
    [BZOJ4241]历史研究
  • 原文地址:https://www.cnblogs.com/tuboshu/p/10752296.html
Copyright © 2020-2023  润新知