UTFGrid
UTFGrid
UTFGrid is a specification for rasterized interaction data. As of version 1.2, it was removed from incubation in the MBTiles Specification and split into its own repository.
See CHANGELOG.md for per-version changes.
License
This specification is licensed under a Creative Commons Attribution 3.0 United States License.
Applications which make use of the specification are not subject to any restrictions.
Implementations
Write
- Mapnik's grid_renderer (Uses Antigrain Geometry library for rendering).
- Various python sample implementations
- GeoScript groovy example
- TileStache
- create-utfgrids
Read
- Wax for adding support to the Leaflet, Modest Maps, OpenLayers, and Google Maps clients: examples, code
- Leaflet.utfgrid
- OpenLayers Native: blog post, general demo,
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
UTFGrid
UTFGrid is a specification for rasterized interaction data. As of version 1.2, it was removed from incubation in the MBTiles Specification and split into its own repository.
See CHANGELOG.md for per-version changes.
License
This specification is licensed under a Creative Commons Attribution 3.0 United States License.
Applications which make use of the specification are not subject to any restrictions.
Implementations
Write
- Mapnik's grid_renderer (Uses Antigrain Geometry library for rendering).
- Various python sample implementations
- GeoScript groovy example
- TileStache
- create-utfgrids
Read
- Wax for adding support to the Leaflet, Modest Maps, OpenLayers, and Google Maps clients: examples, code
- Leaflet.utfgrid
- OpenLayers Native: blog post, general demo, example multi-grid, example geography-class
- GDAL MBTiles support
- Landez - Python module
Servers
- TileMill - via tilelive.js which uses tilelive-mapnik to request grid creation and node-mbtiles to cache and fetch grids stored in MBTiles format.
- TileStache's
TileStache.Goodies.Providers.MapnikGrid:Provider - django-mbtiles which serves grids stored in MBTiles along with tiles using a simple template tag.
Authors
- Tom MacWright (tmcw)
- Will White (willwhite)
- Konstantin Kaefer (kkaefer)
- Justin Miller (incanus)
- Dane Springmeyer (springmeyer)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Interaction
Tile servers can enhance tilesets with interactivity by implementing two additional HTTP endpoints.
[base path]/layer.json: A layer manifest JSON containing the interaction formatter function and other optional attributes.[base path]/{n}/{n}/{n}.grid.json: A UTFGrid JSON file corresponding to its adjacent tile image.
[base path] refers to the full layer URL prior to any x, y or z coordinates.
Examples:
OSM-style URL schema
http://example.com/0/0/0.png // tile image for 0/0/0
http://example.com/0/0/0.grid.json // utfgrid for 0/0/0
http://example.com/layer.json // layer manifest
TileJSON
UTFGrid requires additions to the TileJSON payload for a layer:
template: String. In the format of a mustache template.legend: String. Self-contained HTML that may be displayed as a legend for this layer. Optional.
Example response from layer.json:
{
"template": "{{NAME}}",
"legend": "<strong>Countries of the World</strong>"
}
Each layer.json item should be represented by a single row in the metadata table where key,value match its key and value in the layer.json object.
Template
As of UTFGrid 1.1, the formatter key is deprecated and replaced by template. Template is to be a mustache format string that produces HTML, which will be cleaned with an HTML whitelist after generation.
Mustache
Template data is specified according to the mustache specification. The full specification is supported, but no partials are provided, or should be provided by implementations.
Given the switch to templates from formatters, the options object is no longer available. Its functionality is emulated by setting 'format flags' on each data object.
For an example data object like
{
"id": "helloworld"
}
This will be transformed into
{
"id": "helloworld"
"__location__": true
}
By the tooltip/interaction implementation, in order to trigger the location template. Note that true, 1, and all non-false values are equal to template, so implementations may set "__location__": 1 to save bytes.
The template implementation could be:
{{#__location__}}
http://your.com/{{id}}
{{/__location__}}
{{#__full__}}
This content has the id {{id}}
{{/__full__}}
{{#__teaser__}}
{{id}}
{{/__teaser__}}
Which, for this implementation, will produce the output
http://your.com/helloworld
legend
A tileset may provide an HTML string that can be rendered by the client as a legend. The string should be self-contained and not reference external stylesheets, scripts or images. The Data URI scheme may be used to embed images or other data if necessary.
<div><span style='padding:0px 10px; background:#333;'></span> +10% population</div>
<div><span style='padding:0px 10px; background:#666;'></span> +5% population</div>
<div><span style='padding:0px 10px; background:#999;'></span> +0% population</div>
<div><span style='padding:0px 10px; background:#ccc;'></span> -5% population</div>
grid.json
See utfgrid.md for the format and storage of UTFGrid JSON.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
UTFGrid
The UTFGrid encoding scheme encodes interactivity data for a tile in a space efficient manner. It is designed to be used in browsers, e.g. for displaying tooltips when hovering over certain features of a map tile.
Since slower browsers and machines can't cope with rendering the actual polygons used to draw vectors on the map tile, we use a grid-based approach where we store the associated information for each pixel.
UTFGrid uses JSON as a container format. It is exclusively geared towards square tiles.
Grid
To achieve reasonable speed in browsers, we store information for a pixel in long strings, where each character's Unicode code point is the key for retrieving the information associated with that pixel. When we have less than 96 unique IDs, this means that the space taken up by storing each pixel separately is 256 * 256 = 64 KB. Gzipping the grid data typically reduces it to a size below 2K.
By default, UTFGrid operates on a 4x4 grid, meaning that a tile at zoom level 0 that contains the entire world in its extent will have an grid resolution of 64x64. We take advantage of UTF-8's variable length codepoint encoding: all ASCII characters are encoded as is, that means that the first 94 codepoints are encoded with their code number as a single byte (codes 0x20,0x21, 0x23-0x5B and 0x5D-0x7F). IDs with a number larger than that will get encoded as multiple bytes.
Encoding IDs
JSON doesn't allow control characters, " and \ to be encoded as their literal UTF-8 representation. Encoding an ID works as follows:
- Add 3210.
- If the result is >= 3410, add 1.
- If the result is >= 9210, add 1.
This ensures that all characters that cannot be represented natively are skipped.
Decoding works as follows:
- If the codepoint is >= 9310, subtract 1.
- If the codepoint is >= 3510, subtract 1.
- Subtract 3210.
Mapping an ID to a key
The UTFgrid file contains an array in a property named grid at the root level. Each entry represents a row in the grid. Each array entry is a string that contains the UTF-8 encoded codepoint for each column. The string length corresponds to the number of entries in the grid array. Only powers of two are allowed.
The keys are stored in an array named keys at the root level. The index of each key represents the ID that it is associated to.
Retrieving a key from a coordinate works as follows (json is the root level object, x and y are the coordinates, starting from top left at 0, and size is the number of entries in the grid key):
var factor = 256 / size, row = y / factor, col = x / factorvar id = json.grid[row].charCodeAt(col);is the character that contains the encoded ID.- Decode the id as described in "Encoding IDs".
var key = json.keys[id];retrieves the ID associated with the coordinate.
All divisions are integer divisions.
Mapping a key to data
The JSON file may contain an optional data property at the root level. If it isn't present, the client looks up the obtained key in its internal data store. If the lookup key is not present, it queries the server with the missing keys. If the data property is present, but the key cannot be found, the client must behave as if there were no data property.
An empty key signifies the unavailability of information for that pixel. No action may be taken to retrieve data for an empty ("") key.
Example UTFGrid JSON file
{ "grid":
[ " !!!#########",
" !!!#########",
" !!!!#########",
" !!!##########",
" !! !!!##########",
" !!!#########",
" !!######### ",
" ! !!! ####### ",
" ### ",
" $ ",
" $$ %%",
" $$$$$$$%%",
" $$$$$$$%%",
" $$$$$$$$$%%",
" $$$$$$$$$$%%",
" $$$$$$$$$$$$%",
" $$$$$$$$$%%%%",
" $$$$$$$$$%%%%%",
" $$$$$$$$%%%%%%",
" $$$$$$$%%%%%%%",
" $$$$%%%%%%%%%%",
" $$$$%%%%%%%%%%%",
" # # # $$$$$%%%%%%%%%%%%",
" $$$$$$$%%%%%%%%%%%%",
" $$$&&&&'%%%%%%%%%%%",
" $$$$&&&&'''%%%%%%%%%",
" $$$$'''''''''%%%%%%%%",
" $$$$'''''''''''%%%%%%",
" $$$$&''''''''((((%%%%%",
" $$$&&''''''''(((((%%%%",
" $$$&&'''''''''(((((((%%",
" $$$&&''''''''''(((((((%",
" $$$&&&''''''''''((((((((",
" ''''''''''''''''((((((((",
" '''''''''''''''((((((((",
" '''''''''''''''((((((((",
" '''''''''''''''((((((((",
" '''''''''''''''((((((((",
" '''''''''''''''((((((((",
" ) '''''''''''''''((((((((",
" ***'''''''''''''(((((((",
" *****'''''''''''(((((((",
" )) ******'''(((((((((((((((",
" *******(((((((((((((((++",
" *******(((((((((((((++++",
" ********((((((((((((++++",
" ***,,-**((((((((((++++++",
" ,,,,-------(((((+++++++",
" ,,---------(((((+++++.+",
" --------(((((+++....",
" -///----0000000....",
" ////----0000000....",
" /////1---0000000...",
" ///11--0000000....",
" 111110000000....",
" 11110000000....",
" 1111000000....",
" 1100 . ",
" ",
" ",
" ",
" ",
" ",
" " ],
"keys":
[ "",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16" ],
"data":
{ "1": { "admin": "Portugal" },
"2": { "admin": "Spain" },
"3": { "admin": "Morocco" },
"4": { "admin": "Algeria" },
"5": { "admin": "Western Sahara" },
"6": { "admin": "Mauritania" },
"7": { "admin": "Mali" },
"8": { "admin": "Cape Verde" },
"9": { "admin": "Senegal" },
"10": { "admin": "Burkina Faso" },
"11": { "admin": "Guinea Bissau" },
"12": { "admin": "Guinea" },
"13": { "admin": "Ghana" },
"14": { "admin": "Sierra Leone" },
"15": { "admin": "Ivory Coast" },
"16": { "admin": "Liberia" } } }
To test implementations, demo.json contains a grid that consists of 65501 different keys. This is the maximum possible in this version of UTFGrid. Implementors should check that obtaining a coordinate should return the key y * 256 + x for all x/y, with the exception of y = 255 and x >= 222 and x <= 255 returning 65501 due to the maximum codepoint allowed in JSON.
A dummy code validation routine is given here:
var json = JSON.parse(/* demo.json */); // the resolution of the grid. adjust this for your grid.
var resolution = 4; var key = 0,
dimension = 256 / resolution; for (var y = 0; y < dimension; y++) {
for (var x = 0; x < dimension; x++) {
var code = json.grid[y].charCodeAt(x);
if (code >= 93) code--;
if (code >= 35) code--;
code -= 32; assert(code == key); if (key < 65501) key++;
}
}
UTFGrid的更多相关文章
- MBTiles
MBTiles Specification MBTiles is a specification for storing tiled map data in SQLite databases for ...
- SuperMap iClient 7C——网络客户端GIS开发平台 产品新特性
SuperMap iClient 7C是空间信息和服务的可视化交互开发平台,是SuperMap服务器系列产品的统一客户端.产品基于统一的架构体系,面向Web端和移动端提供了多种类型的SDK开发包,帮助 ...
- Exploring the MapBox stack: MBTiles, TileJSON, UTFGrids and Wax
转自:http://blog.thematicmapping.org/2012/11/exploring-mapbox-stack-mbtiles-tilejson.html In my last b ...
- Tilemill + tilestream + mapbox.js 自制地图
感谢Mapbox,带来了一整套完整的地图方案. 你可以把你的地图放在Mapbox的网站上.也可以使用他们提供的开源软件自己架设地图服务. Mapbox的地图方案包括web,ios和android. 不 ...
- SuperMap iClient
SuperMap iClient 7C——网络客户端GIS开发平台 产品新特性 SuperMap iClient 7C是空间信息和服务的可视化交互开发平台,是SuperMap服务器系列产品的统一客 ...
- leaflet地图库
an open-source JavaScript libraryfor mobile-friendly interactive maps Overview Tutorials Docs Downlo ...
- 可视化之Berkeley Earth
去年冬天雾霾严重的那几天,写了两篇关于空气质量的文章,<可视化之PM2.5>和<谈谈我对雾霾的认识>.坦白说,环境问题是一个无法逃避又无能为力的话题.最近因为工作中有一些数据可 ...
- openLayers 3知识回顾
openlayers 知识 前段时间帮助同事重构一个地图类的项目,然后就学习了openLayer3这个框架,但是官网上没有中文版,也没有详细的例子解释,我只能遇到看不懂的就翻译成中文来用,为了方便以后 ...
- ol图层支持的数据源
ol.source.BingMaps,必应地图的数据: ol.source.Cluster,聚族矢量数据: ol.source.ImageCanvas,数据来源是一个canvas元素,其中数据是图片: ...
随机推荐
- 机器指令翻译成 JavaScript —— No.5 指令变化
上一篇,我们通过内置解释器的方案,解决任意跳转的问题.同时,也提到另一个问题:如果指令发生变化,又该如何应对. 指令自改 如果指令加载到 RAM 中,那就和普通数据一样,也是可以随意修改的.然而,对应 ...
- 谁偷了我的热更新?Mono,JIT,iOS
前言 由于匹夫本人是做游戏开发工作的,所以平时也会加一些玩家的群.而一些困扰玩家的问题,同样也困扰着我们这些手机游戏开发者.这不最近匹夫看自己加的一些群,常常会有人问为啥这个游戏一更新就要重新下载,而 ...
- Ubuntu部署python3.5的开发和运行环境
Ubuntu部署python3.5的开发和运行环境 1 概述 由于最近项目全部由python2.x转向 python3.x(使用目前最新的 python3.5.1) ,之前的云主机的的默认python ...
- ASP.NET MVC Model元数据(一)
ASP.NET MVC Model元数据(一) 前言 在我初学的时候对Model元数据的概念很模糊,或者说是在大脑中没有它的一个模型,作为小白的我去看网上的一些文章还是两眼一黑啥都看不明白,然后我想退 ...
- Atitit 多元化战略 适合我们发展 的核心业务attilax总结
Atitit 多元化战略 适合我们发展 的核心业务attilax总结 1.1. 历史的大趋势,全球范围内人员的大流动1 1.2. 衣食住行1 1.3. 农村包围城市战略1 1.4. 挪开三座大山(住房 ...
- iOS集成sharesdk遇到的坑
分享新浪微博 ★★★分享新浪微博★★★ 前言: 写这个目地是为了记录那些过坑,直接先上效果图.大家看看如果你遇到了应该如果处理更好,因为刚一看到这个效果的时候就明白其实很简单不就是分享微博吧.但是要求 ...
- 使用nodemailer发送邮件
今天闲来无事,一时兴起看了下如果使用javascript来发送邮件.经过调研发现,nodeJs可以实现这个功能. 具体的步骤如下: 1.安装依赖 npm install nodemailer -g ( ...
- WCF学习之旅—WCF服务配置(十四)
一.概述 我们在前面章节中讲了寄宿,在前面的实例中也用到了配置文件,这一篇主要讲讲如何在应用配置文件,提高WCF程序的灵活性.在编写WCF服务应用程序时,编写配置项也是其中一项主要工作,在前面的几个示 ...
- Boostrap入门(一)
1.第一步:下载Boostrap有关文件 Boostrap中文网:http://www.bootcss.com/ -->--> 2.第二步: 如下代码:引入相关文件即可. <!DOC ...
- JavaScript:正则表达式 前瞻
正向前瞻:用来捕获出现在特定字符之前的字符,只有当字符后面跟着某个特定字符才去捕获它.(?=) 负向前瞻:它用匹配只有当字符后面不跟着某个特定字符时才去匹配它.(?!) 在执行前瞻和负向前瞻之类的运算 ...