Added TileUTFGrid example
This commit is contained in:
58
examples/tileutfgrid.html
Normal file
58
examples/tileutfgrid.html
Normal file
@@ -0,0 +1,58 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<link rel="stylesheet" href="../css/ol.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||
<title>TileUTFGrid example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="map" class="map"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
|
||||
<div class="span8">
|
||||
<h4 id="title">TileUTFGrid example</h4>
|
||||
<p id="shortdesc">This example shows how to read data from a TileUTFGrid layer.</p>
|
||||
<div id="docs">
|
||||
<p>Tiles made with <a href="http://tilemill.com/">TileMill</a>. Hosting on MapBox.com or with open-source <a href="https://github.com/klokantech/tileserver-php/">TileServer</a>.</p>
|
||||
<p>See the <a href="tileutfgrid.js" target="_blank">tileutfgrid.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">utfgrid, tileutfgrid, tilejson</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div id="info" class="alert alert-success">
|
||||
<img id="flag" src="" />
|
||||
<div id="admin_name"> </div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../resources/jquery.min.js" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
<script src="loader.js?id=tileutfgrid" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
46
examples/tileutfgrid.js
Normal file
46
examples/tileutfgrid.js
Normal file
@@ -0,0 +1,46 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.source.TileJSON');
|
||||
goog.require('ol.source.TileUTFGrid');
|
||||
|
||||
var mapLayer = new ol.layer.Tile({
|
||||
source: new ol.source.TileJSON({
|
||||
url: 'http://api.tiles.mapbox.com/v3/mapbox.geography-class.json'
|
||||
})
|
||||
});
|
||||
|
||||
var gridSource = new ol.source.TileUTFGrid({
|
||||
url: 'http://api.tiles.mapbox.com/v3/mapbox.geography-class.json',
|
||||
preemptive: true
|
||||
});
|
||||
|
||||
var gridLayer = new ol.layer.Tile({source: gridSource});
|
||||
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 1
|
||||
});
|
||||
|
||||
var mapElement = document.getElementById('map');
|
||||
var map = new ol.Map({
|
||||
layers: [mapLayer, gridLayer],
|
||||
target: mapElement,
|
||||
view: view
|
||||
});
|
||||
|
||||
var flag = document.getElementById('flag');
|
||||
var admin_name = document.getElementById('admin_name');
|
||||
map.on('pointermove', function(evt) {
|
||||
var viewResolution = /** @type {number} */ (view.getResolution());
|
||||
gridSource.forDataAtCoordinateAndResolution(evt.coordinate, viewResolution,
|
||||
function(data) {
|
||||
// If you want to use the template from the TileJSON,
|
||||
// load the mustache.js library separately and call
|
||||
// info.innerHTML = Mustache.render(gridSource.getTemplate(), data);
|
||||
mapElement.style.cursor = data ? 'pointer' : '';
|
||||
flag.src = data ? 'data:image/png;base64,' + data['flag_png'] : '';
|
||||
flag.style.visibility = data ? 'visible' : 'hidden';
|
||||
admin_name.innerHTML = data ? data['admin'] : ' ';
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user