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

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

问题描述

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

用户可以更改地理位置和边界的颜色,并根据人口统计信息应用主题样式。

随着新版loadGeoJson的发布,我在加速应用程序方面取得了巨大成功,最初我通过JS自己绘制了所有的地理区域。这在大约1500个地区造成了一些记忆问题。这个新功能显着降低了它。我选择在服务器端生成Features对象,并将URL传递给地图进行渲染。该URL将与其他所有样式信息一起传递,以重新构建之前的地图。

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



仔细查看文档,我没有看到任何专门针对loadGeoJson方法的事件,但确实看到了addfeature和setgeometry,但是这两个事件在使用loadGeoJson方法。



这一切都是用Typescript编写的,并试图遵循一种非常严格的MVVM方法,使用Knockout通过绑定来处理所有UI更改。



是否有另一个事件可以与此关联以查看此方法何时完成,以便适当地应用我的样式?

另一种方法,我可以在某处等待烘烤? 。 功能在你的JSON。例如如果您使用 https://storage.googleapis.com/maps-devrel/google.json 在json请求完成后,即在google api开始添加json文件中的功能时,会引发六个事件

< img src =https://i.stack.imgur.com/ZEk8Y.pngalt =在这里输入图片描述>



你可以在这里看到演示: http://jsbin.com/ofutUbA/4/edit


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天全站免登陆