Skip to content

Instantly share code, notes, and snippets.

@awoodruff
Last active June 1, 2018 20:05
Show Gist options
  • Save awoodruff/9216081 to your computer and use it in GitHub Desktop.
Save awoodruff/9216081 to your computer and use it in GitHub Desktop.
Projection face!
Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 5 }, "geometry": { "type": "LineString", "coordinates": [ [ -44.501023116211492, 14.664054242728627 ], [ -43.846729203163086, 14.991522877448357 ], [ -42.504676875835557, 14.255482807121819 ], [ -40.847290110080955, 13.382947692850754 ], [ -38.465736016867723, 12.245511054654894 ], [ -36.455823935432555, 11.377689789399907 ], [ -35.81814995177951, 11.08130607224725 ], [ -33.956028964698149, 10.237741382316498 ], [ -32.788064683408209, 10.116964260564677 ], [ -31.55421226164211, 9.928031501398802 ], [ -33.903905844338688, 9.056570669499441 ], [ -35.194091879410522, 8.420001721818185 ], [ -36.392587557069007, 8.221979923449496 ], [ -37.367423492735128, 8.168565740750205 ], [ -38.501544948084614, 8.176471551487154 ], [ -39.433206391170749, 8.199291770855904 ], [ -40.523567205263369, 8.425285328479182 ], [ -41.694671059462721, 8.510529961147759 ], [ -42.535207843398076, 8.397272811822081 ], [ -43.56951728751352, 9.092798133515412 ], [ -44.393229095585617, 9.685016845180776 ], [ -44.889371173544575, 10.613348391522422 ], [ -45.216940903657722, 11.3386853869516 ], [ -45.239683164848401, 12.084685261677516 ], [ -45.171456381276421, 13.02639206739547 ], [ -44.946963613134798, 13.963625248231612 ], [ -44.501023116211492, 14.664054242728627 ] ] } },
{ "type": "Feature", "properties": { "id": 4 }, "geometry": { "type": "LineString", "coordinates": [ [ -31.024131031341273, 9.848720012739228 ], [ -32.774214337969916, 10.096738201276985 ], [ -33.978771225888799, 10.231893336571327 ], [ -35.830875192748955, 11.069228117517843 ], [ -38.4671237306273, 12.262190074908789 ], [ -40.813640158354488, 13.354848980211171 ], [ -42.480053781829255, 14.258107970403849 ], [ -43.830589851146598, 14.990149420982849 ], [ -45.324920180770356, 16.074332064338421 ], [ -46.512322911406237, 16.935829288687078 ], [ -45.040920099459903, 17.204014693096351 ], [ -43.683228593466801, 17.345598769510666 ], [ -41.813372770624433, 17.296200927526112 ], [ -40.341969958678057, 17.067124135187196 ], [ -38.382071971192047, 16.525139475195722 ], [ -36.385120145749937, 15.403510211422493 ], [ -34.444524140237817, 13.682853840324237 ], [ -31.024131031341273, 9.848720012739228 ] ] } },
{ "type": "Feature", "properties": { "id": 2 }, "geometry": { "type": "LineString", "coordinates": [ [ -44.836239748743978, 6.713931881137064 ], [ -43.596972764662098, 7.820895341193799 ], [ -42.489723321016754, 8.386426113814053 ], [ -41.598211679945152, 8.477004209423527 ], [ -40.478423525822009, 8.386426113814053 ], [ -39.381063811369394, 8.207993078085407 ], [ -38.444381469436642, 8.120457961848798 ], [ -37.367612490011844, 8.129933419239579 ], [ -36.364854890669918, 8.211113813413725 ], [ -35.183184188874684, 8.431717851136439 ], [ -33.834996117762095, 9.058731265788705 ], [ -31.596751086197152, 9.905628364700195 ], [ -31.024131031341273, 9.843673439859407 ], [ -31.253168451930303, 9.32373475276755 ], [ -31.76279107997814, 8.720098625170042 ], [ -33.103657610107987, 8.052463119288092 ], [ -34.109307507705331, 7.718220884104523 ], [ -35.114957405302704, 7.38371069962174 ], [ -36.281033213116906, 7.152458755392092 ], [ -37.461473833029928, 7.048943904166737 ], [ -39.137556995692194, 7.048943904166737 ], [ -40.412875539685899, 7.230887783660167 ], [ -41.506815684610039, 7.451809786395208 ], [ -42.574775080452007, 7.604775538245357 ], [ -43.365534772253604, 7.448289254426879 ], [ -44.836239748743978, 6.713931881137064 ] ] } },
{ "type": "Feature", "properties": { "id": 2 }, "geometry": { "type": "LineString", "coordinates": [ [ -50.892881395518828, 16.59120674649586 ], [ -50.15497125587779, 18.528332537570265 ], [ -49.347334514673094, 19.896239661891361 ], [ -48.469846728946102, 20.878590702654815 ], [ -46.847539543938687, 22.020516035983672 ], [ -44.732577105209508, 23.132751088534263 ], [ -43.648651761621338, 23.558931637664834 ], [ -42.308712111610475, 23.961189378334861 ], [ -41.281327644121681, 24.146858260167562 ], [ -40.149124178616972, 24.128313028773871 ], [ -38.353412424674005, 23.658291877848821 ], [ -36.824690519691508, 22.976089155969785 ], [ -35.114957405302704, 22.020516035983672 ], [ -33.774090875172881, 20.764770159853967 ], [ -32.609245149240905, 19.541510196791808 ], [ -31.160584598485219, 17.87946446896251 ], [ -30.421924549848324, 16.289408366270901 ], [ -32.137574949564524, 17.504112321633293 ], [ -33.484337238200816, 18.719097085098063 ], [ -34.887534793396128, 19.772882649585156 ], [ -36.455823935432555, 20.449149585833357 ], [ -38.37615468586467, 20.935779868575409 ], [ -39.960191351436919, 21.15926308943914 ], [ -41.512732969937453, 21.255999230686871 ], [ -43.251125630844307, 21.021244641149085 ], [ -45.506673013808864, 20.449149585833357 ], [ -47.052219894654613, 19.837474631270574 ], [ -48.523622706600982, 18.861356095254855 ], [ -50.892881395518828, 16.59120674649586 ] ] } },
{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.082789010605239, 75.04242636600496 ], [ 4.828280442870797, 75.02982194221255 ], [ 9.788647679236238, 74.819030121534098 ], [ 14.082361340414813, 74.590480733411439 ], [ 18.404292389803302, 74.278271863450243 ], [ 22.810510338199773, 73.938116882093581 ], [ 26.467801418258983, 73.559901489012219 ], [ 30.404936003517111, 73.072769029902659 ], [ 34.043971155946458, 72.602201901951162 ], [ 37.853419731859987, 71.937321335341721 ], [ 42.75592101659258, 70.916103503333787 ], [ 47.958003832111096, 69.367177374349041 ], [ 53.084390790275258, 67.357027078892884 ], [ 56.644482232650319, 65.74922102632766 ], [ 60.01827270101478, 64.008617847593058 ], [ 63.654234509517792, 62.021763797967125 ], [ 67.378829496950971, 59.357928994980504 ], [ 70.560595432568093, 56.184928153320406 ], [ 72.104055167900711, 52.332623897602481 ], [ 72.489581637615871, 47.352607798342078 ], [ 72.489581637615871, 41.09421655680115 ], [ 72.489581637615871, 36.371105808190997 ], [ 71.97554634466232, 31.229918982619655 ], [ 71.083002704882119, 27.429572501345273 ], [ 69.137415312291267, 22.020516035983672 ], [ 67.305466947422602, 16.872012193549754 ], [ 65.114815721901778, 10.715410583857871 ], [ 62.510931017181314, 5.667383006007405 ], [ 59.751349601382515, 0.31751361086118 ], [ 57.463462262099526, -4.418411319197091 ], [ 54.723100113395652, -10.090958736459376 ], [ 53.717450215798287, -14.049111467927364 ], [ 53.382233583265801, -18.579738151293487 ], [ 53.382233583265801, -25.14610500219273 ], [ 54.052666848330766, -30.216624344655425 ], [ 55.058316745928138, -34.205064216715343 ], [ 58.745699703785135, -40.615277695552749 ], [ 63.103515926707047, -45.76144558267206 ], [ 66.455682252031636, -49.16948119897085 ], [ 71.819148372550913, -53.968382552026171 ], [ 78.523481023200091, -57.556330964354231 ], [ 85.227813673849198, -60.159965201223301 ], [ 96.129175818440558, -64.593106941400009 ], [ 102.50479894004765, -67.193119183180031 ], [ 110.019600887918557, -70.081628249036612 ], [ -42.466292626462966, -69.979433596315502 ], [ -44.948316067869804, -64.392020002599565 ], [ -47.050096482415789, -62.016745861484573 ], [ -49.529272604198354, -60.326615095525071 ], [ -55.083583419728875, -58.812772408506042 ], [ -59.250554947639593, -57.375700572627103 ], [ -62.438369861243174, -56.147485014535896 ], [ -64.742529891397268, -55.092649646194715 ], [ -66.960537495886086, -53.571206621946516 ], [ -68.636620658548381, -51.528245273038287 ], [ -68.971837291080817, -50.040859092789304 ], [ -68.971837291080817, -47.606743909469039 ], [ -67.217555142362841, -45.073903177239316 ], [ -64.949237700691342, -42.874341119618649 ], [ -61.932288007899253, -40.102410110684076 ], [ -60.363613390909734, -38.738585321672559 ], [ -58.915338315107142, -37.479437357974987 ], [ -58.24490505004222, -34.483111773184987 ], [ -58.24490505004222, -31.661288390091386 ], [ -59.585771580172029, -30.797133792774936 ], [ -60.694993942422649, -30.194112378838696 ], [ -61.301641718412178, -29.581764312673378 ], [ -61.539327591405737, -28.848438943650898 ], [ -61.345005116802241, -28.006388078121834 ], [ -60.926638110301894, -27.262698923238045 ], [ -60.336093070904845, -26.48350500789622 ], [ -59.664386276280332, -26.08650959169082 ], [ -59.146478733423301, -26.049010811112574 ], [ -58.580121682574671, -26.057973988870057 ], [ -53.216655562055358, -26.962725940645729 ], [ -57.239255152444848, -25.450841330931766 ], [ -58.608218159053898, -25.043738749427199 ], [ -59.323722593144346, -24.840569542035237 ], [ -59.712045993190571, -24.444111424897429 ], [ -59.918661933175798, -23.871758737143988 ], [ -59.973398010110074, -22.991746885191677 ], [ -59.585771580172029, -21.116937868170705 ], [ -59.187651785671363, -20.066338471423887 ], [ -58.86292851770159, -19.367132078860276 ], [ -58.066917809726384, -18.234725271733708 ], [ -57.360266621358583, -17.38090886540191 ], [ -56.904038519912405, -16.651124130041023 ], [ -59.585771580172029, -15.577649229247616 ], [ -61.417892519381802, -14.58575789352474 ], [ -63.226191791227087, -13.496258472211252 ], [ -64.681634415397198, -12.789885326651536 ], [ -65.409755043749243, -12.449972558135853 ], [ -65.924325472805265, -12.004372568143655 ], [ -66.308823600876224, -11.362629148813339 ], [ -66.468922891242244, -10.550257093622736 ], [ -66.486483288690323, -9.577471301454691 ], [ -66.290104230821186, -8.503438210537643 ], [ -64.072096626332353, -4.53170164475555 ], [ -61.647381212549469, -1.707083685996805 ], [ -59.444485546047417, 1.036151318533947 ], [ -57.90968841750977, 3.352856815330158 ], [ -55.741990650203626, 6.043217899774788 ], [ -54.222305459652731, 8.720098625170042 ], [ -52.211005664457986, 11.708250999932664 ], [ -52.211005664457986, 13.02639206739547 ], [ -54.557522092185209, 16.289408366270901 ], [ -55.406774017671189, 18.41947591309329 ], [ -56.233605254847475, 20.764770159853967 ], [ -55.898388622315025, 23.574448847537649 ], [ -54.222305459652731, 26.324628805165606 ], [ -53.551872194587844, 29.89051476950188 ], [ -53.551872194587844, 33.332083360765068 ], [ -54.222305459652731, 35.553549877935048 ], [ -55.563171989782582, 36.911383410950499 ], [ -57.239255152444848, 38.772054314545706 ], [ -58.423723710463292, 40.996856228604258 ], [ -58.915338315107142, 42.598003526146073 ], [ -58.915338315107142, 45.49843921137019 ], [ -58.580121682574671, 48.255927459193742 ], [ -57.239255152444848, 51.293815238756544 ], [ -54.89273872471766, 55.114659025331591 ], [ -52.546222296990472, 59.121686774902365 ], [ -50.199705869263276, 61.610619325969694 ], [ -46.512322911406237, 64.498068495175602 ], [ -44.000318843436546, 66.044206595829223 ], [ -40.813640158354488, 68.005606815029381 ], [ -36.120607302900076, 69.699313489554427 ], [ -33.660637739135723, 70.469323523897415 ], [ -30.086707917315881, 71.588021033564175 ], [ -25.058458429329018, 72.618524346562268 ], [ -20.030208941342163, 73.497969796422893 ], [ -14.331526188290411, 74.151900181277938 ], [ -8.968060067771106, 74.603450660150443 ], [ -3.604593947251801, 74.955621464397737 ], [ 0.082789010605239, 75.04242636600496 ] ] } },
{ "type": "Feature", "properties": { "id": 99 }, "geometry": { "type": "LineString", "coordinates": [ [ -45.06236059303788, 13.292728367282068 ], [ -44.134909681496211, 13.059415555877479 ], [ -43.439321497839963, 12.667425533396841 ], [ -42.938152563299006, 12.105512059109872 ], [ -42.598819109255309, 11.355026856584423 ], [ -42.540853427283963, 10.696481753135744 ], [ -42.627801950240993, 10.093931716049731 ], [ -42.7437333141837, 9.634074056365257 ], [ -43.05841213199411, 9.288599921507187 ], [ -43.622622371559075, 9.102620466142893 ], [ -44.340131713508583, 9.65000115872234 ], [ -44.901486388010319, 10.609566572212744 ], [ -45.19353485585652, 11.337408629893588 ], [ -45.2567798421532, 12.078123196112628 ], [ -45.178291956980587, 13.037115470448992 ], [ -45.06236059303788, 13.292728367282068 ] ] } },
{ "type": "Feature", "properties": { "id": 5 }, "geometry": { "type": "LineString", "coordinates": [ [ -63.085447253774049, -13.538048154689536 ], [ -62.121491730391377, -12.822159178666773 ], [ -61.261854742834331, -12.407143055580898 ], [ -60.277028104813162, -12.28281804584333 ], [ -59.250554947639593, -12.407143055580898 ], [ -58.24490505004222, -12.736422612790012 ], [ -57.64513791381448, -13.179478258843226 ], [ -57.260327916484485, -13.804011288101757 ], [ -57.239255152444848, -14.702654997219474 ], [ -57.524964297490136, -15.484494613980523 ], [ -57.993979473668297, -16.227856503139343 ] ] } },
{ "type": "Feature", "properties": { "id": 6 }, "geometry": { "type": "LineString", "coordinates": [ [ -58.580121682574671, -16.003739514601826 ], [ -56.825590240058787, -16.654861707754602 ], [ -55.407581478646982, -16.380408716771747 ], [ -54.095868875414943, -16.046431615183096 ], [ -52.881438929522915, -15.679243293832098 ], [ -51.875789031925542, -15.354223965167911 ], [ -50.534922501795727, -14.702654997219474 ], [ -49.194055971665911, -13.744143733749327 ], [ -48.356988186385578, -12.736422612790012 ], [ -48.188406074068531, -11.416813472125247 ], [ -48.45525666593408, -10.108584903120365 ], [ -48.858839339133425, -8.759550114304762 ], [ -49.822343708651537, -7.463431737550846 ], [ -50.87013913432817, -6.418355213311232 ] ] } },
{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ 14.832320842033301, 5.707538916242118 ], [ 15.774443660654201, 7.124158674964114 ], [ 17.178837269760525, 8.052463119288092 ], [ 18.688118983732821, 8.255504304287182 ], [ 20.531003595085085, 8.052463119288092 ], [ 22.143587946493586, 7.678148290643575 ], [ 23.883169920409646, 7.048943904166737 ], [ 25.304269920153459, 6.372172786467535 ], [ 26.866155680296128, 5.371660650809573 ], [ 28.461111528864446, 3.891010342107852 ], [ 29.246686455488678, 3.050880744746975 ], [ 29.595878964992831, 2.51931299862557 ], [ 29.909367859543831, 1.885569364411107 ], [ 30.123182262725713, 1.12571781494264 ], [ 30.200064246348493, 0.34924566497145 ], [ 30.252285938526324, -1.369731626524384 ], [ 30.178478395062118, -3.311986669115553 ], [ 29.917069305993881, -5.075358447969823 ], [ 29.536965193324853, -6.598844507512566 ], [ 28.877455475490862, -8.907844446700182 ], [ 28.139094344614669, -11.220053771562142 ], [ 27.23533624573421, -13.39367353488252 ], [ 26.464023453343991, -14.441617034152694 ], [ 25.798796288384537, -15.048526959601391 ], [ 24.642226894619757, -15.485981819320227 ], [ 23.547953287877199, -16.003739514601826 ], [ 21.871870125214905, -17.296301676892284 ], [ 20.195786962552607, -18.899102874837155 ], [ 19.387102150312163, -20.319605692920831 ], [ 18.51970379989034, -21.431138984712909 ], [ 17.149884526576567, -22.331095609046113 ], [ 15.837970739630675, -23.211602173749725 ], [ 14.501526906024774, -23.825812801615374 ], [ 13.261264674999913, -23.770624689143158 ], [ 12.044273286532839, -23.458550313470337 ], [ 10.712338576401484, -23.145435120324976 ], [ 9.804071354046476, -22.681037619456234 ], [ 8.897965258805421, -22.150934230304259 ], [ 8.12798819138418, -21.431138984712909 ], [ 7.992132459761633, -20.498618817570996 ], [ 8.12798819138418, -19.535976903314829 ], [ 8.341700576320134, -18.75194154445045 ], [ 8.798421456449105, -17.93919743853845 ] ] } },
{ "type": "Feature", "properties": { "id": 2 }, "geometry": { "type": "LineString", "coordinates": [ [ 15.133573541660148, -5.411402816735709 ], [ 14.465047819880926, -6.312564771460281 ], [ 13.792707011530331, -7.423294619729012 ], [ 13.156237679371038, -9.092884526720617 ], [ 12.821021046838592, -10.754623951203225 ], [ 13.066403181302347, -11.814626377647803 ], [ 13.491454311903484, -12.736422612790012 ], [ 13.919674697109484, -13.421657513153368 ], [ 14.832320842033301, -14.049111467927364 ], [ 15.801184686753718, -14.214840849833292 ], [ 16.741728838511133, -13.949586438080162 ], [ 17.280729068477431, -13.198411231666077 ], [ 17.717619996618033, -12.44819674073268 ], [ 18.184487167357894, -11.747327940472333 ], [ 19.095209537888618, -11.148489716633037 ], [ 19.86057033002016, -10.422970392215497 ], [ 21.201436860149975, -10.090958736459376 ], [ 21.893451643579464, -9.504997469623358 ], [ 22.54230339027983, -8.759550114304762 ], [ 22.877520022812277, -7.088557586849804 ], [ 22.813112658288929, -5.718993097178885 ], [ 22.54230339027983, -4.739136614461172 ], [ 21.755570133163697, -3.676094856621757 ], [ 20.866220227617532, -3.055773886823417 ] ] } },
{ "type": "Feature", "properties": { "id": 3 }, "geometry": { "type": "LineString", "coordinates": [ [ 24.553603185474572, -11.416813472125247 ], [ 25.275657102889504, -10.411982420174709 ], [ 25.928433648510019, -9.527035212789984 ], [ 26.379695327388024, -8.828353999424513 ], [ 26.958056749559915, -7.994140101527551 ], [ 27.570552878266653, -6.75357397752831 ], [ 27.953222091491142, -5.807876973859756 ], [ 28.240986143331579, -4.739136614461172 ], [ 28.342877942048489, -3.311032292014735 ], [ 28.376841874954124, -2.044375766746517 ], [ 28.240986143331579, -0.694894949565804 ], [ 28.023048177815497, 0.466123302980132 ], [ 27.570552878266653, 1.667180091954001 ], [ 27.23533624573421, 2.341709266732113 ] ] } }
]
}
<!DOCTYPE html>
<meta charset="utf-8">
<title>PROJECTION FACE</title>
<style>
body{ text-align: center }
</style>
<div id="map"></div>
<select id="projection-menu"></select>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/d3.geo.polyhedron.v0.min.js"></script>
<script>
var ratio = window.devicePixelRatio || 1,
width = 960 * ratio,
height = 450 * ratio;
var options = [
{name: "Aitoff", projection: d3.geo.aitoff()},
{name: "Albers", projection: d3.geo.albers().scale(145).parallels([20, 50])},
{name: "August", projection: d3.geo.august().scale(60)},
{name: "Baker", projection: d3.geo.baker().scale(100)},
{name: "Berghaus", projection: d3.geo.berghaus().scale(100)},
{name: "Boggs", projection: d3.geo.boggs()},
{name: "Bonne", projection: d3.geo.bonne().scale(100)},
{name: "Bromley", projection: d3.geo.bromley()},
{name: "Collignon", projection: d3.geo.collignon().scale(93)},
{name: "Craster Parabolic", projection: d3.geo.craster()},
{name: "Eckert I", projection: d3.geo.eckert1().scale(165)},
{name: "Eckert II", projection: d3.geo.eckert2().scale(165)},
{name: "Eckert III", projection: d3.geo.eckert3().scale(180)},
{name: "Eckert IV", projection: d3.geo.eckert4().scale(180)},
{name: "Eckert V", projection: d3.geo.eckert5().scale(170)},
{name: "Eckert VI", projection: d3.geo.eckert6().scale(170)},
{name: "Eisenlohr", projection: d3.geo.eisenlohr().scale(60)},
{name: "Equirectangular (Plate Carrée)", projection: d3.geo.equirectangular()},
{name: "Fahey", projection: d3.geo.fahey().scale(120)},
{name: "Gall Stereographic", projection: d3.geo.cylindricalStereographic().parallel(45).scale(140)},
{name: "Goode Homolosine", projection: d3.geo.homolosine()},
{name: "Ginzburg IV", projection: d3.geo.ginzburg4().scale(120)},
{name: "Ginzburg V", projection: d3.geo.ginzburg5().scale(120)},
{name: "Ginzburg VI", projection: d3.geo.ginzburg6().scale(120)},
{name: "Ginzburg VIII", projection: d3.geo.ginzburg8().scale(120)},
{name: "Ginzburg IX", projection: d3.geo.ginzburg9().scale(120)},
{name: "Gringorten", projection: d3.geo.gringorten().scale(220)},
{name: "Guyou", projection: d3.geo.guyou().scale(150)},
{name: "Hammer", projection: d3.geo.hammer().scale(165)},
{name: "Hammer Retroazimuthal", projection: d3.geo.hammerRetroazimuthal().scale(90)},
{name: "HEALPix", projection: d3.geo.healpix()},
{name: "Hill", projection: d3.geo.hill().scale(120)},
{name: "Kavrayskiy VII", projection: d3.geo.kavrayskiy7()},
{name: "Lagrange", projection: d3.geo.lagrange().scale(120)},
{name: "Lambert cylindrical equal-area", projection: d3.geo.cylindricalEqualArea()},
{name: "Larrivée", projection: d3.geo.larrivee().scale(95)},
{name: "Laskowski", projection: d3.geo.laskowski().scale(120)},
{name: "Loximuthal", projection: d3.geo.loximuthal()},
{name: "Mercator", projection: d3.geo.mercator().scale(100)},
{name: "Miller", projection: d3.geo.miller().scale(100)},
{name: "McBryde–Thomas Flat-Polar Parabolic", projection: d3.geo.mtFlatPolarParabolic()},
{name: "McBryde–Thomas Flat-Polar Quartic", projection: d3.geo.mtFlatPolarQuartic()},
{name: "McBryde–Thomas Flat-Polar Sinusoidal", projection: d3.geo.mtFlatPolarSinusoidal()},
{name: "Mollweide", projection: d3.geo.mollweide().scale(165)},
{name: "Natural Earth", projection: d3.geo.naturalEarth()},
{name: "Nell–Hammer", projection: d3.geo.nellHammer()},
{name: "Orthographic", projection: d3.geo.orthographic().scale(200)},
{name: "Polyconic", projection: d3.geo.polyconic().scale(100)},
{name: "Rectangular Polyconic", projection: d3.geo.rectangularPolyconic().scale(120)},
{name: "Robinson", projection: d3.geo.robinson()},
{name: "Sinusoidal", projection: d3.geo.sinusoidal()},
{name: "Sinu-Mollweide", projection: d3.geo.sinuMollweide()},
{name: "Stereographic", projection: d3.geo.stereographic()},
{name: "Times", projection: d3.geo.times().scale(140)},
{name: "Van der Grinten", projection: d3.geo.vanDerGrinten().scale(75)},
{name: "Van der Grinten II", projection: d3.geo.vanDerGrinten2().scale(75)},
{name: "Van der Grinten III", projection: d3.geo.vanDerGrinten3().scale(75)},
{name: "Van der Grinten IV", projection: d3.geo.vanDerGrinten4().scale(120)},
{name: "Wagner IV", projection: d3.geo.wagner4()},
{name: "Wagner VI", projection: d3.geo.wagner6()},
{name: "Wagner VII", projection: d3.geo.wagner7()},
{name: "Waterman", projection: d3.geo.polyhedron.waterman().scale(70)},
{name: "Winkel Tripel", projection: d3.geo.winkel3()}
];
var menu = d3.select("#projection-menu")
.on("change", change);
menu.selectAll("option")
.data(options)
.enter().append("option")
.text(function(d) { return d.name; });
function change() {
update(options[this.selectedIndex]);
}
var i = 0,
n = options.length - 1;
rando();
var projection = options[i].projection;
options.forEach(function(option) {
option.projection
.translate([width / 2, height / 2])
.scale(option.projection.scale() * ratio)
.clipExtent([[2 * ratio, 2 * ratio], [width - 2 * ratio, height - 2 * ratio]]);
});
var graticule = d3.geo.graticule()(),
face,
boundaries;
var canvas = d3.select("#map").append("canvas")
.attr("width", width)
.attr("height", height)
.style("width", width / ratio + "px")
.style("height", height / ratio + "px");
var context = canvas.node().getContext("2d");
context.fillStyle = "#f9f9f9";
context.strokeStyle = "#000";
var path = d3.geo.path()
.projection(projection)
.context(context);
function rando() {
var j = Math.floor(Math.random() * n);
i = j + (j >= i);
menu.property("selectedIndex", i = j + (j >= i));
}
function change() {
update(options[this.selectedIndex]);
}
function pathTween(projection0, projection1) {
var t = 0,
projection = d3.geo.projection(function(λ, φ) {
λ *= 180 / Math.PI, φ *= 180 / Math.PI;
var p0 = projection0([λ, φ]), p1 = projection1([λ, φ]);
return [(1 - t) * p0[0] + t * p1[0], (1 - t) * -p0[1] + t * -p1[1]];
})
.scale(1)
.translate([width / 2, height / 2])
.clipExtent(projection0.clipExtent()),
path = d3.geo.path().projection(projection).context(context);
return function() {
return function(u) {
t = u;
redraw(path);
};
};
}
function update(option) {
canvas.transition()
.duration(750)
.ease( d3.ease("quad") )
.tween("path", pathTween(projection, projection = option.projection));
path.projection(projection);
}
function redraw(path) {
context.clearRect(0, 0, width, height);
context.lineWidth = .5 * ratio;
context.strokeStyle = "#999";
context.beginPath(), path(graticule), context.stroke();
context.beginPath(), path({type: "Sphere"}), context.stroke();
context.lineWidth = 2 * ratio;
if (face) {
context.strokeStyle = "#000";
context.lineWidth = 2;
context.beginPath(), path(face), context.stroke();
}
}
d3.json("/awoodruff/raw/9216081/face.geojson", function(error, data) {
face = data;
redraw(path)
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment