Map_split.vue 2.98 KB
<!--
 * @Author: jiangbotao
 * @Date: 2019-12-09 23:17:48
 * @LastEditors: jiangbotao
 * @LastEditTime: 2019-12-10 16:24:38
 * @FilePath: \mymapbox\src\components\Map3857.vue
 -->
<template>
    <div >
        <div id='before' class='map'></div>
        <div id='after' class='map'></div>
    </div>
</template>

<script>
import mapboxgl from 'mapbox-gl';
import Compare from 'mapbox-gl-compare';
import { Logo, MapService } from '@supermap/iclient-mapboxgl';
export default {
    name: 'HelloWorld',

    data () {
        return {
        
        }
    },
    mounted(){ 
        var host = "http://support.supermap.com.cn:8090",
        chinaUrl = host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}',
        chinaDarkUrl = host + '/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}',
        attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
            " with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
            " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
        var beforeMap = new mapboxgl.Map({
            container: 'before',
            style: {
                "version": 8,
                "sources": {
                    "raster-tiles": {
                        "attribution": attribution,
                        "type": "raster",
                        "tiles": [chinaUrl],
                        "tileSize": 256,
                    },
                },
                "layers": [{
                    "id": "before",
                    "type": "raster",
                    "source": "raster-tiles",
                    "minzoom": 0,
                    "maxzoom": 22
                }],
            },
            center: [0, 0],
            zoom: 0
        });
        beforeMap.addControl(new mapboxgl.NavigationControl(), 'top-left');
        var afterMap = new mapboxgl.Map({
            container: 'after',
            style: {
                "version": 8,
                "sources": {
                    "raster-tiles": {
                        "type": "raster",
                        "tiles": [chinaDarkUrl],
                        "tileSize": 256,
                    },
                },
                "layers": [{
                    "id": "after",
                    "type": "raster",
                    "source": "raster-tiles",
                    "minzoom": 0,
                    "maxzoom": 22
                }],
            },
            center: [0, 0],
            zoom: 0
        });

        //mapbox 卷帘(对比)控件
        var map = new mapboxgl.Compare(beforeMap, afterMap, {
            // Set this to enable comparing two maps by mouse movement:
            // mousemove: true
        });
    }
}
</script>

<style scoped>
.map {
  position: absolute;
  height: 100%;
  width: 100%;
  background-color: white
}
</style>