简体   繁体   English

OpenLayers:获取给定投影中的地图分辨率(4326)

[英]OpenLayers: Get resolution of map in a given projection (4326)

I'm using OpenLayers to display OpenStreetMap maps. 我正在使用OpenLayers显示OpenStreetMap地图。 (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. 我正在显示一些非常复杂的矢量叠加层,对于许多计算机来说,我从服务器通过GeoJSON从服务器返回到叠加层的功能的数量和分辨率都证明了太多。

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. 使用Map对象上的getResolutioncalculateBounds方法,这应该相对容易做到。 calculateBounds returns a Bounds object that then can be transformed between the map projection and display projection. calculateBounds返回一个Bounds对象,然后可以在地图投影和显示投影之间进行转换。

How do I transform the resolution into my desired projection (4326 in this case)? 如何将分辨率转换成所需的投影(在这种情况下为4326)? Is there a built in way of doing this or do I have to run the resolution against a known formula? 是否有内置的方法来执行此操作,或者我必须针对已知公式运行分辨率?

您可以使用Proj4js在客户端上变换坐标系。

How about just limiting the scale at which your GeoJSON vector layer will draw? 仅限制您的GeoJSON矢量图层绘制的比例怎么样?

http://dev.openlayers.org/docs/files/OpenLayers/Layer-js.html#OpenLayers.Layer.maxScale 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. 然后,对服务器的OpenLayers AJAX请求应仅触发超出此范围的事件。 Pick an OpenSteetMaps scale / zoom level that corresponds to when you want to show the vector layer, and set the maxScale accordingly. 选择与要显示矢量层时相对应的OpenSteetMaps比例/缩放级别,并相应地设置maxScale。

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 http://msdn.microsoft.com/en-us/library/aa940990.aspx

Update 更新

You could implement a clustering strategy in OpenLayers. 您可以在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 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 http://openlayers.org/dev/examples/strategy-cluster.html

To avoid having different sized points you sould set the pointRadius: "${radius}" to a constant. 为了避免具有不同大小的点,您可以将pointRadius:“ $ {radius}”设置为常数。

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. 最后,一种替代方法是使用WMS服务而不是GeoJSON,然后服务器将仅返回固定大小的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM