A Pen by Anthony Madhvani on CodePen.
Created
April 11, 2015 11:50
-
-
Save octagonal/ec17e8f0a241588a23a9 to your computer and use it in GitHub Desktop.
YPovJo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=visualization"></script> | |
<div id="panel"> | |
<button onclick="toggleHeatmap()">Toggle Heatmap</button> | |
<button onclick="changeGradient()">Change gradient</button> | |
<button onclick="changeRadius()">Change radius</button> | |
<button onclick="changeOpacity()">Change opacity</button> | |
</div> | |
<div id="map-canvas"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adding 500 Data Points | |
var map, pointarray, heatmap; | |
var taxiData = [ | |
]; | |
function initialize() { | |
$.getJSON( "http://madhvani.me:3000/kot?area=gte.0", function( data ) { | |
$.each( data, function( key, val ) { | |
//console.log(val.latitude + "," + val.longitude); | |
//taxiData.push(new google.maps.LatLng(val.latitude, val.longitude)); | |
//taxiData.push({location: new google.maps.LatLng(val.latitude, val.longitude), weight: val.price}); | |
taxiData.push(new google.maps.LatLng(val.latitude, val.longitude)); | |
//items.push( "<li id='" + key + "'>" + val + "</li>" ); | |
}); | |
}); | |
var mapOptions = { | |
zoom: 10, | |
center: new google.maps.LatLng(50.819582,3.2672855), | |
mapTypeId: google.maps.MapTypeId.SATELLITE | |
}; | |
map = new google.maps.Map(document.getElementById('map-canvas'), | |
mapOptions); | |
var pointArray = new google.maps.MVCArray(taxiData); | |
heatmap = new google.maps.visualization.HeatmapLayer({ | |
data: pointArray, | |
dissipating: true | |
}); | |
heatmap.setMap(map); | |
} | |
function toggleHeatmap() { | |
heatmap.setMap(heatmap.getMap() ? null : map); | |
} | |
function changeGradient() { | |
var gradient = [ | |
'rgba(0, 255, 255, 0)', | |
'rgba(0, 255, 255, 1)', | |
'rgba(0, 191, 255, 1)', | |
'rgba(0, 127, 255, 1)', | |
'rgba(0, 63, 255, 1)', | |
'rgba(0, 0, 255, 1)', | |
'rgba(0, 0, 223, 1)', | |
'rgba(0, 0, 191, 1)', | |
'rgba(0, 0, 159, 1)', | |
'rgba(0, 0, 127, 1)', | |
'rgba(63, 0, 91, 1)', | |
'rgba(127, 0, 63, 1)', | |
'rgba(191, 0, 31, 1)', | |
'rgba(255, 0, 0, 1)' | |
] | |
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient); | |
} | |
function changeRadius() { | |
heatmap.set('radius', heatmap.get('radius') ? null : 20); | |
} | |
function changeOpacity() { | |
heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, body, #map-canvas { | |
height: 100%; | |
margin: 0px; | |
padding: 0px | |
} | |
#panel { | |
position: absolute; | |
top: 5px; | |
left: 50%; | |
margin-left: -180px; | |
z-index: 5; | |
background-color: #fff; | |
padding: 5px; | |
border: 1px solid #999; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment