Map_feature_sql.vue 3.3 KB
<!--
 * @Author: jiangbotao
 * @Date: 2019-12-10 14:16:04
 * @LastEditors: jiangbotao
 * @LastEditTime: 2019-12-10 14:56:09
 * @FilePath: \mymapbox\src\components\Map_filter_sql.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: 'HelloWorld',
    data () {
        return {
        
        }
    },
    mounted(){ 
        var map, host = "http://support.supermap.com.cn:8090";
        var url = host + "/iserver/services/map-world/rest/maps/World";
        var dataUrl = host + "/iserver/services/data-world/rest/data";

        var map = new mapboxgl.Map({
            container: 'map',
            style: {
                "version": 8,
                "sources": {
                    "raster-tiles": {
                        "attribution": 'attribution',
                        "type": "raster",
                        "tiles": [host + '/iserver/services/maps/rest/maps/World/zxyTileImage.png?prjCoordSys={"epsgCode":3857}&z={z}&x={x}&y={y}'],
                        "tileSize": 256,
                    },
                },
                "layers": [{
                    "id": "simple-tiles",
                    "type": "raster",
                    "source": "raster-tiles",
                    "minzoom": 0,
                    "maxzoom": 22
                }],
            },
            center: [110.143, 30.236],
            maxZoom: 18,
            zoom: 2
        });
        map.addControl(new Logo(), 'bottom-right');
        map.addControl(new mapboxgl.NavigationControl(), 'top-left');

        map.on('load', function () {
            query();
        });

        function query() {
            // 指定 SQL 查询即在指定数据集集合中查找符合 SQL 条件的矢量要素
            // 并在客户端中展示出来
            var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
                queryParameter: {
                    name: "Countries@World",
                    attributeFilter: "SMID = 247"
                },
                datasetNames: ["World:Countries"]
            });

            new FeatureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) {
                map.addSource("queryDatas", {
                    "type": "geojson",
                    "data": serviceResult.result.features
                });
                map.addLayer({
                    "id": "queryDatas",
                    "type": "fill", /* fill类型一般用来表示一个面,一般较大 */
                    "source": "queryDatas",
                    "paint": {
                        "fill-color": "#FF3300", /* 填充的颜色 */
                        "fill-opacity": 0.6      /* 透明度 */
                    },
                });
                map.on('click', 'queryDatas', function (e) {
                    new mapboxgl.Popup()
                        .setLngLat(e.lngLat)
                        .setHTML(e.features[0].properties.SMID + ":" + e.features[0].properties.COUNTRY)
                        .addTo(map);
                });
            });
        }
    }
}
</script>

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