viewer_spatialquery_tl.vue 8.08 KB
<!--
 * 空间查询
 * 二维结果面形成entity
 * @Author: jiangbotao
 * @Date: 2019-12-03 22:52:56
 * @LastEditors: jiangbotao
 * @LastEditTime: 2019-12-10 10:40:00
 * @FilePath: \superglobevue\src\components\viewer.vue
 -->
<template>
    <div>
		<div id="cesiumContainer" v-bind:style="styleObject"></div>
		<div id='loadingbar' class="spinner">
			<div class="spinner-container container1">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
			<div class="spinner-container container2">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
			<div class="spinner-container container3">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
		</div>
        <div id="toolbar" class="param-container tool-bar">
			<div>
				<button id="search" >查询</button>
			</div>
		</div>
	</div>
</template>

<script>
import URL_CONFIG from "./../config/urlConfig.vue";
const Cesium = window.Cesium;
const SuperMap = window.SuperMap;
export default {
    data: function() {
        return {
            styleObject: {
                width: "100%",
                position: "absolute",
                top: "0px",
                bottom: "0px",
                left: "0px",
                backgroundColor: "#000000"
            },
            smviewer: {}
        };
    },
    mounted: function() {
        var __this = this;
        __this.viewer = new Cesium.Viewer('cesiumContainer', { animation: true });
        var scene = __this.viewer.scene;
        var widget = __this.viewer.cesiumWidget;
        var camera = scene.camera;
        // 隐藏logo
        $(".cesium-widget-credits")[0].style.visibility = "hidden";
        $(".cesium-viewer-animationContainer")[0].style.visibility="hidden";
        $(".cesium-infoBox")[0].style.visibility='hidden';
        // 隐藏导航工具
        // $(".cesium-viewer-navigationContainer")[0].style.visibility="hidden";

        try {
           var promise2 = scene.addS3MTilesLayerByScp("http://www.supermapol.com/realspace/services/3D-dynamicDTH/rest/realspace/datas/Config%20-%201/config", 
                { name: "oblique photography" });
            Cesium.when([promise2], function(layers) {
                camera.setView({ 
                    destination : new Cesium.Cartesian3(-2623004.4174251584, 3926981.958360567, 4287374.829655093),
                    orientation : {
                        heading: 4.39611370540786,
                        pitch : -0.43458664812464143,
                        roll : 2.0174972803488345e-11
                    }
                });
                // 去除加载动画
                $('#loadingbar').remove();

                var positions = null;
				// 绘制面
                var handlerPolygon = new Cesium.DrawHandler(__this.viewer, Cesium.DrawMode.Polygon, 0);
				handlerPolygon.drawEvt.addEventListener(function(polygon){
                    var points = polygon.object.positions;
                    var arr = [];
                    if(points && points instanceof Array && points.length >= 3){
                        for(var i = 0, j = points.length; i < j; i++){
                            var point = __this.convertPoint(points[i]);
                            if(point){
                                arr.push(point);
                            }
                        }
                    }
                    var linearRing = new SuperMap.Geometry.LinearRing(arr);
                    var searchPolygon = new SuperMap.Geometry.Polygon(linearRing);
                    query(searchPolygon);
                });
                $("#search").on("click", function(){
					handlerPolygon.activeEvt.addEventListener(function(isActive){
						if(isActive === true){
							__this.viewer.enableCursorStyle = false;
							__this.viewer._element.style.cursor = '';
							$('body').removeClass('drawCur').addClass('drawCur');
						}else{
							__this.viewer.enableCursorStyle = true;
							$('body').removeClass('drawCur');
						}
					});
					handlerPolygon && handlerPolygon.deactivate();
                    handlerPolygon && handlerPolygon.activate();
                });
                function processCompleted(queryEventArgs){
                    var selectedFeatures = queryEventArgs.originResult.features;
                    __this.viewer.entities.removeAll();
                    
                    console.log(selectedFeatures);
                    for(var i = 0; i < selectedFeatures.length; i++){
                        var value = selectedFeatures[i].fieldValues["0"];
                        var feature = selectedFeatures[i];
                        var pts = [];
                        for(var j=0; j< feature.geometry.points.length; j++){
                            pts.push(feature.geometry.points[j].x);
                            pts.push(feature.geometry.points[j].y);
                        }
                        __this.viewer.entities.add({
                            id: value,
                            name: selectedFeatures[i].fieldValues["0"],
                            polygon: {
                                hierarchy: Cesium.Cartesian3.fromDegreesArray(pts),
                                material: new Cesium.Color(0.0, 1.0, 0.0, 0.3),
                                extrudedHeight: 100,
                                height: 50,
                                vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
                                outline : true,
                                outlineColor : Cesium.Color.BLACK
                            },
                        });
                    }
                }
                function query(drawGeometryArgs){
                    var getFeaturesByGeometryParameters, getFeaturesByGeometryService;
                    getFeaturesByGeometryParameters = new SuperMap.REST.GetFeaturesByGeometryParameters({
                        datasetNames: ["铁岭矢量面:New_Region3D_1"],
                        toIndex:-1,
                        spatialQueryMode:SuperMap.REST.SpatialQueryMode.INTERSECT,
                        geometry: drawGeometryArgs
                    });
                    var url = 'http://www.supermapol.com/realspace/services/data-dynamicDTH/rest/data';
                    getFeaturesByGeometryService = new SuperMap.REST.GetFeaturesByGeometryService(url, {
                        eventListeners: {
                            "processCompleted": processCompleted,
                            "processFailed": processFailed
                        }
                    });
                    getFeaturesByGeometryService.processAsync(getFeaturesByGeometryParameters);
                }
                function processFailed(e) {
                    alert(e.error.errorMsg);
                }
            }, function() {
                var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                widget.showErrorPanel(title, undefined, e);
            });
        } catch (e) {
            if (widget._showRenderLoopErrors) {
                var title = '渲染时发生错误,已停止渲染。';
                widget.showErrorPanel(title, undefined, e);
            }
        }

        $("#loadingbar").remove();
    },
    methods:{
        convertPoint : function(point){
            var lonlatPoint = Cesium.Cartographic.fromCartesian(point);
            var x = Cesium.Math.toDegrees(lonlatPoint.longitude);
            var y = Cesium.Math.toDegrees(lonlatPoint.latitude);
            if(x && y){
                return new SuperMap.Geometry.Point(x, y);
            }
            return undefined;
        }
    }
};
</script>

<style>
.sm-compass {
    pointer-events: auto;
    position: absolute;
    right: 10px;
    top: 10px;
    width: 128px;
    height: 128px;
    overflow: hidden;
}
.sm-zoom {
	top: 130px;
}
.drawCur{
	cursor: url(/images/cur/draw.cur), auto;
}
.cesium-infoBox{
    top: 20;
    left: 0;
    transition: opacity 0.2s;
}
</style>