openlayer相关。。。。

点击地图的时候添加标注

this.map.on('singleclick',function(e){
            that.clickPoint = e.coordinate
            if (that.vectorSource) {
                that.vectorSource.clear()
            }
            let startMarker = new Feature({
                type: 'icon',
                geometry: new Point(e.coordinate)
            });
            //设置点要素样式
            startMarker.setStyle(new olStyle({
                image: new olIcon({
                    src: that.api + '/tool/star2.png'
                })
            }));
            //矢量标注的数据源
            that.vectorSource = new SourceVector({
                features: [startMarker]
            });
            //矢量标注图层
            let vectorLayer = new layerVector({
                source: that.vectorSource,
                zIndex:9999
            });
            console.log(vectorLayer)
            that.map.addLayer(vectorLayer);
        })

贴的图鼠标滑动时不能超过该框,需要给ol/View也设置extent,这样鼠标滑动图片时不会划出。
在这里插入图片描述

在框内的地图不随着鼠标移动的时候而移动

this.extent = [0, 0, 1024, 968];
        this.projection=new Projection({
            code: 'xkcd-image',
            units: 'pixels',
            extent: this.extent
        })
        this.view=new olView({
            // center:[510,480],
            projection: this.projection,
            zoom:1,
            maxZoom: 1,
            minZoom:1,
            extent: this.extent
        })
        this.map=new olMap({
            target:'map',
            view:this.view
        })

        //以下代码是禁止拖动地图
        let that = this; 
        let pan = getPan();
        pan.setActive(false);//false:当前地图不可拖动。true:可拖动
        function getPan() {
            let pan;
            that.map.getInteractions().forEach(function(element, index, array) {
                if(element instanceof DragPan) {
                    pan = element;
                }
            })
            return pan;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值