Add layer-swipe example
This commit is contained in:
committed by
Tom Payne
parent
b698c5bf7b
commit
d65ae078ef
51
examples/layer-swipe.html
Normal file
51
examples/layer-swipe.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!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>Layer Swipe 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>
|
||||
<input id="swipe" type="range" style="width: 100%">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
|
||||
<div class="span12">
|
||||
<h4 id="title">Layer Swipe example</h4>
|
||||
<p id="shortdesc">Example of a Layer swipe map.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="layer-swipe.js" target="_blank">layer-swipe.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">swipe, openstreetmap</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="loader.js?id=layer-swipe" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
47
examples/layer-swipe.js
Normal file
47
examples/layer-swipe.js
Normal file
@@ -0,0 +1,47 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.source.BingMaps');
|
||||
goog.require('ol.source.OSM');
|
||||
|
||||
var osm = new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
});
|
||||
var bing = new ol.layer.Tile({
|
||||
source: new ol.source.BingMaps({
|
||||
key: 'Ak-dzM4wZjSqTlzveKz5u0d4IQ4bRzVI309GxmkgSVr1ewS6iPSrOvOKhA-CJlm3',
|
||||
style: 'Aerial'
|
||||
})
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [osm, bing],
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: [0, 0],
|
||||
zoom: 2
|
||||
})
|
||||
});
|
||||
|
||||
var swipe = document.getElementById('swipe');
|
||||
|
||||
bing.on('precompose', function(event) {
|
||||
var ctx = event.getContext();
|
||||
var width = ctx.canvas.width * (swipe.value / 100);
|
||||
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.rect(width, 0, ctx.canvas.width - width, ctx.canvas.height);
|
||||
ctx.clip();
|
||||
});
|
||||
|
||||
bing.on('postcompose', function(event) {
|
||||
var ctx = event.getContext();
|
||||
ctx.restore();
|
||||
});
|
||||
|
||||
swipe.addEventListener('change', function() {
|
||||
map.requestRenderFrame();
|
||||
}, false);
|
||||
Reference in New Issue
Block a user