Repository navigation
derive scale in 3d model example - #8516
andrewharvey wants to merge 1 commit into
Conversation
|
@ansis I think you implemented Mercator coordinates. What do you think about Andrew's proposal for implementing a way to get a scale factor? If we stick with this PR, I'd suggest adding a comment explaining what the math is doing. |
|
I've explained below, but I think ideally we'd wrap this up in a method that we expose to the user. I'll try to do that shortly...
From https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor, the Mercator projection's scale factor is secant(latitude in radians) which is 1 / cos(latitude in radians). This is since at higher latitudes, a meter is more pixels than at the lower latitudes, and this scale factor accounts for this.
This is the extent of the map in meters, -180 longitude to 180 longitude. We need this because the Mapbox GL Custom Layers expects all units to be unit values, 0 to 1, so we need to know the extent in meters so we can scale our model units (in meters) to a 0 to 1 value that Mapbox expects.
1 meter in the model units / the total extent of the map in meters gives our 0 to 1 unit value from above, then simply multiply by the mercator scale factor to get our transform scale. |
|
I put together #8524 which would make these scale calculations internal to the However since that, if approved, would only go into the next release, I think this change to the documentation could still go in independently so that the example is updated straight away. |
|
We can skip this and just wait for #8524 together with https://github.com/mapbox/mapbox-gl-js-docs/pull/23 in the next release. |
Launch Checklist
closes #8508. the custom layers with three.js example uses a magic number for the model scale, in this PR we try to show for a model with units in meters, how to determine the scale.
This PR is one option. another option is move most of this code to src/geo/mercator_coordinates.js, so the user can just ask for MercatorScale(lat), I'd probably prefer the latter, thoughts?