Geoserver+Ajax 请求服务(空间、属性查询及添加图层服务)

一、过滤不为Geometry字段时属性查询:

   function getBoundary(JIGOU_MC) {
            var data = {
                "service": "wfs",
                "version": "1.1.0",
                "request": "GetFeature",
                "typeName": layer,//图层
                "outputFormat": "application/json",
                "cql_filter": "NAME LIKE '%" + JIGOU_MC + "%'"
            };
            $.ajax({
                url: url,//wfs服务地址
                data: data,
                type: "GET",
                contentType: "text/plain;charset=UTF-8",
                success: function (data) {
                    var features = new ol.format.GeoJSON().readFeatures(data);
                    if (features.length > 0) {
                        var extent = features[0].getGeometry().getExtent();
                        map.getView().fit(extent, {
                            size: map.getSize(),
                            duration: 500
                        });
                    } else {
                        alert('没有查询到机构所在行政区!');
                    }
                },
                error: function (data) {
                    alert('没有查询到机构所在行政区!');
                }
            });
        }

二、空间查询:

  function getBoundary( x, y) {
            var data = {
                "service": "wfs",
                "version": "1.1.0",
                "request": "GetFeature",
                "typename": layer,
                "outputformat": "application/json",
                "cql_filter": "CONTAINS(SHAPE,SRID=4326;POINT(" + x + " " + y + "))"
            };
            $.ajax({
                url: url,
                data: data,
                type: "GET",
                contentType: "text/plain;charset=UTF-8",
                success: function (data) {
                    var features = new ol.format.GeoJSON().readFeatures(data);
                }
            });
        }

三、获取图层服务:

  var wmsSource = new ol.source.TileWMS({
                url: url,
                params: {
                    'FORMAT': 'image/png',
                    'VERSION': '1.1.1',
                    tiled: true,
                    "LAYERS": layers,
                    "exceptions": 'application/vnd.ogc.se_inimage',
                },
                serverType: 'geoserver',
                crossOrigin: 'anonymous',
            });

            var wmsLayer = new ol.layer.Tile({
                source: wmsSource,
                zIndex: index//图层显示层级
            });
            map.addLayer(wmsLayer);```

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Vue 项目中使用 ArcGIS API for JavaScript 添加 GeoServer 的 WMTS 服务和 GeoJSON 格式图层的步骤如下: 1. 安装 ArcGIS API for JavaScript: ``` npm install --save @arcgis/core ``` 2. 在 Vue 组件中引入 ArcGIS API for JavaScript: ``` import * as ArcGIS from "@arcgis/core"; ``` 3. 在 Vue 组件中创建地图和视图: ``` <template> <div ref="mapViewNode" style="height: 100vh;"></div> </template> <script> export default { name: "MapView", data() { return { mapView: null } }, mounted() { this.initializeMap(); }, methods: { async initializeMap() { const [Map, MapView] = await ArcGIS.loadModules(["esri/Map", "esri/views/MapView"]); const map = new Map({ basemap: "streets-navigation-vector" }); const mapView = new MapView({ container: this.$refs.mapViewNode, map: map, zoom: 12, center: [-118.805, 34.027] }); this.mapView = mapView; } } }; </script> ``` 4. 在 `initializeMap` 方法中添加 WMTS 服务和 GeoJSON 格式图层: ``` async initializeMap() { const [Map, MapView, WMTSLayer, GeoJSONLayer] = await ArcGIS.loadModules(["esri/Map", "esri/views/MapView", "esri/layers/WMTSLayer", "esri/layers/GeoJSONLayer"]); const map = new Map({ basemap: "streets-navigation-vector" }); const mapView = new MapView({ container: this.$refs.mapViewNode, map: map, zoom: 12, center: [-118.805, 34.027] }); const wmtsLayer = new WMTSLayer({ url: "http://localhost:8080/geoserver/gwc/service/wmts", id: "geoserver-wmts", title: "GeoServer WMTS", activeLayer: { id: "topp:states" } }); map.add(wmtsLayer); const geoJsonLayer = new GeoJSONLayer({ url: "http://localhost:8080/geoserver/topp/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=topp:states&outputFormat=application%2Fjson" }); map.add(geoJsonLayer); this.mapView = mapView; } ``` 注意:在添加 WMTS 服务和 GeoJSON 格式图层时需要确保服务和数据源的坐标系信息一致,否则可能会导致图层位置不正确。同时,GeoJSON 的 URL 需要在后面添加 WFS 参数,以便获取 GeoJSON 格式的数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值