Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active November 4, 2016 17:23
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 ThomasG77/52f729ba5bf18d5051018dec516fe778 to your computer and use it in GitHub Desktop.
Save ThomasG77/52f729ba5bf18d5051018dec516fe778 to your computer and use it in GitHub Desktop.
Tangram plaything with OSM2VectorTiles tiles

Tangram personal playground

Tangram is a MapZen company project. There is a smalll tutorial for getting started at https://tangrams.github.io/tangram-tutorial/

We choose to play with it, featuring basic map creation with Tangram.

Two files are required:

  • an html file for the web page to call Leaflet and Tangram together (they work together)
  • a yaml file for tiles styling configuration required for Tangram engine where we use http://osm2vectortiles.org remote CDN tiles.

Demo is available at http://bl.ocks.org/ThomasG77/52f729ba5bf18d5051018dec516fe778

Feel free to ask any questions or improvements in the comments.

<!DOCTYPE html>
<html lang="en">
<head>
<title>My Web Map</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://mapzen.com/js/mapzen.css">
<script src="https://mapzen.com/js/mapzen.min.js"></script>
<style>
#map {
height: 100%;
width: 100%;
position: absolute;
}
html,body{margin: 0; padding: 0}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.Mapzen.map('map', {
scene: 'vector.yaml'//L.Mapzen.BasemapStyles.TronMoreLabels
});
map.setView([37.7749, -122.4194], 12);
map.on('tangramloaded', function(event) {
console.log(event.tangramLayer);
});
var locator = L.Mapzen.locator();
locator.setPosition('bottomright');
locator.addTo(map);
L.Mapzen.hash({
map: map
});
</script>
</body>
</html>
MIT License
Copyright (c) 2016 Thomas Gratier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
sources:
_osm2vectortiles:
type: MVT
url: http://osm2vectortiles-0.tileserver.com/v1/{z}/{x}/{y}.pbf
layers:
_earthLayer:
data:
source: _osm2vectortiles
layer: landuse
draw:
_landUseStyle:
style: polygons
order: 0
color: '#ddeeee'
_waterLayer:
data:
source: _osm2vectortiles
layer: water
draw:
_waterStyle:
style: polygons
order: 1
color: '#88bbee'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment