Open ansis opened 7 years ago
Sounds great! Thanks for the detailed proposal @ansis.
This would be very useful for us. I just had an exchange with support about this same question today.
Our use case is we are integrating Mapbox with our own 3D map. To do a smooth crossfade between 2D and 3D we need information about the real-world location of the Mapbox camera. Today we're trying to figure out how to estimate this given the information available through the public API.
We are desperately waiting for this to exchange current rendering with mapbox
@drhase2 It sounds like this feature implementation will be as easy as wiring up a private property to some external getters / setters. Any interest in putting together a PR?
(Also, FWIW, you may prototype this feature using the existing private API: map.transform.fov = 4
)
This is a big wall of text but the actual implementation should be short.
Motivation
You want to change how perspective-y the map looks, either to match the fov in some other piece of software or to just change the appearance of a 3D map to make you look closer or more distant.
Design Alternatives
Field of view
Expose the
fieldOfView
(fov) transform property in all the placesbearing
is exposed.Field of view is usually specified as an angle in either the x or y direction. Since maps can exist at variable aspect ratio and resolutions, the fov needs to be scaled at least in one direction. For example, if you stretch a map horizontally does the horizontal fov change? or does the vertical fov change? or do they both change? Here is an overview of some of the options. The main options are:
Name possibilities:
fov
,fieldOfView
,verticalFieldOfView
,fovY
,fieldOfViewY
focal_length / dolly zoom / old altitude
Field of view could alternatively be specified as the distance from the camera to the center. This is basically the dolly zoom effect. The old internal
altitude
property implemented this. Tangram implements this and calls itfocal_length
.do nothing
It's an option since this is mostly a nice-to-have but the cost of supporting it isn't high.
Design
We should expose
fieldOfView
in all the places we exposebearing
.Field of view is better than
focal_length
/altitude
/dolly zoom because:I think either
fov
orfieldOfView
are good names. The former is standard in graphics but the latter is less cryptic. I lean towardsfieldOfView
.We should have a fixed vertical fov. This is the most common approach in games and is better suited for wider aspect ratios. This is what is currently implemented.
Mock-Up
var map = new Map({ fieldOfView: 35 })
var fov = map.getFieldOfView(fieldOfView)
map.setFieldOfView(fov)
and usingCameraOptions
:map.jumpTo({ fieldOfView: fov })
map.easeTo({ fieldOfView: fov })
map.flyTo({ fieldOfView: fov })
Concepts
field of view
Video games, 3d graphics libraries.
Implementation
The core of this is already implemented. The
Transform#fov
property (https://github.com/mapbox/mapbox-gl-js/pull/3790) needs to be exposed through an external api.