UNPKG

1.14 kBJavaScriptView Raw
1goog.require('ol.Map');
2goog.require('ol.View');
3goog.require('ol.control');
4goog.require('ol.layer.Tile');
5goog.require('ol.source.BingMaps');
6goog.require('ol.source.OSM');
7
8var osm = new ol.layer.Tile({
9 source: new ol.source.OSM()
10});
11var bing = new ol.layer.Tile({
12 source: new ol.source.BingMaps({
13 key: 'As1HiMj1PvLPlqc_gtM7AqZfBL8ZL3VrjaS3zIb22Uvb9WKhuJObROC-qUpa81U5',
14 imagerySet: 'Aerial'
15 })
16});
17
18var map = new ol.Map({
19 layers: [osm, bing],
20 target: 'map',
21 controls: ol.control.defaults({
22 attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
23 collapsible: false
24 })
25 }),
26 view: new ol.View({
27 center: [0, 0],
28 zoom: 2
29 })
30});
31
32var swipe = document.getElementById('swipe');
33
34bing.on('precompose', function(event) {
35 var ctx = event.context;
36 var width = ctx.canvas.width * (swipe.value / 100);
37
38 ctx.save();
39 ctx.beginPath();
40 ctx.rect(width, 0, ctx.canvas.width - width, ctx.canvas.height);
41 ctx.clip();
42});
43
44bing.on('postcompose', function(event) {
45 var ctx = event.context;
46 ctx.restore();
47});
48
49swipe.addEventListener('input', function() {
50 map.render();
51}, false);