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
分页:12
转载请注明
本文标题:Exploring New Technologies for Making Maps. Vector Tiles &amp; WebGL (Part One ...
本站链接:http://www.codesec.net/view/532379.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(214)