将 Google Earth Engine 应用程序嵌入网页

2024-03-12

有没有一种更简单的方法可以将 Google Earth Engine (javascript) 应用程序嵌入到网页中,而无需遵循Google EE 演示应用程序 https://developers.google.com/earth-engine/app_engine_examples?

The 地球引擎代码 https://code.earthengine.google.com/环境使得开发核心 GEE 应用程序变得快速而快捷。然而,将 GEE 应用程序嵌入到网页中所花费的时间是制作 GEE 应用程序所需时间的 10 倍。

所有演示应用程序似乎都需要 (a) 使用谷歌应用引擎 https://developers.google.com/earth-engine/app_engine_intro,(b) 用 Python 重新编码 GEE 应用程序,(c) 使用 jinja2 模板引擎将 Python 代码链接到网页,以及 (d) 仍然有一些挥之不去的 JavaScript。

例如,在时尚灯光演示 https://trendy-lights-dot-ee-demos.appspot.com/,服务器端脚本编写器服务器.py https://github.com/google/earthengine-api/blob/master/demos/trendy-lights/server.pyApp Engine 启动了一切,很快就变得复杂起来。 (即使是更简单的演示也会走这条路。)

当用户第一次在浏览器中加载应用程序时,他们的 请求通过以下方式路由到 MainHandler 类中的 get() 函数 我们正在使用的框架,webapp2。

get() 函数返回主网页(来自index.html) 以及浏览器渲染 Earth Engine 地图所需的信息 以及要在地图上显示的多边形的 ID。该信息是 通过模板引擎注入到index.html模板中 称为 Jinja2,它将来自 Python 上下文的信息放入 HTML供用户的浏览器接收。


之所以复杂,是因为授权。 Earth Engine 调用必须针对某人的 Earth Engine 帐户进行授权。那必须是最终用户(参见:https://github.com/google/earthengine-api/tree/master/demos/client-auth https://github.com/google/earthengine-api/tree/master/demos/client-auth,但仅当最终用户拥有 Earth Engine 帐户)或应用程序的凭据时才有效。如果应用程序的凭据只是卡在 JavaScript 中,那么任何人都可以窃取这些凭据并使用它们做任何他们想做的事情。因此我们建议使用 appengine 服务器身份验证路由(https://github.com/google/earthengine-api/tree/master/demos/server-auth-nodejs https://github.com/google/earthengine-api/tree/master/demos/server-auth-nodejs)以确保您的凭据安全。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 Google Earth Engine 应用程序嵌入网页 的相关文章

随机推荐