A simple CARTO VL map from a GeoJSON + 3 .geojson files (point, line, polygon)
Last active
November 19, 2018 18:11
-
-
Save VictorVelarde/fe7fae0f6f92de3de32a3f7e8a213aa9 to your computer and use it in GitHub Desktop.
[CARTO VL - Simple geojson created with geojson.io in a gist]
This file contains hidden or 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>GeoJSON lines test | CARTO</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta charset="UTF-8"> | |
<script src="http://libs.cartocdn.com/carto-vl/v1.0.0/carto-vl.js"></script> | |
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js"></script> | |
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.css" rel="stylesheet" /> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
} | |
#map { | |
position: absolute; | |
height: 100%; | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
const map = new mapboxgl.Map({ | |
container: 'map', | |
style: carto.basemaps.voyager, | |
center: [0, 0], | |
zoom: 1 | |
}); | |
const nav = new mapboxgl.NavigationControl(); | |
map.addControl(nav, 'top-left'); | |
// gist: https://gist.github.com/VictorVelarde/fe7fae0f6f92de3de32a3f7e8a213aa9 | |
const base = 'https://gist.githubusercontent.com/VictorVelarde/fe7fae0f6f92de3de32a3f7e8a213aa9/raw/e8473430e9876fa81d1a31f2875068c400806db1/'; | |
const url = base + 'point.geojson'; // line.geojson polygon.geojson | |
map.on('load', () => { | |
fetch(url) | |
.then(response => response.json()) | |
.then(function (data) { | |
const source = new carto.source.GeoJSON(data); | |
const viz = new carto.Viz(` | |
width: 10 | |
color: opacity(#FF3D00, 0.5) | |
`); | |
const layer = new carto.Layer('layer', source, viz); | |
layer.addTo(map); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment