Constructs a new Viewport
Optionaltransform: Partial<TransformProps>Optionaldimensions: Vec2Sets/Gets a transform object
a Transform-like object containing the new Transform properties
When argument is provided, sets x,y,z,r from the Transform and returns this for method chaining.
Returns a Transform object containing the current x,y,z,r values otherwise
version
Returns the screen center coordinate in [x, y]
viewport screen center coordinate in [x, y]
Returns the screen center coordinate in [lon, lat]
viewport screen center coordinate in [lon, lat]
Gets the visible dimensions
Gets the visible Extent (in WGS84 coordinates)
Returns the viewport's visible polygon (wound counterclockwise) (in "screen" coordinates) We construct a rotated rectangle that contains the original screen rectangle. The rotated rectangle has the same center point as the original screen rectangle. see https://math.stackexchange.com/questions/1628657/dimensions-of-a-rectangle-containing-a-rotated-rectangle The first coordinate in the rotated rectangle is the rotated origin (E)
| E__
|r/ ''--..__
|/ r''--..__
[0,0] A═══════════════════════D__
/║ ║ ''H N
/r║ ║ / W._/
/ ║ + ║ / /'-E
/ ║ ║r/ S
F__ ║ ║/
''B═══════════════════════C [w,h]
''--..__r /|
''--..__ /r|
''G |
Gets the visible Extent (in world coordinates)
Viewportis a class for managing the state of the viewer and converting between Lon/Lat [λ,φ] and Cartesian [x,y] coordinatesOriginal geographic coordinate data is in WGS84 (Lon,Lat) and "projected" into screen space [x,y] using the Web Mercator projection see: https://en.wikipedia.org/wiki/Web_Mercator_projection
Some nomenclature on the coordinates that this code uses:
The parameters of this projection are stored in
_transformx,y- translation, (from origin coordinate [0,0], to top-left screen coordinate)z- zoom (the scale factor is 2^z)r- rotation, optionally applied post-projection to change the map bearing away from north-upThe viewport (what a user can see) is defined by: A rectangular Extent A-B-C-D (stored in
_dimensions), representing the user's screen. By default, the origin of the screen space is top-left coordinate 'A' [0,0]. When a rotation is applied, the visible extent extends to E-F-G-H and top-left coordinate 'E'.