Last active
May 29, 2019 08:19
-
-
Save ramiroaznar/44eb18664a8f3f97d9c3a3242736b38b to your computer and use it in GitHub Desktop.
CARTO JS & Planet Basemaps
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> | |
<title>CARTO JS + Planet Basemaps</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<!-- Include Airship --> | |
<link rel="stylesheet" href="https://libs.cartocdn.com/airship-style/v2.0.5/airship.css"> | |
<link rel="stylesheet" href="https://libs.cartocdn.com/airship-icons/v2.0.5/icons.css"> | |
<script src="https://libs.cartocdn.com/airship-components/v2.0.5/airship.js"></script> | |
<!-- Include Leaflet --> | |
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script> | |
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet"> | |
<!-- Include CARTO.js --> | |
<script src="https://libs.cartocdn.com/carto.js/v4.1.11/carto.min.js"></script> | |
<link href="main.css" rel="stylesheet"> | |
</head> | |
<body id="app" class="as-app-body as-app"> | |
<div class="as-content"> | |
<main class="as-main"> | |
<div class="as-map-area"> | |
<div id="map"></div> | |
<div class="as-map-panels"> | |
<div class="as-panel as-panel--top as-panel--right"> | |
<div class="as-panel__element as-p--32"> | |
<h4 class="as-subheader as-font--medium">CARTO JS & Planet Basemaps</h4> | |
<span class="as-caption">Insert Planet API Key</span> | |
<input id='input-form' class="as-input" type="text" placeholder="PL_API_KEY"> | |
</div> | |
</div> | |
</div> | |
</div> | |
</main> | |
</div> | |
<script src="main.js" type="text/javascript"></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
* { | |
box-sizing: border-box; | |
} | |
body, *{ margin: 0; padding: 0; } | |
#map { | |
position: absolute; | |
height: 100%; | |
width: 100%; | |
z-index: 0; | |
} |
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
// add Leaflet basemap | |
const map = L.map('map').setView([30, 0], 3); | |
map.scrollWheelZoom.disable(); | |
const client = new carto.Client({ | |
apiKey: 'default_public', | |
username: 'cartojs-test' | |
}); | |
const form = document.getElementById('input-form'); | |
form.addEventListener('change', (e) => { | |
// get Planet API Key | |
let PL_API_KEY = e.srcElement.value; | |
// generate Planet basemap | |
let mosaic = `https://tiles1.planet.com/basemaps/v1/planet-tiles/global_monthly_2018_07_mosaic/gmap/{z}/{x}/{y}.png?api_key=${PL_API_KEY}` | |
// add Planet Basemap to Leaflet map | |
L.tileLayer(mosaic, { | |
maxZoom: 18 | |
}).addTo(map); | |
// add CARTO VL layer | |
const source = new carto.source.Dataset('ne_10m_populated_places_simple'); | |
const style = new carto.style.CartoCSS(` | |
#layer { | |
marker-width: 7; | |
marker-fill: #EE4D5A; | |
marker-line-color: #FFFFFF; | |
} | |
`); | |
const layer = new carto.layer.Layer(source, style); | |
client.addLayer(layer); | |
client.getLeafletLayer().addTo(map); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment