高德开放平台GeoHUB初用(Vue使用高德地图Loca 2.0)

高德开放平台GeoHUB,高德不声不息出的这玩意挺吊的。

以往地图打点、连线、做特定地市的区域地图,都不知道哪里找GeoJSON数据的,现在有这东西就超级方便了。结合高德地图的api,挺好用的了。这里通过Loca.ScatterLayer的来展示下GeoHUB的简单使用。

在这里插入图片描述

知识

实现

components – map – locaPoint.vue

呼吸点的加载代码主要如下,制作geo地图数据具体过程参考下节GeoHUB制作地图geo数据相关介绍

initBreathPoint() {
  this.breathPoint = new Loca.ScatterLayer({
    loca: this.loca,
    zIndex: 113,
    opacity: 1,
    visible: true,
    zooms: [2, 22]
  })
  // 这里加载geo地图数据
  this.breathPoint.setSource(this.geoLevelF)
  this.breathPoint.setStyle({
    unit: 'meter',
    size: [520, 520],
    borderWidth: 520,
    borderColor: 'rgba(250,250,250,1)',
    duration: 500,
    animate: true,
    texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/breath_yellow.png',
    color: 'rgba(200,200,200,1)'
  })
}

GeoHUB 制作地图geo数据

  • 1、选择绘制点功能,然后就可以在地图上标点。具体位置可以在搜索栏搜索定位。这里随便选了几个地点。

在这里插入图片描述

  • 2、如果对数据有定制要求,可以添加自定义的属性字段。例如类型、颜色、分组…

在这里插入图片描述

  • 3、点击保存后,返回数据集列表。点击下载,得到一个huadu.geojson的文件。

在这里插入图片描述

  • 4、huadu.geojson文件内容如下,标准的geo地图数据格式
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.220125, 23.404326] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.203846, 23.377273] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.254308, 23.416872] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.232409, 23.426934] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.161159, 23.400596] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.166207, 23.385075] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.307605, 23.389929] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.235221, 23.496927] }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": { "type": "Point", "coordinates": [113.155997, 23.483681] }
    }
  ]
}
this.geoLevelF = new Loca.GeoJSONSource({
  url: publicPath + `/data/huadu.geojson`
})
  • 6、设置呼吸点数据,加载到地图上显示
this.breathPoint.setSource(this.geoLevelF)
  • 7、效果

在这里插入图片描述

代码总览

涉及的文件如下(具体参考代码):

|-- public
    |-- data
        |-- huadu.geojson
|-- src
    |-- components
        |-- map
            |-- locaPoint.vue
    |-- views
        |-- amapLocaTest    // 实例所在
            |-- index.vue
            |-- index.scss
            |-- index.js

代码

代码总览的目录去代码里找着看就行了。

总结

以上,只是简单的使用了geohub绘制点功能。还有绘制线、绘制面、自定义属性、上传数据、发布数据服务等功能有兴趣的自行探索了。

代码里面用Vue演示了高德地图Loca 2.0的一些数据可视化效果。除了呼吸点,还有脉冲线连接线,具体看代码了。

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue3中,可以通过以下步骤加载GeoServer瓦片地图: 1. 首先,在Vue项目中安装高德地图2.0和axios: ``` npm install vue-amap axios --save ``` 2. 在main.js中引入高德地图2.0和axios: ``` import VueAMap from 'vue-amap'; import axios from 'axios'; Vue.use(VueAMap); Vue.use(axios); ``` 3. 在Vue组件中引入高德地图组件: ``` <template> <div> <amap :zoom="zoom" :center="center"> <tile-layer :url="url" /> </amap> </div> </template> <script> export default { data() { return { zoom: 10, center: [116.397428, 39.90923], url: 'http://localhost:8080/geoserver/gwc/service/tms/1.0.0/map:village@EPSG:3857@png/{z}/{x}/{y}.png' } } } </script> ``` 在上面的代码中,我们加载了GeoServer瓦片地图,其中url为GeoServer中瓦片地图的地址。 4. 在Vue组件中使用axios从GeoServer中获取瓦片地图的地址,并将其赋值给url: ``` <template> <div> <amap :zoom="zoom" :center="center"> <tile-layer :url="url" /> </amap> </div> </template> <script> import axios from 'axios'; export default { data() { return { zoom: 10, center: [116.397428, 39.90923], url: '' } }, mounted() { axios.get('http://localhost:8080/geoserver/gwc/service/wmts?request=GetTile&version=1.0.0&service=WMTS&layer=map:village&tilematrixset=EPSG:3857&format=image/png&TileMatrix={z}&TileCol={x}&TileRow={y}').then(res => { this.url = res.request.responseURL; }); } } </script> ``` 在上面的代码中,我们通过axios从GeoServer中获取瓦片地图的地址,并将其赋值给url。注意,上面的代码中的url为WMTS的地址,需要根据自己的情况修改。 这样,我们就成功地加载了GeoServer瓦片地图。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值