前端进阶之---GIS可视化leaflet的使用(四)

98 阅读3分钟

ArcGIS技术总结与开发实践

ArcGIS平台概述

ArcGIS是由Esri开发的地理信息系统(GIS)平台,提供从数据采集、空间分析到可视化呈现的全套解决方案。其核心优势在于:

  • 全球覆盖的地理数据资源
  • 强大的空间分析能力
  • 多平台支持(桌面端、Web端、移动端)
  • 丰富的API和开发工具

学习资源

  1. 官方文档:www.esri.com/zh-cn/home
  2. 示例地图库:livingatlas.arcgis.com/en/browse/
  3. 在线地图查看器:www.arcgis.com/apps/mapvie…

Vue项目集成实践

1. 基础集成方案

依赖安装
npm install leaflet
npm install esri-leaflet
基础实现
<script setup>
    import 'leaflet/dist/leaflet.css'
    import L from 'leaflet'
    import basemapLayer from 'esri-leaflet/src/Layers/BasemapLayer'
</script>

2. 进阶应用

底图组合使用
<template>
  <div class="portal">
    <div class="map-content" id="mapId"></div>
  </div>
</template>
<script setup>
    import 'leaflet/dist/leaflet.css'
    import L from 'leaflet'
    import basemapLayer from 'esri-leaflet/src/Layers/BasemapLayer'
    import { onMounted, reactive, ref, watch } from 'vue'
    
    let map = null
    onMounted(() => {
      initMap()
    })
    const initMap = async () => {
        const myMap = basemapLayer('Imagery')
        map = L.map('mapId', {
            preferCanvas: true,
            attributionControl: false,
            renderer: L.canvas(),
            center: [34.22088, 121.14048],
            zoom: 4,
            layers: [myMap],
            zoomControl: false,
            worldCopyJump: true,
            zoomSnap: 1,
            zoomDelta: 1,
            wheelPxPerZoomLevel: 120,
            crs: L.CRS.EPSG3857,
        })
        L.control.layers(baseLayers).addTo(map)
    }
</script>
<style lang="scss" scoped>
.portal {
  width: 100%;
  height: calc(100vh - 91px);
  box-sizing: border-box;
  position: relative;
}
.map-content {
  width: 100%;
  height: 100%;
}
</style>

然后我们看效果 image.png

通过查看源码可知,basemapLayer内置了20种不同的底图

"Streets", "Topographic", "Oceans", "OceansLabels", "NationalGeographic", "Physical", "Gray", "GrayLabels", "DarkGray", "DarkGrayLabels", "Imagery", "ImageryLabels", "ImageryTransportation", "ImageryClarity", "ImageryFirefly", ShadedRelief", "ShadedReliefLabels", "Terrain", "TerrainLabels" or "USATopo"

我们在尝试一下别的底图

const myMap = basemapLayer('Streets')

image.png

const myMap = basemapLayer('Terrain')

image.png

也可以将两种底图组合使用

const myMap = basemapLayer('Oceans')
const myMapLabel = basemapLayer('OceansLabels')
const arcgisLayer = L.layerGroup([myMap, myMapLabel])
 map = L.map('mapId', {
    preferCanvas: true,
    attributionControl: false,
    renderer: L.canvas(),
    center: [34.22088, 121.14048],
    zoom: 4,
    layers: [arcgisLayer],
    zoomControl: false,
    worldCopyJump: true,
    zoomSnap: 1,
    zoomDelta: 1,
    wheelPxPerZoomLevel: 120,
    crs: L.CRS.EPSG3857,
})

image.png

dynamicMapLayer核心特性

动态地图层(dynamicMapLayer)是ArcGIS平台提供的实时数据可视化方案,与静态basemapLayer相比具有以下优势:

  • 实时数据更新‌:支持动态加载服务器端渲染的地图服务
  • 灵活样式控制‌:可通过参数动态调整图层样式
  • 多层数据叠加‌:支持多个动态图层的叠加显示
  • 按需加载‌:可根据视图范围动态请求数据
基础实现方案
1. 基础配置
const dynamicLayer = L.esri.dynamicMapLayer({
  url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
  opacity: 0.8,
  minZoom: 1,
  maxZoom: 18,
  attribution: 'Esri & Contributors'
});
2. 高级参数配置
const earthquakeLayer = L.esri.dynamicMapLayer({
  url: 'https://services.arcgis.com/v01gqwM5QqNysAAi/arcgis/rest/services/Recent_Earthquakes/FeatureServer/1',
  zoom: true,
  zoomInterval: true,
  minZoom: 1,
  maxZoom: 18,
  layers: [0], // 指定显示的子图层
  opacity: 0.7,
  useCanvas: true,
  tiled: true,
  renderer: {
    type: 'simple',
    symbol: {
      type: 'esriSMS',
      style: 'esriSMSSquare',
      color: [255, 0, 0, 127],
      size: 8
    }
  }
});
性能优化策略
  1. 瓦片缓存机制‌:

    tiled: true,
    tileCacheSize: 50
    
  2. 视图范围限制‌:

    minZoom: 6,
    maxZoom: 15
    
  3. 渲染优化‌:

    preferCanvas: true,
    useCanvas: true
    

常见问题解决方案

  1. 跨域问题‌:

    • 配置代理服务器
    • 使用CORS兼容服务
  2. 数据加载慢‌:

    • 启用tiled参数
    • 设置合理的minZoom/maxZoom
  3. 样式定制‌:

    • 使用renderer参数
    • 通过query设置过滤条件

推荐服务地址

  1. 世界影像图:services.arcgisonline.com/ArcGIS/rest…
  2. 海洋底图:services.arcgisonline.com/ArcGIS/rest…
  3. 矢量底图:basemaps.arcgis.com/arcgis/rest…
  4. 夜光地图:fly.maptiles.arcgis.com/arcgis/rest…
  5. 哨兵影像:sentinel.arcgis.com/arcgis/rest…

通过以上实践,开发者可以充分发挥dynamicMapLayer的实时可视化优势,构建专业级的地理信息应用。