Skip to content

Class: GeoView ​

One geo subplot's projection and view. Build it with createGeoView.

To draw: stream geometry through projection (or project points with project), remember version, and give the primitives transform on every frame. Reproject when version has changed. When a zoom has settled, call rebase and reproject.

Properties ​

PropertyModifierTypeDescription
boundsreadonlyGeoBoundsThe pixel bounds of the range box at the fitted view (Plotly's this.bounds): the clip rectangle of the map and its background. It does not move with a pan or zoom.
clipAnglereadonlynumber | nullThe angle from the rotation's centre past which a point is hidden, in degrees, or null when the projection shows the whole sphere.
fitScalereadonlynumberd3's scale when projection.scale is 1 (Plotly's fitScale).
initialStatereadonlyGeoViewStateThe state the layout (and the fit) describe, before any interaction.
layoutreadonlyFullGeoLayoutThe container this view was built from.
midPointreadonlyPairThe middle of bounds (Plotly's midPt), where center is read back from.
modereadonlyGeoInteractionModeWhich of Plotly's interactions the map has.
projectionreadonlyGeoProjectionThe d3 projection at the current state, for streaming geometry (projection.stream) and for d3's own helpers. Its output is d3 px: x from the left edge of the subplot's rect, y down from its top edge, so a sink writes size.height - y to get subplot px. It has no clipExtent; clip to bounds. Geometry streamed here is at the current state, while transform applies to geometry of the base state: call rebase before projecting unless version has just changed. Do not call its setters; change the view with set.
rangesreadonlyobjectThe ranges of the range box: the axis ranges, or what fitbounds made of them.
ranges.latreadonlyPair-
ranges.lonreadonlyPair-
scaleExtentreadonlyPairThe least and greatest projection.scale an interaction may reach (minscale, maxscale).
sizereadonlyGeoSizeThe subplot's rect; projection draws into [0, width] × [0, height], y down.
typereadonlystringprojection.type.
validreadonlybooleanfalse when the fit failed (an empty rect or ranges d3 cannot bound): nothing can be drawn.

Accessors ​

state ​

Get Signature ​

ts
get state(): GeoViewState;

The current rotation, scale and translate point.

Returns ​

GeoViewState


transform ​

Get Signature ​

ts
get transform(): Readonly<DataTransform>;

Carries geometry projected at the base state (subplot px) to where the current pan and zoom draw it: world = data * scale + offset. The identity right after a projection.

Returns ​

Readonly<DataTransform>


version ​

Get Signature ​

ts
get version(): number;

Names the projection that geometry was made with. It changes when geometry projected earlier no longer fits this view: after a rotation and after rebase. It is unique across views, so a view of another type, size or parallels has another version too.

Returns ​

number

Methods ​

invert() ​

ts
invert(x, y): [number, number] | null;

The longitude and latitude drawn at a subplot px in the current view; null when the pixel is off the map. d3's inverses answer for any pixel (off an orthographic disc they give the nearest point of its edge), so a pixel counts as on the map when its longitude and latitude are drawn within INSIDE_TOLERANCE_PX of it (Plotly's outside test) and the projection does not hide them.

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

[number, number] | null


invertAt() ​

ts
invertAt(
   state,
   x,
   y
): [number, number] | null;

d3's inverse at another state of this view, without the on-the-map test of invert; null when it is missing or not finite.

Parameters ​

ParameterType
stateGeoViewState
xnumber
ynumber

Returns ​

[number, number] | null


isLonLatOverEdges() ​

ts
isLonLatOverEdges(lon, lat): boolean;

Plotly's isLonLatOverEdges: whether the projection hides a point, either because it has no pixel for it (outside the three parts of Albers USA) or because it lies past the clip angle (the far side of an orthographic globe).

Parameters ​

ParameterType
lonnumber
latnumber

Returns ​

boolean


project() ​

ts
project(lon, lat): [number, number] | null;

Where a longitude and latitude are drawn in the current view, in subplot px; null when the projection hides the point (isLonLatOverEdges) or has no finite answer. Points outside bounds are returned: the subplot's scissor hides those.

Parameters ​

ParameterType
lonnumber
latnumber

Returns ​

[number, number] | null


projectAt() ​

ts
projectAt(
   state,
   lon,
   lat
): [number, number] | null;

d3's answer for a longitude and latitude at another state of this view, in subplot px, without the clip test of project. For interaction maths, which asks where things would be.

Parameters ​

ParameterType
stateGeoViewState
lonnumber
latnumber

Returns ​

[number, number] | null


rebase() ​

ts
rebase(): boolean;

Makes the current state the base: transform becomes the identity and version changes, so the caller reprojects. Call it when a zoom has settled (curves resampled at the old scale drift). Returns whether anything changed; a view already at its base is left alone.

Returns ​

boolean


set() ​

ts
set(patch): this;

Changes the view for an interactive preview. scale and translate change the transform only; a rotation makes the new state the base and changes version. A projection that cannot rotate (Albers USA) ignores rotation.

Parameters ​

ParameterType
patchGeoViewPatch

Returns ​

this


toLayout() ​

ts
toLayout(state?): GeoLayoutView;

The view as the layout values Plotly writes when an interaction ends: the rotation, the longitude and latitude in the middle of the bounds as center, and projection.scale. center is d3's inverse as it is, which is what Plotly writes.

Parameters ​

ParameterType
stateGeoViewState

Returns ​

GeoLayoutView

Released under the MIT License.