html5 canvas:服务器或客户端从经纬度快速转换为像素值

发布于 2024-09-10 17:58:18 字数 655 浏览 3 评论 0原文

我正在使用 html5 canvas 元素制作一些地图和动画(示例 在此处可见 .)我希望能够基于画布的几何形状有效地生成像素值线串(x1、y1、x2、y2),最好是从 PostGIS 生成。也就是说,在伪 geojson 中:

"Coordinates":"[[-122.0, 35.0], [-121.0, 36.0]]"

在函数传递 100px canvas-width 的情况下可能会输出参数:

"Pixels":"[[30, 40],[50,60]]"

我想最终启用如下网址:

www.example.com/canvas_size:200/ box_width:3-miles/center_point:lon|lat

所以我认为这必须动态完成。其他人是如何处理这种事情的?我突然想到,也许可以将整个世界视为一个 20,000,000 像素的画布,以像素形式存储预转换的数据,然后用客户端算术对其进行偏移。欢迎提出任何建议,包括远离我最初想法的方法。如果有人熟悉卡塔根是否或如何完成此操作,将不胜感激指向一个库或函数或两个的指针。

I am working on some maps and animations using the html5 canvas element (example visible here.) I would like to be able to efficiently generate pixel-valued linestrings (x1, y1, x2, y2), ideally from PostGIS, based on the geometry of the canvas. That is, in pseudo-geojson:

"Coordinates":"[[-122.0, 35.0], [-121.0, 36.0]]"

might output in the case of a function passed a 100px canvas-width parameter:

"Pixels":"[[30, 40],[50,60]]"

I would like to eventually enable urls like:

www.example.com/canvas_size:200/box_width:3-miles/center_point:lon|lat

so I assume this has to be done dynamically. How have other people tackled this kind of thing? It has occurred to me is to maybe treat the entire world as a 20,000,000 pixel canvas, store pre-transformed data in pixel form, then just offset it with client-side arithmetic. Any suggestions welcome, including approaches far afield of my first thoughts. If anyone is familiar with if or how this is done in Cartagen, would appreciate a pointer to a library or function or two.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说好的呢 2024-09-17 17:58:18

尝试以下代码,其中像素将适应画布的高度和宽度:

function getPoint(latitude, longitude, canvas_width, canvas_height) {
            var obj = {};
            obj.x = (latitude * canvas_height / 180.0) + (canvas_height / 2);
            obj.y = (longitude * canvas_width / 360.0) + (canvas_width / 2);
            return obj;
        }

Try this code where the pixels will adapt to the height and width of the canvas:

function getPoint(latitude, longitude, canvas_width, canvas_height) {
            var obj = {};
            obj.x = (latitude * canvas_height / 180.0) + (canvas_height / 2);
            obj.y = (longitude * canvas_width / 360.0) + (canvas_width / 2);
            return obj;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文