OpenLayers:获取给定投影中地图的分辨率(4326)
我正在使用 OpenLayers 来显示 OpenStreetMap 地图。 (不过,我认为这应该足够通用,适用于任何地图产品...)
我正在显示一些非常复杂的矢量叠加,以及我通过 GeoJSON 从服务器返回的特征的数量和分辨率事实证明,覆盖对于许多计算机来说太过分了。
我现在想做的是仅发送适合当前缩放分辨率的数据。使用 Map
对象上的 getResolution
和 calculateBounds
方法应该相对容易做到这一点。 calculateBounds
返回一个 Bounds 对象,然后可以在地图投影和显示投影之间进行转换。
如何将分辨率转换为我想要的投影(在本例中为 4326)?是否有内置的方法可以做到这一点,或者我是否必须根据已知的公式运行分辨率?
I'm using OpenLayers to display OpenStreetMap maps. (Though, I'd assume this should be general enough to work for any map product...)
I'm displaying some very sophisticated vector overlays, and the amount and resolution of the features I'm returning from the server via GeoJSON to overlay has proven too much for many computers.
What I'd like to do now instead is to only send data befitting the resolution of the current zoom. This should be relatively easy to do using the getResolution
and calculateBounds
methods on the Map
object. calculateBounds
returns a Bounds object that then can be transformed between the map projection and display projection.
How do I transform the resolution into my desired projection (4326 in this case)? Is there a built in way of doing this or do I have to run the resolution against a known formula?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Proj4js 来转换客户端上的坐标系。
You can use Proj4js to transform coordinate systems on the client.
只限制 GeoJSON 矢量图层的绘制比例怎么样?
http://dev.openlayers.org/ docs/files/OpenLayers/Layer-js.html#OpenLayers.Layer.maxScale
那么对服务器的 OpenLayers AJAX 请求应该仅在超出此范围时触发。选择与您想要显示矢量图层的时间相对应的 OpenSteetMaps 比例/缩放级别,并相应地设置 maxScale。
请求应自动将当前地图显示的范围发送到您的服务器以获取相关功能。
我可能误解了你的困境。如果您想要解析公式,本文将介绍它们:
http://msdn.microsoft .com/en-us/library/aa940990.aspx
更新
您可以在 OpenLayers 中实施集群策略。我认为这应该会减少渲染时间,尽管我假设将从数据库返回相同数量的数据。
http://dev. openlayers.org/releases/OpenLayers-2.7/doc/apidocs/files/OpenLayers/Strategy/Cluster-js.html
在此处查看示例:
http://openlayers.org/dev/examples/strategy-cluster.html
为了避免出现不同大小的点,您应该设置 pointRadius:“$ {半径}”为常数。
最后一种替代方法是使用 WMS 服务而不是 GeoJSON,这样服务器将仅返回固定大小的图像。
How about just limiting the scale at which your GeoJSON vector layer will draw?
http://dev.openlayers.org/docs/files/OpenLayers/Layer-js.html#OpenLayers.Layer.maxScale
Then the OpenLayers AJAX requests to the server should only trigger beyond this scale. Pick an OpenSteetMaps scale / zoom level that corresponds to when you want to show the vector layer, and set the maxScale accordingly.
The requests should automatically be sending the bounds of the current map display to your server to get the relevant features.
I may have misunderstood your dilemma though. If you want the resolution formulas this article describes them:
http://msdn.microsoft.com/en-us/library/aa940990.aspx
Update
You could implement a clustering strategy in OpenLayers. I think this should reduce rendering time, although I'd presume the same amount of data would be returned from the database.
http://dev.openlayers.org/releases/OpenLayers-2.7/doc/apidocs/files/OpenLayers/Strategy/Cluster-js.html
Check out the example here:
http://openlayers.org/dev/examples/strategy-cluster.html
To avoid having different sized points you sould set the pointRadius: "${radius}" to a constant.
Finally an alternative would be to use a WMS service rather than GeoJSON, the server would then only be returning images of a fixed size.