Openlayers 3 - What does resolution represent as a style function parameter?
Asked Answered
A

3

9

I am trying to use resolution passed into the StyleFunction to work out the size of my image Icons. Using tests, at a zoom where the scale line is 100m the resolution reported to the styling function is 2.3886.

I've take screenshots of the scale line and measured its length in pixels. A 100m scaleline is 68 pixels, or 1.4705 metres per pixel.

1.4705 !== 2.3886, so what is the resolution unit? The API documentation does not explain it and says it is just a number, but without an idea of units it is difficult to work out.

This is to accurately scale the icon to real world length BTW.

Using this jsfiddle.net/dz9gL0g0/ I find that 200m scaleline reports the 2.38, but 100m returns less (1.19). Is the resolution I'm getting from the previous zoomlevel? If I use the resolution passed in OR call the getResolution function directly, 100m scaleline always returns 2.83 for me, not the 1.19 I think it should, although 1.19 * 84 is mostly correct (scale line is bigger in example than my app, which gives me a 68 pixel scale line for 100m).

Moving the window alters the resolution - resize the jsfiddle and the resolution unit changes. My 100m scaleline still fits the geographical feature I use to test, but now reports 2.38.

Ascot answered 21/5, 2015 at 7:5 Comment(3)
Is this location-based? At 0/0 lat lon it reports 1.19, in Portsmouth (UK) it reports 2.83...Ascot
Yes, it depends on the latitude. See en.wikipedia.org/wiki/Longitude#Length_of_a_degree_of_longitudeAnthropometry
So the question is not answered really - if the resolution passed in does not reflect the actuality of pixels. 2.83 !== 1.47. Sorry, long absence due to holidays.Ascot
A
8

After posting a bug request at github (https://github.com/openlayers/ol3/issues/3770) it was suggested that ol.proj.Projection.getPointResolution() be used to gather the correct resolution for the projection (which I assumed was being passed into the styling function at run-time - assumptions, eh?).

var view = map.getView();
var coords = view.getCenter();
var resolution = view.getResolution();    
var projection = view.getProjection();
var resolutionAtCoords = projection.getPointResolution(resolution, coords);

This results in a much closer 1.50XXXX resolution being returned, which is dependant on the latitude. It remains to be seen if my tiled map source is scaled appropriately to the projection, but this means that my pixels per metre are now within a margin of error, correct.

Ascot answered 8/6, 2015 at 15:20 Comment(0)
A
11

The resolution is the size of 1 pixel in map units. Let's say your map projection is EPSG:3857 whose unit is meters. For example if the current resolution is 20000 m/px, this means that 1 px represents 20000m.

Maybe it also helps taking a look at this example.

Anthropometry answered 22/5, 2015 at 6:55 Comment(2)
If you look below, the numbers don't seem to make sense. 2.3886 * 68 (pixels in the 100m scale line as measured by me === 162.43m - the number doesn't seem to match reality. Outputting the zoom and resolution shows 16 zoom/2.388657133911758 resolution, the projection reported by the view is EPSG3857Ascot
Note that there is a difference between the reality and what you are seeing projected on the screen. For example if you have a tile of 256x256 pixels and your resolution is 20000. Then this tile would cover 256 * 20000 m X 256 * 20000 m, but only projected! In the real world the area that this tile covers will be totally different.Anthropometry
A
8

After posting a bug request at github (https://github.com/openlayers/ol3/issues/3770) it was suggested that ol.proj.Projection.getPointResolution() be used to gather the correct resolution for the projection (which I assumed was being passed into the styling function at run-time - assumptions, eh?).

var view = map.getView();
var coords = view.getCenter();
var resolution = view.getResolution();    
var projection = view.getProjection();
var resolutionAtCoords = projection.getPointResolution(resolution, coords);

This results in a much closer 1.50XXXX resolution being returned, which is dependant on the latitude. It remains to be seen if my tiled map source is scaled appropriately to the projection, but this means that my pixels per metre are now within a margin of error, correct.

Ascot answered 8/6, 2015 at 15:20 Comment(0)
B
1

AFAIK the resolution is in meters per pixel. Here is a feature from my application that is styled as ol.style.Circle with radius 3 / resolution:

open layers circle with radius depending on resolution

Is your scale line working correctly? Using a non standard projection i had to use ol.proj.addProjection(...) and ol.proj.addCoordinateTransforms(...) in addition to just defining the projection via proj4.defs(...) to get it working.

Berlyn answered 21/5, 2015 at 7:51 Comment(1)
I measured a know geographical location to the scale line on a map , and checked it's actual length in two other mapping length tools, all told me that feature (a dry dock) was 100m +/- 5m - the scale line matched it's length correctly so the scale line looks to be accurate.Ascot

© 2022 - 2024 — McMap. All rights reserved.