1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_layerSwitch"></title>
- <script type="text/javascript" src="../js/include-web.js"></script>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:95%; position: absolute;top: 0;">
- <div id="map" style="width: 100%;height:95%"></div>
- <input id="swipe" type="range" style="width: 100%;">
- <script type="text/javascript">
- var host = window.isLocal ? window.server : "https://iserver.supermap.io";
- var worldurl = host + '/iserver/services/map-world/rest/maps/World',
- worldNighturl = host + '/iserver/services/map-world/rest/maps/世界地图_Night';
- var world = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest({
- url: worldurl
- }),
- projection: 'EPSG:4326'
- });
- var worldNight = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest({
- url: worldNighturl
- }),
- projection: 'EPSG:4326'
- });
- var map = new ol.Map({
- layers: [world, worldNight],
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}}),
- view: new ol.View({
- center: [0, 0],
- zoom: 3,
- projection: 'EPSG:4326',
- multiWorld: true
- })
- });
- var swipe = document.getElementById('swipe');
- // ol6 废除了 precompose,由 prerender 事件替换
- worldNight.on('prerender', function (event) {
- var ctx = event.context;
- 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();
- });
- // ol6 废除了 postcompose,由 postrender 事件替换
- worldNight.on('postrender', function (event) {
- var ctx = event.context;
- ctx.restore();
- });
- swipe.addEventListener('input', function () {
- map.render();
- }, false);
- </script>
- </body>
- </html>
|