Heatmap tiles for Google Maps
Visualize your map data in tiles. HeatTiles will show you a heatmap-like representation of your collection of LatLng points, and update it as you zoom in or out. It uses the Mercator Projection and Google's OverlayMapTypes to create and show the tiles.
You can simple download the latest release of HeatTiles from here, or just download one of the following files:
NPM and Bower versions comming soon.
To use HeatTiles, you have to include it to your project using one of the following methods:
<script type="text/javascript" src="path/to/google-heat-tiles.js"></script>
var HeatTiles = require('path/to/google-heat-tiles');
define(['path/to/google-heat-tiles'], function(HeatTiles) {});
And then create a new HeatTiles instance passing your map
object and an optional options
object.
After that you can use the setData()
method with your array of LatLng or LatLngLiteral objects, and call the show()
method to show the tiles in your map.
var mapOptions = {
center: { lat: 37.774546, lng: -122.433523 },
zoom: 14
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var heatTilesOptions = {
opacity: 0.6
};
var data = [
new google.maps.LatLng(37.782551, -122.445368),
new google.maps.LatLng(37.782745, -122.444586)
];
var heatTiles = new HeatTiles(map, heatTilesOptions);
heatTiles.setData(data);
heatTiles.show();
The size in pixels of the tiles on top of your map. Default: 256
Level of opacity of your tiles so they don't cover the map. Default: 0.3
Enable or disable debug mode to show the tile coordinates on your map. Default: false
Recieves an array of LatLng or LatLngLiteral objects and processes the data
var data = [
new google.maps.LatLng(37.782551, -122.445368),
new google.maps.LatLng(37.782745, -122.444586)
];
// or
var data = [
{lat: 37.782551, lng: -122.445368},
{lat: 37.782745, lng: -122.444586}
];
heatTiles.setData(data);
Shows the tiles in your map
heatTiles.setData(data);
heatTiles.show();
Hides the tiles in your map
heatTiles.setData(data);
heatTiles.show();
// ...later...
heatTiles.hide();
Updates your tiles. Useful when you change your data or a HeatTile option such as opacity and want to update your map without having to hide().show();
heatTiles.setData(data);
heatTiles.show();
// ...later...
heatTiles.setData(newData);
heatTiles.update();
Receives the opacity level (between 0 and 1) and updates the options object. You have to call .update()
for the map to chage.
heatTiles.setData(data);
heatTiles.show();
// ...later...
heatTiles.setOpacity(0.88);
heatTiles.update();
- Google Maps JavaScript API
Feel free to fork this repo and add magic to HeatTiles. Just clone it and install its dependencies with:
npm install
You can run the gulp build with:
npm run build
And the Jest unit tests with:
npm test
Thanks for reading (:
By @Charca