Map_wz.vue 2.75 KB
<!--
 * @Author: jiangbotao
 * @Date: 2019-12-10 22:15:53
 * @LastEditors: jiangbotao
 * @LastEditTime: 2019-12-12 17:31:11
 * @FilePath: \supermapvue\src\components\vt\Map_wz.vue
 -->
<template>
    <div >
        <div id="map"></div>
    </div>
</template>

<script>
import mapboxgl from 'mapbox-gl';
import { Logo } from '@supermap/iclient-mapboxgl';

export default {
    name: 'MVT',
    data () {
        return {
        
        }
    },
    mounted(){ 
        // var url = "http://127.0.0.1:8090/iserver/services/map-mvt-China_Dark/rest/maps/China_Dark/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true";
        // $.ajax({
        //     url:url,
        //     success:function(mvtStyle){
        //         var zoom = mvtStyle.zoom == null ? minZoomLevel : mvtStyle.zoom;
        //         var map = new mapboxgl.Map({
        //             container: 'map', // container id
        //             style: mvtStyle,
        //             center: [-1, -2],// starting position
        //             zoom: 4, // starting zoom
        //             minZoom: 0,
        //             maxZoom: 5,
        //             crs: "EPSG:4490"
        //         });
        //         map.addControl(new mapboxgl.NavigationControl(), 'top-left');
        //         // map.setStyle({
        //         //     style: {
        //         //         layers: [
        //         //             {
        //         //                 "id": "background",
        //         //                 "type": "background",
        //         //                 "layout": {},
        //         //                 "paint": {
        //         //                     "background-color": "#fcfcfc"
        //         //                 }
        //         //             }
        //         //         ]
        //         //     }
        //         // }, {diff: false});
        //     }
        // });
        var map = new mapboxgl.Map({
            container: 'map', // container id
            style: 
                'http://127.0.0.1:8090/iserver/services/map-mvt-China_Dark/rest/maps/China_Dark/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true',
            center: [116.4, 39.9],
            minZoom: 0,
            zoom: 5
        });
        map.addControl(new mapboxgl.NavigationControl(), 'top-left');
        map.on('load', function () {
            console.log(map.getStyle().layers);
            map.setPaintProperty('WorldElements_R@China', 'fill-color', '#a1dab4');
            map.setPaintProperty('Country_R@China', 'fill-color', '#f03b20');
            map.setPaintProperty('Province_R@China', 'fill-color', '#fd8d3c');
        });
    }
}
</script>

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