Question

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?

Was it helpful?

Solution

You can use Proj4js to transform coordinate systems on the client.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top