Comments (4)
source 的对应的数据形式是 名为 vector 的矢量数据。
我们可以通过
let source = new ol.source.Vector({
url, // GeoJSON格式数据资源
format: new ol.format.GeoJSON()
})
创建它。
但是,问题就来了,它提供的数据源,只能通过 geoJson 或者 KML 格式的文件加载
const vector = new HeatmapLayer({
source: new VectorSource({
url: 'data/kml/2012_Earthquakes_Mag5.kml',
format: new KML({
extractStyles: false
})
}),
blur: parseInt(blur.value, 10),
radius: parseInt(radius.value, 10)
});
如上面的官网例子
这在我们实际开发当中很明显是不合理的,因为很多时候我们热力图的点都是由后端接口返回的,而不是直接请求静态资源。那么我们该如何转化后端返回的数据,形成热力图的点呢?
from blog.
首先,补充一下,vector 是可以配置 feature 的。
我们通过生成把坐标点,转化成feature的点。
function createFeature ({type = 'Point', coordinates = [0, 0]}) {
return new ol.Feature({
geometry: new ol.geom[type](coordinates)
})
}
我们就可以通过点数据生成 feature 了。添加到一个空的 vector 里,再把 vector 配置到 heatmap图层内。
完整代码:
// 这里 data 的格式自然是 [[0, 0],[0, 0],[0, 0]] 的坐标集合
createHeatmapLayer ({data, blur = 15, radius = 5}) {
let source = new ol.source.Vector({})
let features = []
for (let i in data) {
let newFeature = createFeature({coordinates: data[i]})
features.push(newFeature)
}
source.addFeatures(features)
let Heatmap = new ol.layer.Heatmap({
source,
blur,
radius
})
return Heatmap
}
以上
from blog.
请问如何设置每个Feature的大小呢
from blog.
@uct8086 通过控制每个点的radius来实现 5大概是5公里好像
from blog.
Related Issues (20)
- 链接失效
- 关于 electron 数据缓存
- 一些关于 VSCode 插件开发的解决方案 HOT 1
- peerDependencies作用
- ELO rating system
- VSCode 插件在 kooltest 自动化测试的开发实践
- 薅一手 Github Actions 自动发包 VSCode 插件
- 八月小结
- [摘]个人效率指南
- 关于 CDN 前端该懂的一切 HOT 1
- 《DDIA》读书笔记
- PostgreSQL 数据迁移
- 九月小结
- 如何在 Sketch 插件中使用 React Typescript HOT 1
- 十月小结
- 从 Node 上传服务说起的爬坑日记
- 八股合集
- 一个说新不算新的服务端渲染技术——流式渲染 HOT 1
- 我来杭州的这两年 HOT 1
- 五月第一周周报
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.