Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styling feature function resolution seems incorrect. #3770

Closed
pconnell99 opened this issue Jun 8, 2015 · 3 comments
Closed

Styling feature function resolution seems incorrect. #3770

pconnell99 opened this issue Jun 8, 2015 · 3 comments

Comments

@pconnell99
Copy link

Using http://jsfiddle.net/dz9gL0g0/ I determined that the resolution passed into the styling function appears to be incorrect. When running this code and using a geographical feature that is 100m in length (a dry dock in Portsmouth Harbour, UK) the scale line matches it's length, and the number of pixels in that line is 68: 100/68 === 1.470588235294118. The resolution passed into the styling function at the same point is 2.388657133911758. I had a stackoverflow issue open at http://stackoverflow.com/questions/30366777/openlayers-3-what-does-resolution-represent-as-a-style-function-parameter but didn't really get the clarity I needed.

Am I incorrect in my assumptions? My scaling in the style function needs to be exact - if I style a feature to be 100m it needs to be exactly 100m.

@alvinlindstam
Copy link
Contributor

Have a look at http://jsfiddle.net/fcLvL0j0/

I added a call to http://openlayers.org/en/v3.6.0/apidoc/ol.proj.Projection.html#getPointResolution, which returns the resolution at the given coordinate.

Basically, the map (the view) has a resolution which is what is passed on the style function. But some projections, such as default EPSG:3857 are not equidistant, so the actual resolution (map units per pixel) may vary based on latitude.

You can use the example code to determine the resolution at a given point, such as the geometries midpoint, in the style function. But note that some projections may be distorted, so that 10 vertical pixels might not represent the same distance as 10 horizontal pixels.

@pconnell99
Copy link
Author

That is MUCH closer to what I was estimating - I understand the difference at different latitudes as well. Thanks for that - odd really, the resolution passed into the styling function isn't much use to me. Is there any chance that the documentation for the resolution parameter in the API docs could be amended to highlight this for others?

Correct resolution is mostly important if you want to style features that are real-world sizes, not abstract pushpins.

@skarkkai
Copy link

I second the suggestion to amend the documentation for the resolution parameter. http://openlayers.org/en/v3.12.1/apidoc/ol.View.html#setResolution currently describes resolution as "The units are projection units per pixel (e.g. meters per pixel)", which sounds to me like the parameter actually means real-world meters per pixel. It is hard to figure out you need to use getPointResolution when using real-world meters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants