leaflet 缩放动画 (自定义弹窗)

leaflet 缩放动画

默认方法

  • zoomanim事件与_zoomAnimation方法与默认类名leaflet-zoom-animated;
// 自定义覆盖物类
var CustomOverlay = L.Layer.extend({
    initialize: function(content, options) {
        this._content = content;
        L.setOptions(this, options);
    },

    onAdd: function(map) {
        this._map = map;
        this._container = L.DomUtil.create('div', 'custom-overlay leaflet-zoom-animated');
        this._container.style.position = 'absolute';
        this._container.style.zIndex = 101;
        this._container.innerHTML = this._content;
        map.getPanes().overlayPane.appendChild(this._container);
        if (L.Browser.any3d) {
            map.on("zoomanim", this._zoomAnimation, this); //默认动画效果与类名leaflet-zoom-animated搭配使用。
        }
        this._initposition();

    },
    onRemove: function() {
        map.off({
                zoomanim: this._zoomAnimation,
            },
            this
        );
        this._container.remove();
    },
    _zoomAnimation: function(a) {
        var point = this._map._latLngToNewLayerPoint(this.options.position, a.zoom, a.center);
        point.y = point.y - 150;
        point.x = point.x - 26;
        L.DomUtil.setTransform(this._container, point);
    },
    _initposition: function() {
        var point = this._map.latLngToLayerPoint(this.options.position);
        point.y = point.y - 150;
        point.x = point.x - 26;
        L.DomUtil.setTransform(this._container, point);
    }
});

export default CustomOverlay;

自定义方法

  • zoomstart 与 zoomend事件搭配css过渡实现;
// 自定义覆盖物类
var CustomOverlay = L.Layer.extend({
    initialize: function(content, options) {
        this._content = content;
        L.setOptions(this, options);
    },

    onAdd: function(map) {
        this._map = map;
        this._container = L.DomUtil.create('div', 'custom-overlay');
        this._container.style.position = 'absolute';
        this._container.style.zIndex = 101;
        this._container.innerHTML = this._content;
        map.getPanes().overlayPane.appendChild(this._container);

        this._initposition();

        map.on('zoomend', () => {
            this._zoomAnimation();
            this._container.classList.remove('zoom-animating');
        });

        map.on('zoomstart', () => {
            this._initposition();
            this._container.classList.add('zoom-animating');
        });


    },
    onRemove: function() {
        this._container.remove();
    },
    _zoomAnimation: function(a) {
        let point = { x: 100, y: 88 }
        L.DomUtil.setTransform(this._container, point);
    },
    _initposition: function() {
        let point = { x: 900, y: 88 }
        L.DomUtil.setTransform(this._container, point);
    }
});

export default CustomOverlay;
.zoom-animating  {
  -webkit-transition: -webkit -transform 0.25s cubic-bezier(0, 0, 0.25, 1);
  -moz-transition: -moz-transform 0.25s cubic-bezier(0, 0, 0.25, 1);
  transition: transform 0.25s cubic-bezier(0, 0, 0.25, 1);
}

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值