zoukankan      html  css  js  c++  java
  • leaflet marker 旋转

    leaflet.markerRotation.js 代码(这段代码是从插件 leaflet.polylineDecorator.js 中复制的):

    // leaflet 实现 marker 旋转
    (function () {
        // save these original methods before they are overwritten
        var proto_initIcon = L.Marker.prototype._initIcon;
        var proto_setPos = L.Marker.prototype._setPos;
    
        var oldIE = (L.DomUtil.TRANSFORM === 'msTransform');
    
        L.Marker.addInitHook(function () {
            var iconOptions = this.options.icon && this.options.icon.options;
            var iconAnchor = iconOptions && this.options.icon.options.iconAnchor;
            if (iconAnchor) {
                iconAnchor = (iconAnchor[0] + 'px ' + iconAnchor[1] + 'px');
            }
            this.options.rotationOrigin = this.options.rotationOrigin || iconAnchor || 'center bottom';
            this.options.rotationAngle = this.options.rotationAngle || 0;
    
            // Ensure marker keeps rotated during dragging
            this.on('drag', function (e) { e.target._applyRotation(); });
        });
    
        L.Marker.include({
            _initIcon: function () {
                proto_initIcon.call(this);
            },
    
            _setPos: function (pos) {
                proto_setPos.call(this, pos);
                this._applyRotation();
            },
    
            _applyRotation: function () {
                if (this.options.rotationAngle) {
                    this._icon.style[L.DomUtil.TRANSFORM + 'Origin'] = this.options.rotationOrigin;
    
                    if (oldIE) {
                        // for IE 9, use the 2D rotation
                        this._icon.style[L.DomUtil.TRANSFORM] = 'rotate(' + this.options.rotationAngle + 'deg)';
                    } else {
                        // for modern browsers, prefer the 3D accelerated version
                        this._icon.style[L.DomUtil.TRANSFORM] += ' rotateZ(' + this.options.rotationAngle + 'deg)';
                    }
                }
            },
    
            setRotationAngle: function (angle) {
                this.options.rotationAngle = angle;
                this.update();
                return this;
            },
    
            setRotationOrigin: function (origin) {
                this.options.rotationOrigin = origin;
                this.update();
                return this;
            }
        });
    })();
    View Code

    引用 leaflet.markerRotation.js,然后就可以设置 marker 的旋转角度了:

    marker.setRotationOrigin('center center');
    marker.setRotationAngle(45);
    View Code

    参考github:

    https://github.com/bbecquet/Leaflet.RotatedMarker

  • 相关阅读:
    JIT动态编译器的原理与实现之Interpreter(解释器)的实现(三)
    java工作之后需要看的书籍
    WebService 之 REST vs SOAP
    消息队列
    dreamweaver cs6 的破解方法
    jquery mobile页面跳转后js不执行的问题
    JQueryMobile页面跳转参数的传递解决方案
    HTMl5的sessionStorage和localStorage
    phoneGap、JQueryMobile 简介及中文API地址
    Android 禁止响应屏幕翻转
  • 原文地址:https://www.cnblogs.com/s0611163/p/15603106.html
Copyright © 2011-2022 走看看