类名 util/extend/layer/vector/L.Renderer.js
import * as L from '@mapgis/leaflet'
// @link https://github.com/Raruto/leaflet-rotate
/**
 * L.Renderer
 */
const rendererProto = L.extend({}, L.Renderer.prototype)

L.Renderer.include({
  _updateTransform(center, zoom) {
    if (!this._map._rotate || this._map._bearing === 0) {
      return rendererProto._updateTransform.call(this, center, zoom)
    }
    // 更新缩放因子
    const scale = this._map.getZoomScale(zoom, this._zoom)
    // 计算左上角经纬度在当前层级下的像素偏移值
    // 注:计算值为相对于像素原点的偏移
    const offset = this._map._latLngToNewLayerPoint(this._topLeft, zoom, center)
    if (L.Browser.any3d) {
      L.DomUtil.setTransform(this._container, offset, scale)
    } else {
      L.DomUtil.setPosition(this._container, offset)
    }
  },

  _update() {
    // 初始状态较小层级下偏移问题,控制不旋转或this._map._bearing === 0时,默认逻辑
    if (!this._map._rotate || this._map._bearing === 0) {
      this._topLeft = this._map.containerPointToLatLng(
        this._map.getSize().multiplyBy(-this.options.padding)
      )
      return rendererProto._update.call(this)
    }
    // Update pixel bounds of renderer container (for positioning/sizing/clipping later)
    // Subclasses are responsible of firing the 'update' event.
    const p = this.options.padding
    const map = this._map
    const size = this._map.getSize()
    const padMin = size.multiplyBy(-p)
    const padMax = size.multiplyBy(1 + p)
    /// / TODO: Somehow refactor this out into map.something() - the code is
    /// /   pretty much the same as in GridLayer.
    const clip = new L.Bounds([
      map.containerPointToLayerPoint([padMin.x, padMin.y]).floor(),
      map.containerPointToLayerPoint([padMin.x, padMax.y]).floor(),
      map.containerPointToLayerPoint([padMax.x, padMin.y]).floor(),
      map.containerPointToLayerPoint([padMax.x, padMax.y]).floor()
    ])
    // min = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();

    this._bounds = clip
    this._topLeft = this._map.layerPointToLatLng(clip.min)

    this._center = this._map.getCenter()
    this._zoom = this._map.getZoom()
  }
})
构造函数
成员变量
方法
事件