Created
November 20, 2011 10:23
-
-
Save maxott/1380117 to your computer and use it in GitHub Desktop.
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
// Create the map | |
var map = new google.maps.Map(d3.select("#map").node(), { | |
zoom : 11, | |
// center: new google.maps.LatLng(37.3943454817, -122.078649925), | |
center : new google.maps.LatLng(-33.778291, 151.168184), | |
mapTypeId : google.maps.MapTypeId.ROADMAP | |
}); | |
// Load the location data. When the data comes back, create an overlay. | |
d3.json("destinations2.json", function(data) { | |
// Simplistic 95% calculation for max | |
var sdata = _.sortBy(data, function(d) { | |
return d.count; | |
}); | |
var i = Math.round(0.95 * sdata.length); | |
var max = sdata[i].count; | |
var color = d3.scale.log().domain([ 1, max ]).range( | |
[ "rgb(255, 255, 229)", "rgb(35, 139, 69)" ]); | |
// Draw a rectangle for every data record | |
_.each(data, function(d) { | |
var rectangle = new google.maps.Rectangle(); | |
var center = new google.maps.LatLng(d.center[0], d.center[1]); | |
var nw = google.maps.geometry.spherical.computeOffset(center, 500 * Math.sqrt(2), 315); | |
var se = google.maps.geometry.spherical.computeOffset(center, 500 * Math.sqrt(2), 135); | |
var bounds = new google.maps.LatLngBounds(); | |
bounds.extend(se); | |
bounds.extend(nw); | |
var rectOptions = { | |
strokeColor : "#AAAAAA", | |
//strokeColor : "blue", | |
strokeOpacity : 0.8, | |
strokeWeight : 2, | |
fillColor : color(d.count), | |
fillOpacity : 0.35, | |
fillOpacity : 0.60, | |
map : map, | |
bounds : bounds | |
}; | |
rectangle.setOptions(rectOptions); | |
}) | |
}); |
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
[{"x":12749.0,"y":-4209.0,"count":2.0,"center":[-37.8100903085907,144.961257547313]}, | |
{"x":13547.0,"y":-3930.0,"count":5.0,"center":[-35.3037906658972,149.117592639439]}, | |
{"x":13551.0,"y":-3928.0,"count":1.0,"center":[-35.2858243602148,149.128515399598]}, | |
{"x":13553.0,"y":-3927.0,"count":5.0,"center":[-35.2768412073736,149.133980459762]}, | |
{"x":13961.0,"y":-3778.0,"count":3.0,"center":[-33.9383514340355,151.166750778159]}, | |
{"x":13963.0,"y":-3755.0,"count":124.0,"center":[-33.731738918688,150.823387255003]}, | |
{"x":13968.0,"y":-3756.0,"count":3.0,"center":[-33.7407220715292,150.893194126261]}, | |
{"x":13971.0,"y":-3773.0,"count":11.0,"center":[-33.8934356698295,151.195313588677]}, | |
{"x":13972.0,"y":-3772.0,"count":1.0,"center":[-33.8844525169883,151.190212743657]}, | |
{"x":13973.0,"y":-3772.0,"count":2.0,"center":[-33.8844525169883,151.201033686453]}, | |
{"x":13974.0,"y":-3771.0,"count":2.0,"center":[-33.8754693641472,151.195936492494]}, | |
{"x":13976.0,"y":-3770.0,"count":9.0,"center":[-33.866486211306,151.20166275278]}, | |
{"x":13976.0,"y":-3771.0,"count":3.0,"center":[-33.8754693641472,151.217576099835]}, | |
{"x":13977.0,"y":-3771.0,"count":2.0,"center":[-33.8754693641472,151.228395903505]}, | |
{"x":13978.0,"y":-3769.0,"count":1.0,"center":[-33.8575030584648,151.207391524537]}, | |
{"x":13979.0,"y":-3772.0,"count":186.0,"center":[-33.8844525169883,151.265959343228]}, | |
{"x":13980.0,"y":-3767.0,"count":3.0,"center":[-33.8395367527824,151.197226098097]}, | |
{"x":13981.0,"y":-3767.0,"count":4.0,"center":[-33.8395367527824,151.208041350322]}, | |
{"x":13982.0,"y":-3767.0,"count":4.0,"center":[-33.8395367527824,151.218856602546]}, | |
{"x":13986.0,"y":-3760.0,"count":7.0,"center":[-33.776654682894,151.150990423843]}, | |
{"x":13986.0,"y":-3761.0,"count":1.0,"center":[-33.7856378357352,151.166844592526]}, | |
{"x":13986.0,"y":-3762.0,"count":3.0,"center":[-33.7946209885764,151.182705804154]}, | |
{"x":13987.0,"y":-3760.0,"count":3.0,"center":[-33.776654682894,151.161797730465]}, | |
{"x":13987.0,"y":-3761.0,"count":3.0,"center":[-33.7856378357352,151.177653032722]}, | |
{"x":13987.0,"y":-3762.0,"count":2.0,"center":[-33.7946209885764,151.193515378428]}, | |
{"x":13988.0,"y":-3760.0,"count":2.0,"center":[-33.776654682894,151.172605037088]}, | |
{"x":13989.0,"y":-3760.0,"count":1.0,"center":[-33.776654682894,151.18341234371]}, | |
{"x":13990.0,"y":-3758.0,"count":3.0,"center":[-33.7586883772116,151.16252336727]}, | |
{"x":13997.0,"y":-3761.0,"count":9.0,"center":[-33.7856378357352,151.28573743469]}, | |
{"x":13998.0,"y":-3752.0,"count":2.0,"center":[-33.7047894601644,151.153989335012]}, | |
{"x":13999.0,"y":-3752.0,"count":5.0,"center":[-33.7047894601644,151.164787591144]}, | |
{"x":14004.0,"y":-3752.0,"count":4.0,"center":[-33.7047894601644,151.218778871803]}] |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=true"></script> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.29.1"></script> | |
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script> | |
<style type="text/css"> | |
html, body, #map { | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script type="text/javascript" src="density.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment