【WebGIS bug】WARNING: Too many active WebGL contexts. Oldest context will be lost.

多次使用多屏对比功能给页面添加图形,然后报错WARNING: Too many active WebGL contexts. Oldest context will be lost.

在这里插入图片描述

在这里插入图片描述

<template>
    <div class="grid-container" v-show="this.$store.getters._getDefaultDpdbVisible">
        <div id="dpdb_id1" class="item1"></div>
        <div id="dpdb_id2" class="item2"></div>
        <div id="dpdb_id3" class="item3"></div>
        <div id="dpdb_id4" class="item4"></div>
    </div>
</template>

<script>
import MapView from '@arcgis/core/views/MapView';
export default {
    data() {
        return {
            aa: '',
            // views: [], //多屏对比的views
            dpdbViews: [],
        };
    },
    watch: {
        '$store.getters._getDefaultDpdbVisible'(newVal, oldVal) {
            console.log('如果v-show为真,就初始化地图');
            console.log('新值: ' + newVal + '  ' + '旧值: ' + oldVal);

            this.initView();
            if (oldVal) {
                console.log('aa');
            }
        },
    },

    mounted() {
        // this.initView();
    },
    methods: {
        //如果v-show为真,就初始化地图
        async initView() {
            //清除之前的view
            this.dpdbViews = [];
            // console.log(dpdbViews);
            const yuanshiView = this.$store.getters._getDefaultMapView;
            //定义四个新的view
            // const dpdbViews = this.dpdbViews;
            //根据需要来创建多个视图并绑定地图容器div的id
            for (let i = 1; i < 5; i++) {
                const dpdbView = new MapView({
                    map: yuanshiView.map,
                    zoom: yuanshiView.zoom,
                    extent: yuanshiView.extent,
                    container: 'dpdb_id' + i, //指定容器
                });
                dpdbView.ui.components = [];
                this.dpdbViews.push(dpdbView);
            }
            // console.log(dpdbViews);
            // 多屏联动
            this.dpdbViews.forEach((view) => {
                console.log(view);
                var fullExtent = null;
                console.log(this);
                view.on('mouse-wheel', (e) => {
                    console.log(this);
                    //延迟获取范围的函数
                    // window.setTimeout(function () {
                    //     //获取操作图层的范围
                    //     console.log(this);

                    //     fullExtent = view.extent;
                    //     //遍历所有视图来设置这个范围
                    //     dpdbViews.forEach(function (nview) {
                    //         nview.extent = fullExtent;
                    //     });
                    // }, 10);
                    fullExtent = view.extent;
                    //遍历所有视图来设置这个范围
                    this.dpdbViews.forEach((nview) => {
                        nview.extent = fullExtent;
                        console.log(this);
                    });
                });
                //设置鼠标拖拽事件
                view.on('drag', (e) => {
                    //获取操作图层的范围
                    fullExtent = view.extent;
                    //遍历所有视图来设置这个范围
                    this.dpdbViews.forEach(function (nview) {
                        nview.extent = fullExtent;
                    });
                });
            });
        },
    },
};
</script>

<style>
.grid-container {
    position: absolute;
    display: grid;
    height: 100%;
    width: 100%;
    background-color: aqua;
    grid-template-columns: auto auto;
    grid-gap: 5px;
    background-color: rgb(3 8 41);
    padding: 0px;
}
.grid-container > div {
    background-color: rgba(255, 255, 255, 0.8);
    text-align: center;
    padding: 0 0;
    font-size: 30px;
}
</style>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老靳的WebGIS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值