openlayers加载天地图

一、openlayers加载天地图

 let that = this;
            //普通地图
            that.layer.tiandituVecLayer = new TileLayer({
                title: 'generalMap',
                source: new XYZ({
                    url: 'http://t3.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=daafafd5b7bb42922f10e3d1c06df824',
                    crossOrigin: 'anonymous'
                }),
                visible:false
            });
            // 卫星影像图层
            that.layer.tiandituImgLayer = new TileLayer({
                title:'yx',
                source: new XYZ({
                    url: 'http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=fea556436d51919f4a429933897be3c1',
                    crossOrigin: 'anonymous',
                }),
                visible:true
            });
            //普通地图标记
            that.layer.tiandituCvaLayer = new TileLayer({
                title: 'generalMapZj',
                source: new XYZ({
                    url: 'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=daafafd5b7bb42922f10e3d1c06df824',
                    crossOrigin: 'anonymous'
                }),
                visible: true
            });
            let container = document.getElementById('popup');
            let  content = document.getElementById('popup-content');
            let  closer = document.getElementById('popup-closer');
            closer.onclick = function () {
                that.overlay.setPosition(undefined);
                closer.blur();
                return false;
            };
            this.overlay = new Overlay({
                element: container,
                autoPan: true,
                autoPanAnimation: {
                    duration: 250,
                },
            });
            this.map = new Map({
                target: 'map',
                // interactions: defaultInteractions().extend([modify]),
                overlays: [that.overlay],
                layers: [
                    that.layer.tiandituImgLayer,
                    that.layer.tiandituVecLayer,
                    that.layer.tiandituCvaLayer
                ],
                view: new View({
                    // projection: 'EPSG:4326',
                    // center: [120.4750, 31.6337],
                    center:[13410926.774433982,3715530.4937355495],
                    zoom: 12,
                }),
                controls: defaults({
                    zoom:false,
                    attributionOptions: {
                        collapsible: false
                    }
                })
            });
            this.$root._olMap = this.map;

二、地图点击事件

 let that = this;
            //地图点击事件
            this.map.on('singleclick', function (evt) {
                //点击获取经纬度
                console.log(evt.coordinate);
                // console.log(ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326'));
                //判断当前单击处是否有要素,捕获到要素时弹出popup
                let thisFeature = that.map.forEachFeatureAtPixel(evt.pixel, function (fea, layer) {
                    return fea;
                });
                let thisLayer = that.map.forEachLayerAtPixel(evt.pixel, function (layer) {
                    return layer;
                });
                if (that.pointSelect){
                    that.map.removeLayer(that.pointSelect);
                    that.pointSelect=null;
                    that.overlay.setPosition(undefined);
                    that.modalShow1=false;
                    that.modalShow=false;
                }
                that.pointSelect = new VectorLayer({
                    className:"pointSelect",
                    title: "pointSelect",
                    source: new VectorSource({
                        features: [thisFeature]
                    }),
                    style:new Style({
                        //填充色
                        fill: new Fill({
                            color: 'rgba(255,0,0,0.3)'
                        }),
                        //边线颜色
                        stroke: new Stroke({
                            color: 'rgba(255,0,0,0.8)',
                            width: 4
                        }),
                        //形状
                        image: new Circle({
                            radius: 7,
                            fill: new Fill({
                                color: '#ffcc33'
                            })
                        })
                    }),
                    zIndex:1000
                })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小仙有礼了

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

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

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

打赏作者

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

抵扣说明:

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

余额充值