当前位置: 首页 > news >正文

三十七、openlayers官网示例Earthquakes Heatmap解析——在地图上加载热力图

官网demo地址:

Earthquakes Heatmap 

这篇主要介绍了热力图HeatmapLayer

HeatmapLayer 是一个用于在地图上显示热力图的图层类型,通常用于表示地理数据中的密度或强度。例如,它可以用来显示地震、人口密度或其他空间数据的热点区域。在这个示例中,HeatmapLayer 被用来显示从 KML 文件中提取的地震数据。 

 const vector = new HeatmapLayer({source: new VectorSource({url: "https://openlayers.org/en/latest/examples/data/kml/2012_Earthquakes_Mag5.kml",format: new KML({extractStyles: false,}),}),//热力图的模糊半径,以像素为单位。blur: parseInt(blur.value, 10),//每个点的影响半径,以像素为单位。radius: parseInt(radius.value, 10),//用于根据特征属性计算热力图中每个点的权重 权重值 应介于 0 到 1 之间weight: function (feature) {const name = feature.get("name");const magnitude = parseFloat(name.substr(2));console.log("magnitude", magnitude);return magnitude - 5;},});

通过滑块的改变控制图层的半径和模糊度 

 blur.addEventListener("input", function () {vector.setBlur(parseInt(blur.value, 10));});radius.addEventListener("input", function () {vector.setRadius(parseInt(radius.value, 10));});

 完整代码:

<template><div class="box"><h1>Earthquakes Heatmap</h1><div id="map"></div><form><label for="radius">radius size</label><input id="radius" type="range" min="1" max="50" step="1" value="5" /><label for="blur">blur size</label><input id="blur" type="range" min="1" max="50" step="1" value="15" /></form></div>
</template><script>
import KML from "ol/format/KML.js";
import Map from "ol/Map.js";
import StadiaMaps from "ol/source/StadiaMaps.js";
import VectorSource from "ol/source/Vector.js";
import View from "ol/View.js";
import { Heatmap as HeatmapLayer, Tile as TileLayer } from "ol/layer.js";
export default {name: "",components: {},data() {return {map: null,};},computed: {},created() {},mounted() {const blur = document.getElementById("blur");const radius = document.getElementById("radius");const vector = new HeatmapLayer({source: new VectorSource({url: "https://openlayers.org/en/latest/examples/data/kml/2012_Earthquakes_Mag5.kml",format: new KML({extractStyles: false,}),}),//热力图的模糊半径,以像素为单位。blur: parseInt(blur.value, 10),//每个点的影响半径,以像素为单位。radius: parseInt(radius.value, 10),//用于根据特征属性计算热力图中每个点的权重 权重值 应介于 0 到 1 之间weight: function (feature) {const name = feature.get("name");const magnitude = parseFloat(name.substr(2));console.log("magnitude", magnitude);return magnitude-5;},});const raster = new TileLayer({source: new StadiaMaps({layer: "stamen_toner",}),});new Map({layers: [raster, vector],target: "map",view: new View({center: [0, 0],zoom: 2,}),});blur.addEventListener("input", function () {vector.setBlur(parseInt(blur.value, 10));});radius.addEventListener("input", function () {vector.setRadius(parseInt(radius.value, 10));});},methods: {},
};
</script><style lang="scss" scoped>
#map {width: 100%;height: 500px;
}
.box {height: 100%;
}
</style>

http://www.lryc.cn/news/364258.html

相关文章:

  • curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL
  • Spring Security 注册过滤器关键点与最佳实践
  • 力扣2024.考试的最大困扰度
  • java配置文件解析yml/xml/properties文件
  • grpc接口调用
  • 通信技术振幅键控(ASK)调制与解调硬件实验
  • 自动化办公02 用openpyxl库操作excel.xlsx文件(新版本)
  • 用户反馈解决方案 —— 兔小巢构建反馈功能
  • git 下载失败
  • 力扣1438.绝对差不超过限制的最长连续子数组
  • 如何避免Python中默认参数带来的陷阱
  • 代码随想录算法训练营第五十天|198.打家劫舍、213.打家劫舍II、337.打家劫舍III
  • VB.net 进行CAD二次开发(二)
  • 安徽某高校数据挖掘作业6
  • CMakeLists.txt和Package.xml
  • Debian常用命令详解
  • 代码随想录算法训练营day29|491.递增子序列、46.全排列、47.全排列II
  • 【ARM Cache 与 MMU 系列文章 7.8 – ARMv8/v9 MMU Table 表分配原理及其代码实现 2】
  • SAP PP学习笔记17 - MTS(Make-to-Stock) 按库存生产(策略70)
  • 网页音频提取在线工具有哪些 网页音频提取在线工具下载
  • 【ARM Cache 系列文章 2.1 -- Cache PoP 及 PoDP 介绍】
  • 一文了解JVM面试篇(上)
  • C#WPF控件Textbox绑定浮点型数据限制小数位方法
  • mysql引入表名称的注意事项
  • C语言数据结构快速排序的非递归、归并排序、归并排序的非递归等的介绍
  • 学生成绩管理系统(大一大作业)
  • 数据结构:模拟栈
  • 02-2.3.6 顺序表和链表的比较
  • C++ : 模板初阶
  • FFA-Net:用于单图像去雾的特征融合注意力网络