UNPKG

@allmaps/render

Version:

Render functions for WebGL and image buffers

172 lines (170 loc) 11.1 kB
import { WarpedMapList } from '../maps/WarpedMapList.js'; import { Point, Rectangle, Size, Bbox, HomogeneousTransform, Fit, Polygon } from '@allmaps/types'; import { Projection } from '@allmaps/project'; import { WarpedMap } from '../maps/WarpedMap.js'; import { ProjectionOptions, SelectionOptions } from '../shared/types.js'; export type ViewportOptions = { rotation: number; devicePixelRatio: number; } & ProjectionOptions; export type ZoomOptions = { zoom: number; }; export type FitOptions = { fit: Fit; }; /** * The viewport describes the view on the rendered map. * @property geoCenter - Center point of the viewport, in longitude/latitude coordinates. * @property geoRectangle - Rotated rectangle (possibly quadrilateral) of the viewport point, in longitude/latitude coordinates. * @property geoSize - Size of the viewport in longitude/latitude coordinates, as [width, height]. (This is the size of the bounding box of the rectangle, since longitude/latitude only makes sense in that case). * @property geoResolution - Resolution of the viewport in longitude/latitude coordinates, as width * height. (This is the size of the bounding box of the rectangle, since longitude/latitude only makes sense in that case). * @property geoRectangleBbox - Bounding box of the rotated rectangle of the viewport, in longitude/latitude coordinates. * @property projectedGeoCenter - Center point of the viewport, in projected geospatial coordinates. * @property projectedGeoRectangle - Rotated rectangle of the viewport point, in projected geospatial coordinates. * @property projectedGeoSize - Size of the viewport in projected geospatial coordinates, as [width, height]. (This is not the size of the bounding box of the rotated rectangle, but the width and hight of the rectangle). * @property projectedGeoResolution - Resolution of the viewport in projected geospatial coordinates, as width * height. (This is not the size of the bounding box of the rotated rectangle, but the width and hight of the rectangle). * @property projectedGeoRectangleBbox - Bounding box of the rotated rectangle of the viewport, in projected geospatial coordinates. * @property rotation - Rotation of the viewport with respect to the projected coordinate system. * @property projectedGeoPerViewportScale - Scale of the viewport, in projected geospatial coordinates per viewport pixel. * @property viewportCenter - Center point of the viewport, in viewport pixels. * @property viewportRectangle - Rectangle of the viewport point, in viewport pixels. * @property viewportSize - Size of the viewport in viewport pixels, as [width, height]. * @property viewportResolution - Resolution of the viewport in viewport pixels, as width * height. * @property viewportBbox - Bounding box of the viewport, in viewport pixels. * @property devicePixelRatio - The devicePixelRatio of the viewport. * @property canvasCenter - Center point of the canvas, in canvas pixels. * @property canvasRectangle - Rectangle of the canvas, in canvas pixels. * @property canvasSize - Size of the canvas in canvas pixels (viewportSize*devicePixelRatio), as [width, height]. * @property canvasResolution - Resolution of the canvas in canvas pixels (viewportSize*devicePixelRatio), as width * height. * @property canvasBbox - Bounding box of the canvas, in canvas pixels. * @property projectedGeoPerCanvasScale - Scale of the viewport, in projected geospatial coordinates per canvas pixel (projectedGeoPerViewportScale/devicePixelRatio). * @property projectedGeoToViewportHomogeneousTransform - Homogeneous Transform from projected geo coordinates to viewport pixels. Equivalent to OpenLayers coordinateToPixelTransform. * @property projectedGeoToCanvasHomogeneousTransform - Homogeneous Transform from projected geo coordinates to canvas pixels. * @property projectedGeoToClipHomogeneousTransform - Homogeneous Transform from projected geo coordinates to WebGL coordinates in the [-1, 1] range. Equivalent to OpenLayers projectionTransform. * @property viewportToClipHomogeneousTransform - Homogeneous Transform from viewport coordinates to WebGL coordinates in the [-1, 1] range. */ export declare class Viewport { geoCenter: Point; geoRectangle: Rectangle; geoSize: Size; geoResolution: number; geoRectangleBbox: Bbox; projection: Projection; projectedGeoCenter: Point; projectedGeoRectangle: Rectangle; projectedGeoSize: Size; projectedGeoResolution: number; projectedGeoRectangleBbox: Bbox; rotation: number; projectedGeoPerViewportScale: number; viewportCenter: Point; viewportRectangle: Rectangle; viewportSize: Size; viewportResolution: number; viewportBbox: Bbox; devicePixelRatio: number; canvasCenter: Point; canvasRectangle: Rectangle; canvasSize: Size; canvasResolution: number; canvasBbox: Bbox; projectedGeoPerCanvasScale: number; projectedGeoToViewportHomogeneousTransform: HomogeneousTransform; projectedGeoToCanvasHomogeneousTransform: HomogeneousTransform; projectedGeoToClipHomogeneousTransform: HomogeneousTransform; viewportToClipHomogeneousTransform: HomogeneousTransform; /** * Creates a new Viewport * * @constructor * @param viewportSize - Size of the viewport in viewport pixels, as [width, height]. * @param projectedGeoCenter - Center point of the viewport, in projected geospatial coordinates. * @param projectedGeoPerViewportScale - Scale of the viewport, in projection coordinates per viewport pixel. * @param rotation - Rotation of the viewport with respect to the projected geo coordinate system. Positive values rotate the viewport positively (i.e. counter-clockwise) w.r.t. the map in projected geospatial coordinates. This is equivalent to rotating the map negatively (i.e. clockwise) within the viewport. * @param devicePixelRatio - The devicePixelRatio of the viewport. * @param projection - The projection the projected coordinates are in . */ constructor(viewportSize: Size, projectedGeoCenter: Point, projectedGeoPerViewportScale: number, partialViewportOptions?: Partial<ViewportOptions>); /** * Static method that creates a Viewport from a size and maps. * * Optionally specify a projection, to be used both when obtaining the extent of selected warped maps in projected geospatial coordinates, as well as when create a viewport * * @param viewportSize - Size of the viewport in viewport pixels, as [width, height]. * @param warpedMapList - A WarpedMapList. * @param partialExtendedViewportOptions - Optional viewport options * @returns A new Viewport object. */ static fromSizeAndMaps<W extends WarpedMap>(viewportSize: Size, warpedMapList: WarpedMapList<W>, partialExtendedViewportOptions?: Partial<ViewportOptions & ZoomOptions & FitOptions & SelectionOptions>): Viewport; /** * Static method that creates a Viewport from a size and a polygon in geospatial coordinates, i.e. lon-lat `EPSG:4326`. * * @static * @param viewportSize - Size of the viewport in viewport pixels, as [width, height]. * @param geoPolygon - A polygon in geospatial coordinates. * @param partialExtendedViewportOptions - Optional viewport options * @returns A new Viewport object. */ static fromSizeAndGeoPolygon(viewportSize: Size, geoPolygon: Polygon, partialExtendedViewportOptions?: Partial<ViewportOptions & ZoomOptions & FitOptions>): Viewport; /** * Static method that creates a Viewport from a size and a polygon in projected geospatial coordinates. * * @static * @param viewportSize - Size of the viewport in viewport pixels, as [width, height]. * @param projectedGeoPolygon - A polygon in projected geospatial coordinates. * @param partialExtendedViewportOptions - Optional viewport options * @returns A new Viewport object. */ static fromSizeAndProjectedGeoPolygon(viewportSize: Size, projectedGeoPolygon: Polygon, partialExtendedViewportOptions?: Partial<ViewportOptions & ZoomOptions & FitOptions>): Viewport; /** * Static method that creates a Viewport from a scale and maps. * * Optionally specify a projection, to be used both when obtaining the extent of selected warped maps in projected geospatial coordinates, as well as when create a viewport * * @param projectedGeoPerViewportScale - Scale of the viewport, in projected geospatial coordinates per viewport pixel. * @param warpedMapList - A WarpedMapList. * @param partialExtendedViewportOptions - Optional viewport options. * @returns A new Viewport object. */ static fromScaleAndMaps<W extends WarpedMap>(projectedGeoPerViewportScale: number, warpedMapList: WarpedMapList<W>, partialExtendedViewportOptions?: Partial<ViewportOptions & ZoomOptions & SelectionOptions>): Viewport; /** * Static method that creates a Viewport from a scale and a polygon in geospatial coordinates, i.e. lon-lat `EPSG:4326`. * * Note: the scale is still in *projected* geospatial per viewport pixel! * * @param projectedGeoPerViewportScale - Scale of the viewport, in projected geospatial coordinates per viewport pixel. * @param geoPolygon - A polygon in geospatial coordinates. * @param partialViewportOptions - Optional viewport options. * @returns A new Viewport object. */ static fromScaleAndGeoPolygon(projectedGeoPerViewportScale: number, geoPolygon: Polygon, partialExtendedViewportOptions?: Partial<ViewportOptions & ZoomOptions>): Viewport; /** * Static method that creates a Viewport from a scale and a polygon in projected geospatial coordinates. * * @param projectedGeoPerViewportScale - Scale of the viewport, in projected geospatial coordinates per viewport pixel. * @param projectedGeoPolygon - A polygon in projected geospatial coordinates. * @param partialViewportOptions - Optional viewport options. * @returns A new Viewport object. */ static fromScaleAndProjectedGeoPolygon(projectedGeoPerViewportScale: number, projectedGeoPolygon: Polygon, partialExtendedViewportOptions?: Partial<ViewportOptions & ZoomOptions>): Viewport; getProjectedGeoBufferedRectangle(bufferFraction: number): Rectangle; private composeProjectedGeoToViewportHomogeneousTransform; private composeProjectedGeoToCanvasHomogeneousTransform; private composeProjectedGeoToClipHomogeneousTransform; private composeViewportToClipHomogeneousTransform; /** * Returns a rectangle in projected geospatial coordinates * * The rectangle is the result of a horizontal rectangle in Viewport space of size 'viewportSize', * scaled using projectedGeoPerViewportScale, centered, * rotated using 'rotation' and translated to 'projectedGeoCenter'. * * @private * @param viewportSize * @param projectedGeoPerViewportScale * @param rotation * @param projectedGeoCenter */ private computeProjectedGeoRectangle; }