views:

347

answers:

2

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?

+1  A: 

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.

geographika
I'm looking for a latitude/longitude per pixel number.
David Pfeffer
I would like to use something more inbuilt to convert the resolution. For boundaries, I don't do any math, I just call the `transform` method. Isn't there something similar? Also, you indicate that the layer should be automatically sending its bounds. I don't see how that would happen since it is a standard vector layer. Am I using the wrong sort of layer? A WMS service isn't an option right now for us.
David Pfeffer
+1  A: 

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

lexicore
Sweet, I was about to abandon this question. Nice save.
David Pfeffer