Skip to content

Instantly share code, notes, and snippets.

@mpmckenna8
Forked from emeeks/d3map.css
Created July 29, 2014 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpmckenna8/61f3414912933de043ef to your computer and use it in GitHub Desktop.
Save mpmckenna8/61f3414912933de043ef to your computer and use it in GitHub Desktop.

A globe using orthographic projection with raster tiles from d3.carto.map.

If you set map.mode("globe") it will overwrite the projection with an orthographic projection and modify panning to allow for rotating a globe along two axes.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>d3.carto.map - globe mode</title>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="https://raw.githubusercontent.com/emeeks/d3-carto-map/master/d3map.css" />
<link type="text/css" rel="stylesheet" href="https://raw.githubusercontent.com/emeeks/d3-carto-map/master/examples/example.css" />
</head>
<style>
html,body {
height: 100%;
width: 100%;
margin: 0;
}
#map {
height: 100%;
width: 100%;
position: absolute;
}
</style>
<script>
function makeSomeMaps() {
map = d3.carto.map();
d3.select("#map").call(map);
map.mode("globe");
map.refresh();
tileLayer = d3.carto.layer();
tileLayer
.type("tile")
.path("examples.map-zgrqqx0w")
.label("Base Layer")
geojsonLayer = d3.carto.layer.geojson();
geojsonLayer
.path("http://bl.ocks.org/emeeks/raw/c970c9ee3e242e90004b/world.geojson")
.label("Canvas Features")
.cssClass("halffilledcountries")
.renderMode("canvas")
.on("load", selectFeatures);
map.addCartoLayer(tileLayer).addCartoLayer(geojsonLayer);
function selectFeatures() {
fNamedCountries = geojsonLayer.features().filter(function (d) {return d.properties.name.length < 6});
featureLayer = d3.carto.layer.featureArray();
featureLayer
.features(fNamedCountries)
.label("SVG Features")
.cssClass("francelike")
.renderMode("svg");
map.addCartoLayer(featureLayer);
}
}
</script>
<body onload="makeSomeMaps()">
<div id="map"></div>
<footer>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8" type="text/javascript"></script>
<script src="http://d3js.org/topojson.v1.min.js" type="text/javascript">
</script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js" type="text/javascript">
</script>
<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/tile.js" type="text/javascript">
</script>
<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.quadtiles.js" type="text/javascript">
</script>
<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.geo.raster.js" type="text/javascript">
</script>
<script src="https://rawgit.com/emeeks/d3-carto-map/master/d3.carto.map.js" type="text/javascript">
</script>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment