    import * as L from '@mapgis/leaflet'
    // @link https://github.com/Raruto/leaflet-rotate
    /**
     * L.Popup
     */
    const popupProto = L.extend({}, L.Popup.prototype)

    L.Popup.include({
      _animateZoom(e) {
        if (!this._map._rotate) {
          popupProto._animateZoom.call(this, e)
        }
        let pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center)
        const anchor = this._getAnchor()

        pos = this._map.rotatedPointToMapPanePoint(pos)

        L.DomUtil.setPosition(this._container, pos.add(anchor))
      },

      _adjustPan() {
        if (
          !this.options.autoPan ||
          (this._map._panAnim && this._map._panAnim._inProgress)
        ) {
          return
        }

        const map = this._map
        const marginBottom =
          parseInt(L.DomUtil.getStyle(this._container, 'marginBottom'), 10) || 0
        const containerHeight = this._container.offsetHeight + marginBottom
        const containerWidth = this._containerWidth
        const layerPos = new L.Point(
          this._containerLeft,
          -containerHeight - this._containerBottom
        )

        layerPos._add(L.DomUtil.getPosition(this._container))

        // var containerPos = map.layerPointToContainerPoint(layerPos);
        // TODO: use popupProto._adjustPan
        const containerPos = layerPos._add(this._map._getMapPanePos())
        const padding = L.point(this.options.autoPanPadding)
        const paddingTL = L.point(this.options.autoPanPaddingTopLeft || padding)
        const paddingBR = L.point(this.options.autoPanPaddingBottomRight || padding)
        const size = map.getSize()
        let dx = 0
        let dy = 0

        if (containerPos.x + containerWidth + paddingBR.x > size.x) {
          // right
          dx = containerPos.x + containerWidth - size.x + paddingBR.x
        }
        if (containerPos.x - dx - paddingTL.x < 0) {
          // left
          dx = containerPos.x - paddingTL.x
        }
        if (containerPos.y + containerHeight + paddingBR.y > size.y) {
          // bottom
          dy = containerPos.y + containerHeight - size.y + paddingBR.y
        }
        if (containerPos.y - dy - paddingTL.y < 0) {
          // top
          dy = containerPos.y - paddingTL.y
        }

        // @namespace Map
        // @section Popup events
        // @event autopanstart: Event
        // Fired when the map starts autopanning when opening a popup.
        if (dx || dy) {
          map.fire('autopanstart').panBy([dx, dy])
        }
      }
    })