An example that superimposes CartoDB labels over an ESRI's satellite layer with Leaflet.js.
Last active
April 6, 2023 09:48
-
-
Save nitaku/b1f831256e6770f8a90f to your computer and use it in GitHub Desktop.
Leaflet: CartoDB labels over ESRI satellite tiles
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 = d3.select 'body' | |
width = body.node().getBoundingClientRect().width | |
height = body.node().getBoundingClientRect().height | |
d3.select('#map') | |
.style | |
width: width | |
height: height | |
esriAttr = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community' | |
esriUrl = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' | |
base_layer = L.tileLayer(esriUrl, {id: 'esri_satellite', attribution: esriAttr}) | |
cartodbAttr = '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>' | |
cartodbUrl = 'http://{s}.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}.png' | |
labels_layer = L.tileLayer(cartodbUrl, {id: 'cartodb_labels', attribution: cartodbAttr}) | |
map = L.map 'map', | |
center: [30, 0], | |
zoom: 2, | |
layers: [base_layer, labels_layer] |
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 { | |
margin: 0; | |
padding: 0; | |
width: 100%; | |
height: 100%; | |
} | |
body { | |
display: flex; | |
} | |
#map { | |
flex-grow: 1; | |
} |
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 lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Leaflet: CartoDB labels over ESRI satellite tiles</title> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" /> | |
<link rel="stylesheet" href="index.css"> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="index.js"></script> | |
</body> | |
</html> |
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
// Generated by CoffeeScript 1.10.0 | |
(function() { | |
var base_layer, body, cartodbAttr, cartodbUrl, esriAttr, esriUrl, height, labels_layer, map, width; | |
body = d3.select('body'); | |
width = body.node().getBoundingClientRect().width; | |
height = body.node().getBoundingClientRect().height; | |
d3.select('#map').style({ | |
width: width, | |
height: height | |
}); | |
esriAttr = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'; | |
esriUrl = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'; | |
base_layer = L.tileLayer(esriUrl, { | |
id: 'esri_satellite', | |
attribution: esriAttr | |
}); | |
cartodbAttr = '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>'; | |
cartodbUrl = 'http://{s}.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}.png'; | |
labels_layer = L.tileLayer(cartodbUrl, { | |
id: 'cartodb_labels', | |
attribution: cartodbAttr | |
}); | |
map = L.map('map', { | |
center: [30, 0], | |
zoom: 2, | |
layers: [base_layer, labels_layer] | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment