超图openlayers

这篇博客介绍了如何在地图上加载JSON数据以显示地图边界,使用OpenLayers库创建矢量图层并设置样式。同时,展示了如何进行地图点聚合,通过Cluster源将点聚合为图标,并根据聚合数量设置不同样式。提供了详细的代码示例。
摘要由CSDN通过智能技术生成

地图边界

地图边界json数据取自http://datav.aliyun.com/portal/school/atlas/area_selector#&lat=33.521903996156105&lng=104.29849999999999&zoom=4

import VectorLayer from 'ol/layer/Vector'
import VectorSource from 'ol/source/Vector'
import GeoJSON from 'ol/format/GeoJSON'
import {Circle, Fill, Stroke, Style} from 'ol/style'

let json = require('./json/hefei.json')
let features = (new GeoJSON({ featureProjection: 'EPSG:4326' })).readFeatures(json)
var vectorSource = new VectorSource({ features: features })
let lineLayer = new VectorLayer({
  zIndex: 99,
  source: vectorSource,
  style: new Style({
    stroke: new Stroke({
      color: 'red',
      width: 3
    }),
    fill: new Fill({
       color: 'rgba(0, 0, 255, 0.1)'
    })
  })
})
this.map.addLayer(lineLayer) // 把图层添加到地图

在这里插入图片描述
参考:https://blog.csdn.net/weixin_42776111/article/details/125103005?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-0-125103005-blog-96479717.pc_relevant_blogantidownloadv1&spm=1001.2101.3001.4242.1&utm_relevant_index=2

地图点聚合

let coord
let feature
 let coords = []
 points.forEach(item => {
   coord = [item.lng, item.lat]
   feature = new Feature({
     geometry: new Point(coord)
   })
   coords.push(feature)
 })
 const clusterSource = new Cluster({
   // distance: 10, // 要素将被聚合在一起的像素距离,默认为20
   // minDistance: 20, // 聚合块之间的最小像素距离,默认为零
   source: new VectorSource({
     features: coords
   })
 })
 const clusters = new VectorLayer({
   source: clusterSource,
   name: 'clusterLayer',
   zIndex: 1,
   style: function (feature, resolution) {
     var size = feature.get('features').length
     // 如果是聚合数为1也就是最底层的则是定位图标
     if (size === 1) {
       return new Style({
         image: new Icon({
           src: icon,
           imgSize: [40, 40],
           scale: 0.7 // 缩放倍数
         })
       })
     } else {
       // 这里设置聚合部分的样式
       return new Style({
         image: new Icon({
           anchor: [0.5, 0.4],
           src: require('../../assets/image/point.png')
         }),
         text: new Text({
           text: size.toString(),
           fill: new Fill({
             color: 'white',
             font: '20px'
           })
         })
       })
     }
   }
 })
 this.map.addLayer(clusters)

在这里插入图片描述

参考:
https://www.csdn.net/tags/MtTaggysNjgyOTgtYmxvZwO0O0OO0O0O.html
https://blog.csdn.net/weixin_44727080/article/details/120199240

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值