vue+ mapbox 添加geojson图层,点击图层 通过设置filter属性 使某个图层高亮)

1. 初始化地图,引入sprite、glyphs文件

      let sprite = "图标文件";

      let glyphs = "字体文件";

    this.map = new mapboxgl.Map({
        container: "map",
        maxZoom: 24,
        minZoom: 5,
        // style: "mapbox://styles/man135/ckvm2zd0i3cyp15nzy7mrdj4p",
        style: {
          version: 8,
          name: "Mapbox Streets Night",
          sprite: sprite, //图标文件
          glyphs: glyphs, //字体文件
          sources: {},
          layers: [],
        },
        center: [120.60411498091571, 36.225539293687276],
        zoom: 10.8,
        pitch: 10,
        bearing: 0,
      });

2.通过addLayer 添加geoserver服务器上的geojson图层

  本例子 添加两个图层分别是  河流面 以及河流高亮面 图层

this.map.on("load", () => {
         //地图背景
       this.map.addLayer({
        id: "background",
        type: "background",
      minzoom:0,
      maxzoom:24,
        layout: {
          'visibility':'visible'
        },
        paint: {
         'background-color':'#0a1729',
         'background-opacity':1
        },
      });
      
       
        // 河流面
        this.map.addLayer({
          id: "riverPolygon",
          type: "fill",
          source: {
            type: "geojson",
            data: 上传到geoServer服务器上的 对应的图层的geojson 链接地址,
          },
          layout: {},
          paint: {
            "fill-color": "#37BEDB",
            "fill-opacity": 0.4,
            "fill-outline-color": "#41AAB0",
          },
        });
        // 高亮
        this.map.addLayer({
          id: "riverPolygon-highlight",
          type: "fill",
          source: {
            type: "geojson",
            data: 上传到geoServer服务器上的 对应的图层的geojson 链接地址,
          },
          layout: {},
          paint: {
            "fill-color": "#00FFFF",
            "fill-opacity": 1,
            "fill-outline-color": "#00FFFF",
          },
          filter: ["in", "River_Name为geojson图层里的字段 就是你需要过滤的字段", ""],
        });
      });

3.图层点击事件 拿到图层信息 赋值 ,(本例子是点击对应的河流图层 对应的河流就会高亮)

 this.map.on("click", "创建的图层id,例如本例子是:riverPolygon", (e) => {
        // 获取图层中的River_Name
       var name = e.features[0].properties.River_Name;
        // 设置高亮图层的过滤
       this.map.setFilter("riverPolygon-highlight", [
            "in",
            "River_Name",
            name,
          ]);
      });

  • 12
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue 项目中使用 ArcGIS API for JavaScript 添加 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: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS", id: "WorldTimeZones", title: "World Time Zones", activeLayer: { id: "WorldTimeZones" } }); map.add(wmtsLayer); const geoJsonLayer = new GeoJSONLayer({ url: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson" }); map.add(geoJsonLayer); this.mapView = mapView; } ``` 注意:在添加 WMTS 服务和 GeoJSON 格式图层时需要确保服务和数据源的坐标系信息一致,否则可能会导致图层位置不正确。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值