惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - 莫小龙

uniapp之plus.downloader.createDownload下载文件传参 谷歌之将网页保存为图片 elementui之table中相同数据的单元格合并 krpano之使用教程 threejs之灯光不跟随OrbitControls控制器旋转 threejs之将张纹理图片组成材质组 canvas之修改Base64图片中不透明部分的颜色 threejs之将PlaneGeometry转换为BufferGeometry threejs之利用shape通过线绘制面和体 threejs之添加渐变背景 threejs之创建发光墙体 arcmap之通过点数据获取等值线 uniapp之安卓APP打开百度地图、高德地图APP openlayer之添加带箭头的线 geoserver之图片图标样式 SHP转WKT文件工具 openlayers之geoserver的wms图层mysql数据源数据修改后更新问题 通过日照时数计算每天RAD(太阳辐射)值 Uniapp之安卓签名证书(.keystore)生成
paperjs之fitBounds适应区域前后屏幕坐标和输入坐标的转换
莫小龙 · 2025-06-11 · via 博客园 - 莫小龙

paperjs之fitBounds适应区域前后屏幕坐标和输入坐标的转换

使用经纬度区域边界创建场景并使用fitBounds将其适应在画布中,代码:

             const app_dom = this.$refs.paperRenderingCanvas;
            this.canvas = document.createElement("canvas");
            this.canvas.width = 1300;
            this.canvas.height = 800;
            let scope = new paper.PaperScope().setup(this.canvas);
            this.view = scope.view;
            this.view.backgroundColor = "white";      
            let viewSize = this.view.viewSize;
            let centerPoint = this.view.center;
            let project = scope.project;
            this.limitInitBounds = this.view.bounds.clone();
            app_dom?.appendChild(this.canvas);

  将边界加入场景中并适配到画布,获取适配前后的中心点和左上点(this.locSign、this.viewSign)用于计算转换

const group = new paper.Group()
const points = getInflectionPointList
const path = new paper.Path()
path.strokeWidth = 3
path.strokeColor = "rgb(120,120,120)"
path.closed = true
for (const point of points) {
      path.add(new paper.Point(point.longitude, point.latitude))
}
group1.addChild(path)
// 获取适配前的中心点和左上点
this.locSign = [group.bounds.centerX, group.bounds.centerY, group.bounds.left, group.bounds.top]
// 转换项目,使其边界适合指定的矩形,而不改变其纵横比。
group1.fitBounds(this.limitInitBounds);
group1.scale(1, -1)
// 获取适配后的中心点和左上点
this.viewSign = [group.bounds.centerX, group.bounds.centerY, group.bounds.left, group.bounds.top]

  转换工具代码:

        // 转换工具  屏幕坐标转经纬度坐标
        viewToLoc(x, y) {
            let lon = (this.locSign[2] - this.locSign[0]) * (x - this.viewSign[0]) / (this.viewSign[2] - this.viewSign[0]) + this.locSign[0]
            let lat = (this.viewSign[1] - y) * (this.locSign[3] - this.locSign[1]) / (this.viewSign[3] - this.viewSign[1]) + this.locSign[1]
            return [lon, lat]
        },
        // 转换工具  经纬度坐转标屏幕坐标
        locToView(lon, lat) {
            let x = (this.viewSign[2] - this.viewSign[0]) * (lon - this.locSign[0]) / (this.locSign[2] - this.locSign[0]) + this.viewSign[0]
            let y = - (this.viewSign[3] - this.viewSign[1]) * (lat - this.locSign[1]) / (this.locSign[3] - this.locSign[1]) + this.viewSign[1]
            return [x, y]
        },

  调用转换工具即可转换坐标。

。。。钻研不易,转载请注明出处