如何确定 Google Maps loadGeoJson 何时完成? [英] how can I determine when Google Maps loadGeoJson completes?

查看:20
本文介绍了如何确定 Google Maps loadGeoJson 何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,用户可以在其中存储他们的映射样式.当用户导航回带有地图的页面时,它应该以以前的方式显示地图.

用户可以根据人口统计信息更改地理和边界的颜色以及应用主题样式.

随着新的 loadGeoJson 的发布,我在加速我的应用程序方面取得了巨大的成功,最初我是通过 JS 自己绘制所有的地理区域.这导致了大约 1500 个地理区域的一些内存问题.这个新功能大大减少了它.我选择在服务器端生成 Features 对象,并将 URL 传递给地图进行渲染.此 URL 与所有其他样式信息一起传入,以像以前一样重建地图.

我遇到的问题是,当我尝试应用样式时,地图没有检索到要在地图上显示的要素列表.

查看文档,我没有看到任何专门针对 loadGeoJson 方法的事件,但确实看到了 addfeature 和 setgeometry,但是在使用 loadGeoJson 方法时,这两个事件都不会引发.

这一切都是用 Typescript 编写的,并尝试遵守非常严格的 MVVM 方法,使用 Knockout 通过绑定为我处理所有 UI 更改.

是否有其他事件可以让我了解此方法何时完成,以便我可以适当地应用我的样式?

还有另一种方法可以让我在某个地方等待"吗?.

解决方案

您可以收听 addFeature 事件,该事件将为您的 json 中的每个功能触发.例如如果您使用

I have a scenario where users can store their mapping styling. When a user navigates back to that page with the map it should display the map the way it was previously.

The user can change colors of geographies, and borders as well as apply thematic styles based on demographic information.

With the release of the new loadGeoJson I have had great success with speeding up my application, Initially I was drawing all of the geographies myself, via JS. This was causeing some memory issues at around 1500 geographies. This new functionality decreases it significantly. I am choosing to generate the Features objects on the server side and just pass a URL to the map for rendering. This URL is passed in along with all of the other style information to rebuild the map as it was previously.

The problem I'm encountering, is when I attempt to apply the stylings, the map hasn't retrieved its list of features to be displayed on the map.

Looking through the documenation I don't see any events specifically for the loadGeoJson method, but did see for addfeature and setgeometry, but neither of these events get raised when using the loadGeoJson method.

This has all been written in Typescript and tries to adhere to a pretty strict MVVM approach using Knockout to handle all of UI changes for me via binding.

Is there another event I can tie into to see when this method has completed so I can apply my styles appropriately?

Is there another approach where I can bake in a 'wait' somewhere? .

解决方案

You can listen to addFeature event which will be fired for each feature in your json. e.g. if you use https://storage.googleapis.com/maps-devrel/google.json six events are raised after the json request is completed i.e. when google api starts adding the features from the json file:

You can see the demo here : http://jsbin.com/ofutUbA/4/edit

这篇关于如何确定 Google Maps loadGeoJson 何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆