LogoLogo
Sign upHelp CenterContactSocial
JS SDK API Reference
JS SDK API Reference
  • API Reference
  • @feltmaps/js-sdk
  • Elements
    • CircleElementCreate
    • CircleElementRead
    • CircleElementUpdate
    • Element
    • ElementChangeCallbackParams
    • ElementCreate
    • ElementGroup
    • ElementGroupChangeCallbackParams
    • ElementUpdate
    • ElementsController
    • GetElementGroupsConstraint
    • GetElementsConstraint
    • HighlighterElementCreate
    • HighlighterElementRead
    • HighlighterElementUpdate
    • ImageElementCreate
    • ImageElementRead
    • ImageElementUpdate
    • LinkElementRead
    • MarkerElementCreate
    • MarkerElementRead
    • MarkerElementUpdate
    • NoteElementCreate
    • NoteElementRead
    • NoteElementUpdate
    • PathElementCreate
    • PathElementRead
    • PathElementUpdate
    • PlaceElementCreate
    • PlaceElementRead
    • PlaceElementUpdate
    • PolygonElementCreate
    • PolygonElementRead
    • PolygonElementUpdate
    • TextElementCreate
    • TextElementRead
    • TextElementUpdate
  • Interactions
    • InteractionsController
    • MapInteractionEvent
  • Layers
    • AggregationConfig
    • AggregationMethod
    • CreateLayersFromGeoJsonParams
    • DataOnlyLayer
    • FeltTiledVectorSource
    • FilterExpression
    • FilterLogicGate
    • FilterTernary
    • Filters
    • GeoJsonDataVectorSource
    • GeoJsonFileVectorSource
    • GeoJsonUrlVectorSource
    • GeometryFilter
    • GetLayerCalculationParams
    • GetLayerCategoriesGroup
    • GetLayerCategoriesParams
    • GetLayerGroupsConstraint
    • GetLayerHistogramBin
    • GetLayerHistogramParams
    • GetLayersConstraint
    • GetRenderedFeaturesConstraint
    • Layer
    • LayerBoundaries
    • LayerChangeCallbackParams
    • LayerCommon
    • LayerFeature
    • LayerFilters
    • LayerGroup
    • LayerGroupChangeCallbackParams
    • LayerProcessingStatus
    • LayerSchema
    • LayerSchemaAttribute
    • LayerSchemaBooleanAttribute
    • LayerSchemaCommonAttribute
    • LayerSchemaDateAttribute
    • LayerSchemaDateTimeAttribute
    • LayerSchemaNumericAttribute
    • LayerSchemaTextAttribute
    • LayersController
    • LegendItem
    • LegendItemChangeCallbackParams
    • LegendItemIdentifier
    • LegendItemsConstraint
    • MultiAggregationConfig
    • RasterBand
    • RasterLayer
    • RasterLayerSource
    • RasterValue
    • UpdateLayerParams
    • ValueConfiguration
    • VectorLayer
  • Main
    • Felt
    • FeltController
    • FeltEmbedOptions
  • Misc
    • MapDetails
    • MiscController
  • Selection
    • ElementGroupNode
    • ElementNode
    • EntityNode
    • FeatureNode
    • FeatureSelection
    • LayerGroupNode
    • LayerNode
    • SelectionController
  • Shared
    • FeltBoundary
    • FeltZoom
    • GeoJsonFeature
    • GeoJsonGeometry
    • GeoJsonProperties
    • LatLng
    • LineStringGeometry
    • LngLatTuple
    • MultiLineStringGeometry
    • MultiPointGeometry
    • MultiPolygonGeometry
    • PointGeometry
    • PolygonGeometry
    • SetVisibilityRequest
    • SortConfig
    • SortDirection
  • Tools
    • CircleToolSettings
    • ConfigurableToolType
    • HighlighterToolSettings
    • InputToolSettings
    • LineToolSettings
    • MarkerToolSettings
    • NoteToolSettings
    • PinToolSettings
    • PlaceFrame
    • PlaceSymbol
    • PolygonToolSettings
    • RouteToolSettings
    • TextToolSettings
    • ToolSettingsChangeEvent
    • ToolSettingsMap
    • ToolType
    • ToolsController
  • UI
    • OnMapInteractionsOptions
    • UiController
    • UiControlsOptions
  • Viewport
    • SetViewportCenterZoomParams
    • ViewportCenterZoom
    • ViewportConstraints
    • ViewportController
    • ViewportFitBoundsParams
    • ViewportState
Powered by GitBook
On this page
  • Extended by
  • Methods
  • getViewport()
  • setViewport()
  • getViewportConstraints()
  • setViewportConstraints()
  • fitViewportToBounds()
  • Events
  • onViewportMove()
  • onViewportMoveEnd()
  • onMapIdle()

Was this helpful?

Export as PDF
  1. Viewport

ViewportController

PreviousViewportConstraintsNextViewportFitBoundsParams

Last updated 27 days ago

Was this helpful?


The viewport controller allows you to control the viewport of the map.

You can get the current viewport, move the viewport, and be notified when the viewport changes.

Extended by

Methods

getViewport()

getViewport(): Promise<>

Gets the current state of the viewport.

Returns

Promise<>

Example

// Get current viewport state
const viewport = await felt.getViewport();
console.log({
  center: viewport.center,
  zoom: viewport.zoom,
});

setViewport()

Moves the map to the specified location.

Parameters

Parameter
Type

viewport

Returns

void

Example

felt.setViewport({
  center: { latitude: 0, longitude: 0 },
  zoom: 10,
});

getViewportConstraints()

Gets the current state of the viewport constraints.

Returns

Example

// Get current viewport constraints
const constraints = await felt.getViewportConstraints();
if (constraints) {
  console.log({
    bounds: constraints.bounds,
    minZoom: constraints.minZoom,
    maxZoom: constraints.maxZoom
  });
} else {
  console.log("No viewport constraints set");
}

setViewportConstraints()

Constrains the map viewport so it stays inside certain bounds and/or certain zoom levels.

Parameters

Parameter
Type

constraints

Returns

void

Examples

felt.setViewportConstraints({
  bounds: [-122.5372532, 37.6652478, -122.1927016, 37.881707],
  minZoom: 1,
  maxZoom: 23,
});

every constraint is optional

felt.setViewportConstraints({
  bounds: [-122.5372532, 37.6652478, -122.1927016, 37.881707],
});

if a constraint is null, it will be removed but keeping the others

felt.setViewportConstraints({ bounds: null });

if method receives null, it will remove the constraints

felt.setViewportConstraints(null);

fitViewportToBounds()

Fits the map to the specified bounds.

Parameters

Parameter
Type

bounds

Returns

void

Example

const west = -122.4194;
const south = 37.7749;
const east = -122.4194;
const north = 37.7749;
felt.fitViewportToBounds({ bounds: [west, south, east, north] });

Events

onViewportMove()

Adds a listener for when the viewport changes.

Parameters

Parameter
Type
Description

args

-

args.handler

This callback is called with the current viewport state whenever the viewport changes.

Returns

VoidFunction

A function to unsubscribe from the listener

Example

const unsubscribe = felt.onViewportMove({
  handler: viewport => console.log(viewport.center.latitude),
});

// later on...
unsubscribe();

onViewportMoveEnd()

Adds a listener for when the viewport move ends, which is when the user stops dragging or zooming the map, animations have finished, or inertial dragging ends.

Parameters

Parameter
Type

args

args.handler

Returns

VoidFunction

A function to unsubscribe from the listener

Example

const unsubscribe = felt.onViewportMoveEnd({
  handler: viewport => console.log(viewport.center.latitude),
});

// later on...
unsubscribe();

onMapIdle()

onMapIdle(args: { handler: () => void; }): VoidFunction

Adds a listener for when the map is idle, which is defined as:

  • No transitions are in progress

  • The user is not interacting with the map, e.g. by panning or zooming

  • All tiles for the current viewport have been loaded

  • Any fade transitions (e.g. for labels) have completed

Parameters

Parameter
Type

args

{ handler: () => void; }

args.handler

() => void

Returns

VoidFunction

A function to unsubscribe from the listener

Example

const unsubscribe = felt.onMapIdle({ handler: () => console.log("map is idle") });

// later on...
unsubscribe();

setViewport(viewport: ): void

getViewportConstraints(): Promise<null | >

Promise<null | >

setViewportConstraints(constraints: null | Partial<>): void

null | Partial<>

fitViewportToBounds(bounds: ): void

onViewportMove(args: { handler: (viewport: ) => void; }): VoidFunction

{ handler: (viewport: ) => void; }

(viewport: ) => void

onViewportMoveEnd(args: { handler: (viewport: ) => void; }): VoidFunction

{ handler: (viewport: ) => void; }

(viewport: ) => void

FeltController
ViewportState
ViewportState
SetViewportCenterZoomParams
ViewportConstraints
ViewportConstraints
ViewportConstraints
ViewportFitBoundsParams
ViewportState
ViewportState
SetViewportCenterZoomParams
ViewportConstraints
ViewportFitBoundsParams
ViewportState
ViewportState
ViewportState
ViewportState