区块链技术博客
www.b2bchain.cn

cesium之基于HeatmapJS的热力图求职学习资料

本文介绍了cesium之基于HeatmapJS的热力图求职学习资料,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

热力图(Heat Map)是通过密度函数进行可视化,用于表示地图中点的密度的热图。它使人们能够独立于缩放因子感知点的密度。一般是基于离散点、线或面的分析与表达,或者基于连续表面的密度分析得到的热力图或热度图。强调空间位置和基本的空间分布特征。

Heatmap.js 这个库可以实现各种动态热力图,帮助您研究和可视化用户的行为。

效果图:

cesium之基于HeatmapJS的热力图

效果图

实现方式

基于cesium ImageryProvider接口实现热力图

“`js
import {Cartesian2, Cartesian3, Cartographic, defaultValue, defined, DeveloperError, WebMercatorProjection, WebMercatorTilingScheme} from ‘cesium’
import HeatmapJS from ‘heatmap.js’

export default class HeatmapImageryProvider {
constructor(options) {
options = defaultValue(options, {});
const data = options.data;

if (!defined(data)) {   throw new DeveloperError('data is required.'); } this._options = defaultValue(options.heatmap, {   xField: "x",   yField: "y",   valueField: 'value' }); this._min = 99999 this._max = -99999 let bounds = {   west: 180,   east: -180,   south: 90,   north: -90 }  // 计算数据经纬度范围、最大值最小值 data.points.forEach(point => {   point[this._options.valueField] > this._max && (this._max = point[this._options.valueField])   point[this._options.valueField] < this._min && (this._min = point[this._options.valueField])   point[this._options.xField] > bounds.east && (bounds.east = point[this._options.xField])   point[this._options.xField] < bounds.west && (bounds.west = point[this._options.xField])   point[this._options.yField] < bounds.south && (bounds.south = point[this._options.yField])   point[this._options.yField] > bounds.north && (bounds.north = point[this._options.yField]) })  this._wmp = new WebMercatorProjection(); this._mbounds = this.wgs84ToMercatorBB(bounds); // 热力图色带 this._options.gradient = defaultValue(this._options.gradient, {   0.25: "rgb(0,0,255)",   0.55: "rgb(0,255,0)",   0.85: "yellow",   1.0: "rgb(255,0,0)" });  this._setWidthAndHeight(this._mbounds); this._options.radius = Math.round(defaultValue(this._options.radius, ((this.width > this.height) ? this.width / 60 : this.height / 60)));  this._spacing = this._options.radius * 1.5; this._xoffset = this._mbounds.west; this._yoffset = this._mbounds.south;  this.width = Math.round(this.width + this._spacing * 2); this.height = Math.round(this.height + this._spacing * 2);  this._mbounds.west -= this._spacing * this._factor; this._mbounds.east += this._spacing * this._factor; this._mbounds.south -= this._spacing * this._factor; this._mbounds.north += this._spacing * this._factor;  this.bounds = this.mercatorToWgs84BB(this._mbounds);  this._container = this._getContainer(this.width, this.height); this._options.container = this._container;  this._heatmap = HeatmapJS.create(this._options); this._canvas = this._container.children[0];  this._tilingScheme = new WebMercatorTilingScheme({   rectangleSouthwestInMeters: new Cartesian2(this._mbounds.west, this._mbounds.south),   rectangleNortheastInMeters: new Cartesian2(this._mbounds.east, this._mbounds.north) });  this._image = this._canvas; this._texture = undefined; this._tileWidth = this.width; this._tileHeight = this.height; this._ready = false;  if (options.data) {   this._ready = this.setWGS84Data(this._min, this._max, options.data.points); }

}

_setWidthAndHeight(mbb) {
var maxCanvasSize = 2000;
var minCanvasSize = 700;
this.width = ((mbb.east > 0 && mbb.west < 0) ? mbb.east + Math.abs(mbb.west) : Math.abs(mbb.east – mbb.west)); this.height = ((mbb.north > 0 && mbb.south < 0) ? mbb.north + Math.abs(mbb.south) : Math.abs(mbb.north – mbb.south));
this._factor = 1;

if (this.width > this.height && this.width > maxCanvasSize) {   this._factor = this.width / maxCanvasSize;    if (this.height / this._factor < minCanvasSize) {     this._factor = this.height / minCanvasSize;   } } else if (this.height > this.width && this.height > maxCanvasSize) {   this._factor = this.height / maxCanvasSize;    if (this.width / this._factor < minCanvasSize) {     this._factor = this.width / minCanvasSize;   } } else if (this.width < this.height && this.width < minCanvasSize) {   this._factor = this.width / minCanvasSize;    if (this.height / this._factor > maxCanvasSize) {     this._factor = this.height / maxCanvasSize;   } } else if (this.height < this.width && this.height < minCanvasSize) {   this._factor = this.height / minCanvasSize;    if (this.width / this._factor > maxCanvasSize) {     this._factor = this.width / maxCanvasSize;   } }  this.width = this.width / this._factor; this.height = this.height / this._factor;

}

_getContainer(width, height, id) {
var c = document.createElement(“div”);
if (id) {
c.setAttribute(“id”, id);
}
c.setAttribute(“style”, “width: ” + width + “px; height: ” + height + “px; margin: 0px; display: none;”);
document.body.appendChild(c);
return c;
}

wgs84ToMercator(point) {
return this._wmp.project(Cartographic.fromDegrees(point[this._options.xField], point[this._options.yField]));
};

wgs84ToMercatorBB(bounds) {
var ne = this._wmp.project(Cartographic.fromDegrees(bounds.east, bounds.north));
var sw = this._wmp.project(Cartographic.fromDegrees(bounds.west, bounds.south));
return {
north: ne.y,
south: sw.y,
east: ne.x,
west: sw.x

热力图(Heat Map)是通过密度函数进行可视化,用于表示地图中点的密度的热图。它使人们能够独立于缩放因子感知点的密度。一般是基于离散点、线或面的分析与表达,或者基于连续表面的密度分析得到的热力图或热度图。强调空间位置和基本的空间分布特征。

Heatmap.js 这个库可以实现各种动态热力图,帮助您研究和可视化用户的行为。

效果图:

cesium之基于HeatmapJS的热力图

效果图

实现方式

基于cesium ImageryProvider接口实现热力图

“`js
import {Cartesian2, Cartesian3, Cartographic, defaultValue, defined, DeveloperError, WebMercatorProjection, WebMercatorTilingScheme} from ‘cesium’
import HeatmapJS from ‘heatmap.js’

export default class HeatmapImageryProvider {
constructor(options) {
options = defaultValue(options, {});
const data = options.data;

if (!defined(data)) {   throw new DeveloperError('data is required.'); } this._options = defaultValue(options.heatmap, {   xField: "x",   yField: "y",   valueField: 'value' }); this._min = 99999 this._max = -99999 let bounds = {   west: 180,   east: -180,   south: 90,   north: -90 }  // 计算数据经纬度范围、最大值最小值 data.points.forEach(point => {   point[this._options.valueField] > this._max && (this._max = point[this._options.valueField])   point[this._options.valueField] < this._min && (this._min = point[this._options.valueField])   point[this._options.xField] > bounds.east && (bounds.east = point[this._options.xField])   point[this._options.xField] < bounds.west && (bounds.west = point[this._options.xField])   point[this._options.yField] < bounds.south && (bounds.south = point[this._options.yField])   point[this._options.yField] > bounds.north && (bounds.north = point[this._options.yField]) })  this._wmp = new WebMercatorProjection(); this._mbounds = this.wgs84ToMercatorBB(bounds); // 热力图色带 this._options.gradient = defaultValue(this._options.gradient, {   0.25: "rgb(0,0,255)",   0.55: "rgb(0,255,0)",   0.85: "yellow",   1.0: "rgb(255,0,0)" });  this._setWidthAndHeight(this._mbounds); this._options.radius = Math.round(defaultValue(this._options.radius, ((this.width > this.height) ? this.width / 60 : this.height / 60)));  this._spacing = this._options.radius * 1.5; this._xoffset = this._mbounds.west; this._yoffset = this._mbounds.south;  this.width = Math.round(this.width + this._spacing * 2); this.height = Math.round(this.height + this._spacing * 2);  this._mbounds.west -= this._spacing * this._factor; this._mbounds.east += this._spacing * this._factor; this._mbounds.south -= this._spacing * this._factor; this._mbounds.north += this._spacing * this._factor;  this.bounds = this.mercatorToWgs84BB(this._mbounds);  this._container = this._getContainer(this.width, this.height); this._options.container = this._container;  this._heatmap = HeatmapJS.create(this._options); this._canvas = this._container.children[0];  this._tilingScheme = new WebMercatorTilingScheme({   rectangleSouthwestInMeters: new Cartesian2(this._mbounds.west, this._mbounds.south),   rectangleNortheastInMeters: new Cartesian2(this._mbounds.east, this._mbounds.north) });  this._image = this._canvas; this._texture = undefined; this._tileWidth = this.width; this._tileHeight = this.height; this._ready = false;  if (options.data) {   this._ready = this.setWGS84Data(this._min, this._max, options.data.points); }

}

_setWidthAndHeight(mbb) {
var maxCanvasSize = 2000;
var minCanvasSize = 700;
this.width = ((mbb.east > 0 && mbb.west < 0) ? mbb.east + Math.abs(mbb.west) : Math.abs(mbb.east – mbb.west)); this.height = ((mbb.north > 0 && mbb.south < 0) ? mbb.north + Math.abs(mbb.south) : Math.abs(mbb.north – mbb.south));
this._factor = 1;

if (this.width > this.height && this.width > maxCanvasSize) {   this._factor = this.width / maxCanvasSize;    if (this.height / this._factor < minCanvasSize) {     this._factor = this.height / minCanvasSize;   } } else if (this.height > this.width && this.height > maxCanvasSize) {   this._factor = this.height / maxCanvasSize;    if (this.width / this._factor < minCanvasSize) {     this._factor = this.width / minCanvasSize;   } } else if (this.width < this.height && this.width < minCanvasSize) {   this._factor = this.width / minCanvasSize;    if (this.height / this._factor > maxCanvasSize) {     this._factor = this.height / maxCanvasSize;   } } else if (this.height < this.width && this.height < minCanvasSize) {   this._factor = this.height / minCanvasSize;    if (this.width / this._factor > maxCanvasSize) {     this._factor = this.width / maxCanvasSize;   } }  this.width = this.width / this._factor; this.height = this.height / this._factor;

}

_getContainer(width, height, id) {
var c = document.createElement(“div”);
if (id) {
c.setAttribute(“id”, id);
}
c.setAttribute(“style”, “width: ” + width + “px; height: ” + height + “px; margin: 0px; display: none;”);
document.body.appendChild(c);
return c;
}

wgs84ToMercator(point) {
return this._wmp.project(Cartographic.fromDegrees(point[this._options.xField], point[this._options.yField]));
};

wgs84ToMercatorBB(bounds) {
var ne = this._wmp.project(Cartographic.fromDegrees(bounds.east, bounds.north));
var sw = this._wmp.project(Cartographic.fromDegrees(bounds.west, bounds.south));
return {
north: ne.y,
south: sw.y,
east: ne.x,
west: sw.x

热力图(Heat Map)是通过密度函数进行可视化,用于表示地图中点的密度的热图。它使人们能够独立于缩放因子感知点的密度。一般是基于离散点、线或面的分析与表达,或者基于连续表面的密度分析得到的热力图或热度图。强调空间位置和基本的空间分布特征。

Heatmap.js 这个库可以实现各种动态热力图,帮助您研究和可视化用户的行为。

效果图:

cesium之基于HeatmapJS的热力图

效果图

实现方式

基于cesium ImageryProvider接口实现热力图

“`js
import {Cartesian2, Cartesian3, Cartographic, defaultValue, defined, DeveloperError, WebMercatorProjection, WebMercatorTilingScheme} from ‘cesium’
import HeatmapJS from ‘heatmap.js’

export default class HeatmapImageryProvider {
constructor(options) {
options = defaultValue(options, {});
const data = options.data;

if (!defined(data)) {   throw new DeveloperError('data is required.'); } this._options = defaultValue(options.heatmap, {   xField: "x",   yField: "y",   valueField: 'value' }); this._min = 99999 this._max = -99999 let bounds = {   west: 180,   east: -180,   south: 90,   north: -90 }  // 计算数据经纬度范围、最大值最小值 data.points.forEach(point => {   point[this._options.valueField] > this._max && (this._max = point[this._options.valueField])   point[this._options.valueField] < this._min && (this._min = point[this._options.valueField])   point[this._options.xField] > bounds.east && (bounds.east = point[this._options.xField])   point[this._options.xField] < bounds.west && (bounds.west = point[this._options.xField])   point[this._options.yField] < bounds.south && (bounds.south = point[this._options.yField])   point[this._options.yField] > bounds.north && (bounds.north = point[this._options.yField]) })  this._wmp = new WebMercatorProjection(); this._mbounds = this.wgs84ToMercatorBB(bounds); // 热力图色带 this._options.gradient = defaultValue(this._options.gradient, {   0.25: "rgb(0,0,255)",   0.55: "rgb(0,255,0)",   0.85: "yellow",   1.0: "rgb(255,0,0)" });  this._setWidthAndHeight(this._mbounds); this._options.radius = Math.round(defaultValue(this._options.radius, ((this.width > this.height) ? this.width / 60 : this.height / 60)));  this._spacing = this._options.radius * 1.5; this._xoffset = this._mbounds.west; this._yoffset = this._mbounds.south;  this.width = Math.round(this.width + this._spacing * 2); this.height = Math.round(this.height + this._spacing * 2);  this._mbounds.west -= this._spacing * this._factor; this._mbounds.east += this._spacing * this._factor; this._mbounds.south -= this._spacing * this._factor; this._mbounds.north += this._spacing * this._factor;  this.bounds = this.mercatorToWgs84BB(this._mbounds);  this._container = this._getContainer(this.width, this.height); this._options.container = this._container;  this._heatmap = HeatmapJS.create(this._options); this._canvas = this._container.children[0];  this._tilingScheme = new WebMercatorTilingScheme({   rectangleSouthwestInMeters: new Cartesian2(this._mbounds.west, this._mbounds.south),   rectangleNortheastInMeters: new Cartesian2(this._mbounds.east, this._mbounds.north) });  this._image = this._canvas; this._texture = undefined; this._tileWidth = this.width; this._tileHeight = this.height; this._ready = false;  if (options.data) {   this._ready = this.setWGS84Data(this._min, this._max, options.data.points); }

}

_setWidthAndHeight(mbb) {
var maxCanvasSize = 2000;
var minCanvasSize = 700;
this.width = ((mbb.east > 0 && mbb.west < 0) ? mbb.east + Math.abs(mbb.west) : Math.abs(mbb.east – mbb.west)); this.height = ((mbb.north > 0 && mbb.south < 0) ? mbb.north + Math.abs(mbb.south) : Math.abs(mbb.north – mbb.south));
this._factor = 1;

if (this.width > this.height && this.width > maxCanvasSize) {   this._factor = this.width / maxCanvasSize;    if (this.height / this._factor < minCanvasSize) {     this._factor = this.height / minCanvasSize;   } } else if (this.height > this.width && this.height > maxCanvasSize) {   this._factor = this.height / maxCanvasSize;    if (this.width / this._factor < minCanvasSize) {     this._factor = this.width / minCanvasSize;   } } else if (this.width < this.height && this.width < minCanvasSize) {   this._factor = this.width / minCanvasSize;    if (this.height / this._factor > maxCanvasSize) {     this._factor = this.height / maxCanvasSize;   } } else if (this.height < this.width && this.height < minCanvasSize) {   this._factor = this.height / minCanvasSize;    if (this.width / this._factor > maxCanvasSize) {     this._factor = this.width / maxCanvasSize;   } }  this.width = this.width / this._factor; this.height = this.height / this._factor;

}

_getContainer(width, height, id) {
var c = document.createElement(“div”);
if (id) {
c.setAttribute(“id”, id);
}
c.setAttribute(“style”, “width: ” + width + “px; height: ” + height + “px; margin: 0px; display: none;”);
document.body.appendChild(c);
return c;
}

wgs84ToMercator(point) {
return this._wmp.project(Cartographic.fromDegrees(point[this._options.xField], point[this._options.yField]));
};

wgs84ToMercatorBB(bounds) {
var ne = this._wmp.project(Cartographic.fromDegrees(bounds.east, bounds.north));
var sw = this._wmp.project(Cartographic.fromDegrees(bounds.west, bounds.south));
return {
north: ne.y,
south: sw.y,
east: ne.x,
west: sw.x

部分转自互联网,侵权删除联系

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » cesium之基于HeatmapJS的热力图求职学习资料
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们