这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助

做地图开发,往往需要掌握专题地图制作的技能。今天用OpenLayers6来做一个热力图的效果。

页面效果:

代码部分:

<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>热力图</title>
<link rel="stylesheet" href="/css/ol.css">
<script src="/js/ol.js"></script>
<script src="heatmap.js"></script>
<script type="text/javascript">
window.onload = function () {map();}
</script>
<style>
#map{
position: fixed;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<form style="position: absolute;left: 200px;z-index: 999;color: blue;">
<label>半径大小</label>
<input id="radius" type="range" min="1" max="50" step="1" value="20" />
<label>模糊大小</label>
<input id="blur" type="range" min="1" max="50" step="1" value="25" />
</form> <div id="map"></div>
</body>
</html>

JavaScript部分:

/*
* heatmap.js
*/
var map1;
function map(){
map1 = new ol.Map({
target: 'map', //地图容器div的id
loadTilesWhileInteracting: true,
layers: [],
view: new ol.View({
center: [12622513, 2636878], //地图初始中心点
zoom: 9, //地图初始显示级别
}),
controls: ol.control.defaults({}).extend([])
}); // 开始做热力图相关功能
let blur = document.getElementById("blur");
let radius = document.getElementById("radius"); var wandaVector = new ol.source.Vector({
url: "/热力图/wanda.geojson",
format: new ol.format.GeoJSON()
});
//定义热力图图层
let vector = new ol.layer.Heatmap({
source: wandaVector,
blur: parseInt(blur.value, 10),
radius: parseInt(radius.value, 10),
}); // 模糊按钮的回调函数
let blurHandler = function (){
vector.setBlur(parseInt(blur.value, 10));
};
blur.addEventListener("input", blurHandler);
blur.addEventListener("change", blurHandler); // 半径按钮的回调函数
let radiusHandler = function () {
vector.setRadius(parseInt( radius.value, 10));
};
radius.addEventListener("input", radiusHandler);
radius.addEventListener("change", radiusHandler); //添加OSM地图作为底图
var osm = new ol.layer.Tile({
source: new ol.source.OSM()
});
map1.addLayer(osm);
map1.addLayer(vector);
}

数据部分:wanda.geojson

{
"type": "FeatureCollection",
"name": "wanda",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "name": "万达影城(增城万达广场店)", "lng": 113.821841, "lat": 23.281847, "address": "广州市增城区荔城街增城大道69号万达广场F4" }, "geometry": { "type": "Point", "coordinates": [ 113.821841, 23.281847 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(南沙万达广场店)", "lng": 113.538016, "lat": 22.800097, "address": "广州市南沙区双山大道3号万达广场4层" }, "geometry": { "type": "Point", "coordinates": [ 113.538016, 22.800097 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(万胜广场店)", "lng": 113.388917, "lat": 23.103397, "address": "广东省广州市海珠区新港东路1236号万胜广场五层" }, "geometry": { "type": "Point", "coordinates": [ 113.388917, 23.103397 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(融创茂店)", "lng": 113.240693, "lat": 23.431699, "address": "广州市花都区凤凰北路63号融创茂购物中心3楼" }, "geometry": { "type": "Point", "coordinates": [ 113.240693, 23.431699 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(广州番禺万达广场店)", "lng": 113.356523, "lat": 23.012651, "address": "广州市番禺区南村镇汉溪大道东389号番禺万达广场4层" }, "geometry": { "type": "Point", "coordinates": [ 113.356523, 23.012651 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(广州海珠万达广场店)", "lng": 113.320582, "lat": 23.089375, "address": "广州市海珠区广州大道南978号601铺" }, "geometry": { "type": "Point", "coordinates": [ 113.320582, 23.089375 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(白云万达广场店)", "lng": 113.273067, "lat": 23.178271, "address": "广州市白云区云城东路503号万达广场娱乐楼三层" }, "geometry": { "type": "Point", "coordinates": [ 113.273067, 23.178271 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(盈熙广场店)", "lng": 113.293956, "lat": 23.07975, "address": "广州市海珠区江南大道南689-709号盈熙广场2层" }, "geometry": { "type": "Point", "coordinates": [ 113.293956, 23.07975 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(萝岗万达店)", "lng": 113.47294, "lat": 23.174362, "address": "广州市黄埔区开创大道与科丰路交汇处万达广场F4" }, "geometry": { "type": "Point", "coordinates": [ 113.47294, 23.174362 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(万科广场店)", "lng": 113.411133, "lat": 23.172774, "address": "广州市天河区华观路天河万科广场4层" }, "geometry": { "type": "Point", "coordinates": [ 113.411133, 23.172774 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(广州万达影城番禺奥园广场店)", "lng": 113.365178, "lat": 22.929663, "address": "广州市番禺区桥南街福德路281号奥园广场三楼万达影城" }, "geometry": { "type": "Point", "coordinates": [ 113.365178, 22.929663 ] } },
{ "type": "Feature", "properties": { "name": "万达影城(亚运城广场店)", "lng": 113.482628, "lat": 22.94697, "address": "广东省广州市番禺区石楼镇康体路43号亚运城广场3楼" }, "geometry": { "type": "Point", "coordinates": [ 113.482628, 22.94697 ] } },
{ "type": "Feature", "properties": { "name": "广州永和万达电影城(永和里享家店)", "lng": 113.574286, "lat": 23.201214, "address": "广东省广州市黄埔区新业路23号" }, "geometry": { "type": "Point", "coordinates": [ 113.574286, 23.201214 ] } },
{ "type": "Feature", "properties": { "name": "万达国际影城(广州新塘万达广场店)", "lng": 113.624387, "lat": 23.158623, "address": "广州市增城区新塘镇新福路9号新塘万达广场4F万达影城" }, "geometry": { "type": "Point", "coordinates": [ 113.624387, 23.158623 ] } },
{ "type": "Feature", "properties": { "name": "万达影城", "lng": 113.237061, "lat": 23.430949, "address": "广州市花都区蓝楹街融创茂" }, "geometry": { "type": "Point", "coordinates": [ 113.237061, 23.430949 ] } }
]
}

如果对您有所帮助,欢迎您点个关注,我会定时更新技术文档,大家一起讨论学习,一起进步。

OpenLayers绘制热力图 代码记录的更多相关文章

  1. R语言绘图:在地图上绘制热力图

    使用ggplot2在地图上绘制热力图 ######*****绘制热力图代码*****####### interval <- seq(0, 150000, 25000)[-2] #设置价格区间 n ...

  2. MVVM 代码记录

      一.XML <Page x:Class="MVVM.MainPage" xmlns="http://schemas.microsoft.com/winfx/20 ...

  3. OpenLayers绘制图形

    OpenLayers绘制图形   OpenLayers的显示构成由外向内为: ol.Map:地图对象. ol.layer.Vector:图层对象layer.Map含有多个layer,最终的显示效果是由 ...

  4. Echarts基于动态数据初步使用 及问题 代码记录.

    ECHARTS 插件 基本的动态数据展示(横向图) 下载 echarts.commn.min.js文件 在页面中进行引用, 并为Echarts图形准备一个div盒子 <!-- 引入插件 --&g ...

  5. ArcGIS JS 3.x使用webgl绘制热力图

        ArcGIS Js Api 3.x 热力图在数据量达到三万左右的时候,绘制速度不尽人意,数据量再大些,缩放时候就会很卡,非常影响客户体验.     参考了一下网上webgl热力图,能达到更流畅 ...

  6. OpenCV学习代码记录——人脸检测

    很久之前学习过一段时间的OpenCV,当时没有做什么笔记,但是代码都还在,这里把它贴出来做个记录. 代码放在码云上,地址在这里https://gitee.com/solym/OpenCVTest/tr ...

  7. OpenCV学习代码记录—— Snake轮廓

    很久之前学习过一段时间的OpenCV,当时没有做什么笔记,但是代码都还在,这里把它贴出来做个记录. 代码放在码云上,地址在这里https://gitee.com/solym/OpenCVTest/tr ...

  8. OpenCV学习代码记录——Hough线段检测

    很久之前学习过一段时间的OpenCV,当时没有做什么笔记,但是代码都还在,这里把它贴出来做个记录. 代码放在码云上,地址在这里https://gitee.com/solym/OpenCVTest/tr ...

  9. OpenCV学习代码记录——轮廓(contour)检测

    很久之前学习过一段时间的OpenCV,当时没有做什么笔记,但是代码都还在,这里把它贴出来做个记录. 代码放在码云上,地址在这里https://gitee.com/solym/OpenCVTest/tr ...

  10. Leaflet绘制热力图【转】

    http://blog.csdn.net/giser_whu/article/details/51485871 时下用的最多的开源二维webgis引擎应该是openlayers与leaflet了,le ...

随机推荐

  1. 《SagDRE: Sequence-Aware Graph-Based Document-Level Relation Extraction with Adaptive Margin Loss》论文阅读笔记

    代码 原文地址 关键参考文献: Document-Level Relation Extraction with Adaptive Thresholding and Localized Context ...

  2. 线性SVM决策过程的可视化

    线性 SVM 决策过程的可视化 导入模块 from sklearn.datasets import make_blobs from sklearn.svm import SVC import matp ...

  3. 罗克韦尔 FT View使用占位符(全局对象参数)来指定弹出窗口的显示名称

    罗克韦尔 FT View使用占位符(全局对象参数)来指定弹出窗口的显示名称 标签占位符 标签占位符能实现将单个图形显示用于多个相似的操作,从而节省开发和维护应用程序的时间. 例如,要为使用同一台机器将 ...

  4. NC22600 Rinne Loves Dynamic Graph

    题目链接 题目 题目描述 Rinne 学到了一个新的奇妙的东西叫做动态图,这里的动态图的定义是边权可以随着操作而变动的图. 当我们在这个图上经过一条边的时候,这个图上所有边的边权都会发生变动. 定义变 ...

  5. OGP协议的使用

    OGP协议是一套Metatags的规格,用来标注页面,告诉我们你的网页快照.帮助社交app高效并准确的获取网页中的核心链接.标题.主图.正文摘要等信息,使得该网页在社交分享中有更好的展现体验. 如果网 ...

  6. 【Unity3D】地面网格特效

    1 前言 ​ 本文实现了地面网格特效,包含以下两种模式: 实时模式:网格线宽度和间距随相机的高度实时变化: 分段模式:将相机高度分段,网格线宽度和间距在每段中对应一个值. ​ 本文完整资源见→Unit ...

  7. 初级算法 - C++反转链表

    顾名思义, 就是将链表的所有结点反转. 解释见:[剑指offer]反转链表,C++实现(链表) 代码: #include <iostream> struct NodeList { int ...

  8. android:加载PDF几种方法汇总对比

    在安卓项目中,加载PDF文件,是一个比较常见的需求.又分为两大类, 1.加载网络PDF 2.加载一个本地静态PDF. 查阅资料,纵观网上在安卓中打开PDF的各种方式,大致可以分为以下几类, 1.直接使 ...

  9. 如何保证消息顺序执行(Rabbitmq/kafka)

    转载: https://www.cnblogs.com/-wenli/p/13047059.html https://www.jianshu.com/p/02fdcb9e8784

  10. 内建函数iter(),第三个参数哨兵用法

    循环读取文件常见写法 CHUNKSIZE=8192 def reader(s): while True: data = s.recv(CHUNKSIZE) if data == b'': break ...