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

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

export default {
    name: 'MVT',
    data () {
        return {
            map: null
        }
    },
    mounted(){ 
        this.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: 3,
            // pitch: 45,
            // bearing: -10
        });
        this.map.addControl(new mapboxgl.NavigationControl(), 'top-left');
        var __this = this;
        this.map.on('load', function () {
            // console.log(map.getStyle().sources);
            // console.log(map.getStyle().layers);
            __this.map.setPaintProperty('WorldElements_R@China', 'fill-color', '#a1dab4');
            __this.map.setPaintProperty('River_R@China', 'fill-color', '#fcfcfc');

            var dataUrl = 'http://127.0.0.1:8090/iserver/services/data-China/rest/data/';
            var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
                queryParameter: {
                    name: "point2",
                    attributeFilter: "SMID > 0",
                },
                datasetNames: ["China:point2"],
                maxFeatures: 1000,
                toIndex: -1
            });
            var featureService = new mapboxgl.supermap.FeatureService(dataUrl);
            var features = null;
            
            featureService.getFeaturesBySQL(sqlParam, function (serviceResult) {
                features = serviceResult.result.features;
                console.log(features);
                
                __this.map.addSource("queryDatas", {
                    "type": "geojson",
                    "data": features
                });
                
                __this.map.addLayer({
                    "id": "queryDatasLayer",
                    "type": "circle",
                    "source": "queryDatas",
                    "paint": {
                        'circle-radius': 4,
                        'circle-color': [
                            'match',
                            ['get', 'TYPE'],
                            'A',
                            '#fbb03b',
                            'B',
                            '#223b53',
                            'C',
                            '#e55e5e',
                            'D',
                            '#3bb2d0',
                            /* other */ '#ccc'
                        ],
                        'circle-opacity': 1.0,
                        "circle-stroke-width": 2,
                        "circle-stroke-color": "#007cbf",
                        "circle-stroke-opacity": 0.7
                    }
                });
                var popup = new mapboxgl.Popup({
                    anchor: 'bottom',
                    closeButton: false,
                    offset: {
                        'bottom': [0, -20],
                    }
                });
                __this.map.on('mousemove', "queryDatasLayer", function (e) {
                    popup.setLngLat(e.lngLat).setHTML(e.features[0].properties.NAME+':'+ e.features[0].properties.VALUE).addTo(__this.map);
                    __this.map.getCanvas().style.cursor = 'pointer';

                });
                __this.map.on('mouseout', "queryDatasLayer", function () {
                    __this.map.getCanvas().style.cursor = '';
                    popup.remove();
                })
            });
        });
    }
}
</script>

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