DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. JavaScript
  4. How the JavaScript Heatmap Implementation Works

How the JavaScript Heatmap Implementation Works

Antonio Santiago user avatar by
Antonio Santiago
·
Feb. 05, 15 · Interview
Like (0)
Save
Tweet
Share
15.75K Views

Join the DZone community and get the full member experience.

Join For Free

a heatmap is a powerful way to visualize data. given a matrix of data each value is represented by a color. the implementation of the heatmap algorithm is expensive in computation terms: for each grid’s pixel you need to compute its color from a set of known values. as you could imagine, it is not feasible to implement it on the client side because map rendering would be really slow.

but openlayers3 comes with a handy class, ol.layer.heatmap , which allows rendering vector data as a heatmap. so the question is: how is it made?

really, the ol.layer.heatmap layer uses a smart approximation to the algorithm which produces great results and is really fast. the steps can be summarized as:

  • a gradient of colors is created as a 1×256 pixel size image.
  • each known value is rendered in a canvas as a grey blurred point using some radius. this produces a canvas where the blurred points can overlap each other and create more obscure zones. something similar to this .

  • finally, an image is obtained from the canvas and for each pixels a color is assigned. the color is obtained from the previous 1×256 pixel image obtained the color specified by the grey value (which goes from 0..255).

the colored image is then rendered in the map canvas, obtaining a nice effect suited to be used for density maps. the ol.layer.heatmap offers some properties we can use to play better: blur , radius , gradient , shadow and weight . this last can be configured per feature, allowing to assign a level of importance to each feature determining more or less the final color.

Implementation JavaScript

Published at DZone with permission of Antonio Santiago, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 4 Best dApp Frameworks for First-Time Ethereum Developers
  • How to Use Buildpacks to Build Java Containers
  • Best Practices for Setting up Monitoring Operations for Your AI Team
  • Integrating AWS Secrets Manager With Spring Boot

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: