Exploring New Technologies for Making Maps. Vector Tiles & WebGL (Part One ...

Maps are both practical and political. They possess undoubtable utility for navigating the physical world and have a long history of being used to shape and reshape the our social and political conceptions of the world. The ability to mark a territory , carve up a continent (or remember one ), count a people , or map our desires is a powerful one. Thus despite being one of the oldest visualization types we have, they remain one of the most popular ways of visualizing data today.

I recently became more interested in more deeply exploring web cartography, and in particular I had a chance to do a couple of things: read Axis Maps’ fantastic Guide to Thematic Mapping , which I highly recommend, and make some maps with a new map rendering library called Tangram .

Two things in particular drove my interest to learn more about making ‘slippy maps’ :

Patricio Gonzalez-Vivo gave a talk about WebGL based mapping at OpenVisConf 2016 and frankly, those demos blew me away. I wanted to better understand how to make these visually expressive maps. Practical needs in myday to day work got me interested in exploring new approaches to rendering data on slippy maps and the challenges we face around interactivity and layering when using a common technique of layering SVG on top of tile based maps.

This blog post, and the next one in the series, aim to share what I learned in exploring Tangram . This post will cover basic setup and concepts and also explore visualizing data on a choropleth map.

Part two will look at getting started with shaders and mouse interaction with Tangram―stay tuned for that.

What is Tangram?

Mapzen is a company working on an open web mapping stack, from tile servers to a rendering engine and other associated tools. Tangram is a rendering engine created by Mapzen that uses WebGL as its core rendering technology , this allows for inclusion of 3D geometry in maps as well as advanced shader-driven visual rendering options. Check out the demos on their home page to get a sense of what I am talking about.

Tangram is implemented as a leaflet.js plugin, leaflet.js is an open source library for making interactive maps on the web. Tangram allows customization of maps via a YAML configuration file. YAML might seem a strange choice at first if you are used to the dominance of JSON for driving all things web. But it ends up being a great configuration language and is more flexible and easier to work with than a JSON alternative would be. We’ll see examples of this later and you can see for yourself what a difference it makes.

Vector Tiles

Another important piece of this rendering stack is the use of vector tiles . Initially slippy maps used image tiles, which are sliced up pictures of the globe. A small image is made for each part of the world for every zoom level we want to support. As the user pans around the map new images appropriate for the zoom level are downloaded and rendered on screen.

Vector tiles replace the images with vector data about the world’s geometry (lines that describe countries or points that describe landmarks for example), and allow the client to have complete control over how that geometry is rendered. They also result in a more compact data transfer than there image based counterparts.

Your First Tangram Map

Lets see what it looks like to get set up with Tangram. The Tangram tutorial is a great resource for getting started, so we won’t duplicate it here. My hope is that this post can act as a companion to the excellent documentation on the tangram site; providing highlights, commentary and caveats as you get started, or a sneak peek if you are still looking from a distance.

So what does a basic map look like with tangram?

First some HTML

<!DOCTYPE html> <head> <meta charset="utf-8"> <!-- leaflet --> <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /> <!-- Tangram library --> <script src="https://mapzen.com/tangram/0.8/tangram.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } #map { height: 100%; width: 100%; position: absolute; } </style> </head> <body> <div id="map"></div> </body>

And some javascript

// Make a leaflet map object var map = L.map('map'); // Create a tangram layer var layer = Tangram.leafletLayer({ scene: 'scene.yaml', attribution: '<a href="https://mapzen.com/tangram" target="_blank">Tangram</a> | OSM contributors | <a href="https://mapzen.com/" target="_blank">Mapzen</a>' }); // Add the tangram layer to the map. layer.addTo(map); // Lets go to Boston! map.setView([42.364506, -71.038887], 15); // Grab the live scene object and listen to events. var scene = layer.scene; scene.subscribe({ error: function (e) { console.log('scene error:', e); }, warning: function (e) { console.log('scene warning:', e); } });

And here is the YAML configuration file we mentioned earlier. We’ll break this down a bit more below.

# Yay YAML, we can write comments! # Each major part of the configuration is a key in a object/dictionary. sources: osm: type: TopoJSON url: https://vector.mapzen.com/osm/all/{z}/{x}/{y}.topojson?api_key=vector-tiles-HqUVidw max_zoom: 16 cameras: camera1: type: perspective lights: light1: visible: true type: directional direction: [0, 1, -.5] diffuse: .4 ambient: 1 layers:

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: WebGLJavaScriptHTMLJavaUV
tags: lt,gt,map,Tangram,maps,leaflet,scene
本文标题:Exploring New Technologies for Making Maps. Vector Tiles &amp; WebGL (Part One ...

技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(559)