Jinuss's blog Jinuss's blog
首页
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript高级程序设计》
    • 《Vue》
    • 《React》
    • 《Git》
    • JS设计模式总结
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • 学习
  • 实用技巧
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

东流

前端可视化
首页
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript高级程序设计》
    • 《Vue》
    • 《React》
    • 《Git》
    • JS设计模式总结
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • 学习
  • 实用技巧
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 框架

  • core模块

  • dom模块

  • control

  • geometry

    • Point
    • Bounds
    • Transformation
      • 概述
      • 源码分析
        • 源码实现
      • 总结
    • LineUtil
    • PolyUtil
  • geo

  • layer

  • Map

  • 《Leaflet源码》笔记
  • geometry
东流
2025-04-09
目录

Transformation

# 概述

Transformation 类在 Leaflet 中用于处理二维仿射变换,表示二维坐标的变换,它包含四个属性:_a、_b、_c 和 _d。这些属性用于表示变换矩阵的元素。

# 源码分析

# 源码实现

Transformation的源码实现如下:

// 构造函数
export function Transformation(a, b, c, d) {
  // a,c:表示x和y轴的缩放因子;b,d表示x和y轴的平移量
  if (Util.isArray(a)) {
    this._a = a[0];
    this._b = a[1];
    this._c = a[2];
    this._d = a[3];
    return;
  }
  this._a = a;
  this._b = b;
  this._c = c;
  this._d = d;
}

// 构造函数的原型上扩展方法
Transformation.prototype = {
  // 转换方法,将一个点进行变换,并返回变换后的点
  transform: function (point, scale) {
    // scale:缩放因子,默认为1
    return this._transform(point.clone(), scale);
  },
  _transform: function (point, scale) {
    scale = scale || 1;
    point.x = scale * (this._a * point.x + this._b);
    point.y = scale * (this._c * point.y + this._d);
    return point;
  },
  // 逆向变换,将变换后的点还原成原始坐标系
  untransform: function (point, scale) {
    scale = scale || 1;
    return new Point(
      (point.x / scale - this._b) / this._a,
      (point.y / scale - this._d) / this._c
    );
  },
};

// 工厂函数
export function toTransformation(a, b, c, d) {
  return new Transformation(a, b, c, d);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

# 总结

通过 Transformation 类,Leaflet 高效地处理了地图坐标的线性变换,支撑了地图瓦片加载、图层叠加等核心功能。

编辑 (opens new window)
上次更新: 2025/04/18, 07:17:03
Bounds
LineUtil

← Bounds LineUtil→

最近更新
01
GeoJSON
05-08
02
Circle
04-15
03
CircleMarker
04-15
更多文章>
Theme by Vdoing | Copyright © 2024-2025 东流 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式