Leaflet地图数据迁徙 + 飞线效果

Leaflet地图数据迁徙 + 飞线效果

效果

在这里插入图片描述

代码

/**
 * 中心点向外点位辐射分离
 * @author Lou
 * @param { Array } arr 点位数据(一个中心点) 
 * @param { String } color 点位颜色
 * @param { String } centerName 中心点名称
 * @param { String } centerNameProp 中心点对应的属性
 * @param { Number } value 点位数值大小
 * @returns { Array }
 */
export function classifyPointData(arr, color = "rgb(101, 169, 249)", centerName, centerNameProp, value = 6) {
  const { jd: centerJD, wd: centerWD } = arr.find((i) => i[centerNameProp] === centerName);
  return arr.filter((i) => i.name !== centerName).map(({ jd, wd }) => ({
      color,
      from: [centerJD, centerWD],
      to: [jd, wd],
      value,
    }));
}

// 飞线的配置项(可以直接看github上的文档)
migrationOptions = {
  marker: {
    radius: [5, 10],
    pulse: false,
    textVisible: false
  },
  line: {
    width: 1,
    order: false,
    icon: {
      type: 'arrow',
      imgUrl: '',
      size: 10
    },
  },
}

// 地图上的绘制
initPoint() {
  this.markerLayer && this.map.removeLayer(this.markerLayer);
  const migrationData = classifyPointData(this.pointList, "rgb(101, 169, 249)", "分指挥部", "name");
  this.migrationGymLayer = L.migrationLayer(migrationData, migrationOptions);
  this.migrationGymLayer.addTo(this.map);
  let markericon = []
  this.pointList.forEach(item => {
    const myIcon = L.divIcon({
      html: `<div class="marker-box flex flex-col items-center">
              <div class="board-box flex flex-col items-center">
                <div class="board">
                  ${ item.name }
                  ${ item.distance ? `<div>距离分指挥部:${ item.distance }</div>` : '' }
                  <div class="logo">
                    <img src="${ pointLogo }"/>
                  </div>
                </div>
                <img class="line" src="${ pointLine }"/>
              </div>
              ${JSON.parse(item.image).length ? `<img src="${ '/sys/sysFile/download?fileId=' + JSON.parse(item?.image)[0]?.id }"/>` : ''}
              <div class="circle-box">
                <div class="circle1"></div>
                <div class="circle2" style="animation-delay: 0.5s;"></div>
                <div class="circle3" style="animation-delay: 1.5s;></div>
              </div>
              </div>
            `,
      // iconSize: [50 , 70], // icon大小
    });

    const m = L.marker([item.wd, item.jd], { icon: myIcon });
    markericon.push(m);
  })
  this.markerLayer = L.layerGroup(markericon);
  this.map.addLayer(this.markerLayer);
},
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
实现这个功能需要以下步骤: 1. 数据准备:获取候鸟迁徙数据,并将其转换为GeoJSON格式。 2. 服务器搭建:使用Flask框架创建一个Web服务器,用于展示地图数据。 3. 地图展示:使用Leaflet.js库创建一个互动地图,显示候鸟迁徙轨迹。 4. 聚类算法:使用聚类算法对候鸟迁徙数据进行聚类,并将聚类结果显示在地图上。 以下是一个简单的实现步骤: 1. 数据准备: 首先,需要获取候鸟迁徙数据,例如从BirdLife International网站,获取到的候鸟迁徙数据。然后将其转换为GeoJSON格式,以便可以在Leaflet地图上展示。 2. 服务器搭建: 使用Flask框架创建一个Web服务器,以便可以将候鸟迁徙数据地图展示在Web页面上。 以下是一个简单的Flask服务器示例: ```python from flask import Flask, render_template app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') if __name__ == '__main__': app.run(debug=True) ``` 3. 地图展示: 使用Leaflet.js库创建一个互动地图,以便可以展示候鸟迁徙轨迹。以下是一个简单的Leaflet地图示例: ```html <!DOCTYPE html> <html> <head> <title>Leaflet Map</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.min.js"></script> <style> #map { height: 500px; } </style> </head> <body> <div id="map"></div> <script> var map = L.map('map').setView([51.505, -0.09], 13); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(map); </script> </body> </html> ``` 4. 聚类算法: 使用聚类算法对候鸟迁徙数据进行聚类,并将聚类结果展示在地图上。以下是一个简单的聚类算法示例: ```python from sklearn.cluster import KMeans # 假设数据已经转换为GeoJSON格式 data = {...} # 使用KMeans算法对数据进行聚类 kmeans = KMeans(n_clusters=3, random_state=0).fit(data) # 获取聚类结果 labels = kmeans.labels_ # 将聚类结果添加到GeoJSON数据中 for i, feature in enumerate(data['features']): feature['properties']['cluster'] = labels[i] # 将聚类结果显示在地图上 ... ``` 以上是一个简单的实现步骤,具体实现细节需要根据实际情况进行调整和优化。
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值