Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Created July 17, 2018 14: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 ramiroaznar/dbccbbb35d2c0fcc62a4b2894f565263 to your computer and use it in GitHub Desktop.
Save ramiroaznar/dbccbbb35d2c0fcc62a4b2894f565263 to your computer and use it in GitHub Desktop.
CARTO line styles | CARTO.s v4.1
<!DOCTYPE html>
<html>
<head>
<title>CARTO line styles | CARTO.s v4.1</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<!-- Include Leaflet -->
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<link href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" rel="stylesheet">
<!-- Include CARTO.js -->
<script src="https://libs.cartocdn.com/carto.js/v4.1.0/carto.min.js"></script>
<style>
* {
box-sizing: border-box;
}
body, *{ margin: 0; padding: 0; }
#map {
position: absolute;
height: 100%;
width: 100%;
z-index: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const map = L.map('map').setView([30, 0], 3);
map.scrollWheelZoom.disable();
L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}.png', {
maxZoom: 18
}).addTo(map);
const client = new carto.Client({
apiKey: 'default_public',
username: 'ramirocartodb'
});
const source = new carto.source.Dataset(`
ne_10m_roads
`);
const style = new carto.style.CartoCSS(`
#layer {
line-width: 1;
line-color: #EE4D5A;
line-opacity: 0.7;
line-dasharray: 4,2;
}
`);
const layer = new carto.layer.Layer(source, style);
client.addLayer(layer);
client.getLeafletLayer().addTo(map);
const layerStyle = layer.getStyle();
console.log(layerStyle)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment