1 | goog.require('ol.Map');
|
2 | goog.require('ol.View');
|
3 | goog.require('ol.control');
|
4 | goog.require('ol.layer.Tile');
|
5 | goog.require('ol.source.BingMaps');
|
6 | goog.require('ol.source.OSM');
|
7 |
|
8 | var osm = new ol.layer.Tile({
|
9 | source: new ol.source.OSM()
|
10 | });
|
11 | var bing = new ol.layer.Tile({
|
12 | source: new ol.source.BingMaps({
|
13 | key: 'As1HiMj1PvLPlqc_gtM7AqZfBL8ZL3VrjaS3zIb22Uvb9WKhuJObROC-qUpa81U5',
|
14 | imagerySet: 'Aerial'
|
15 | })
|
16 | });
|
17 |
|
18 | var map = new ol.Map({
|
19 | layers: [osm, bing],
|
20 | target: 'map',
|
21 | controls: ol.control.defaults({
|
22 | attributionOptions: ({
|
23 | collapsible: false
|
24 | })
|
25 | }),
|
26 | view: new ol.View({
|
27 | center: [0, 0],
|
28 | zoom: 2
|
29 | })
|
30 | });
|
31 |
|
32 | var swipe = document.getElementById('swipe');
|
33 |
|
34 | bing.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 |
|
44 | bing.on('postcompose', function(event) {
|
45 | var ctx = event.context;
|
46 | ctx.restore();
|
47 | });
|
48 |
|
49 | swipe.addEventListener('input', function() {
|
50 | map.render();
|
51 | }, false);
|