Skip to content

Scale Bar

ESM:
Use dark colors for code blocksCopy
1
import "@arcgis/map-components/components/arcgis-scale-bar";
CDN:
No specific import is needed for this component.
Since:ArcGIS Maps SDK for JavaScript 4.28

The Scale Bar component displays a scale bar representing the scale of the map. It respects various coordinate systems and displays units in metric or imperial values. Metric values show either kilometers, meters, centimeters, or millimeters depending on the scale, and likewise, imperial values show miles, feet, or inches depending on the scale. When working with Web Mercator or geographic coordinate systems the scale bar takes into account projection distortion and dynamically adjusts the scale bar.

When the scale bar is inside the map, the actual location of the scale bar is used to calculate the scale. Otherwise, the center of the map is used to calculate the scale.

Known limitations

  • This component is not currently supported within a Scene component.

Demo

Properties

PropertyAttributeType
autoDestroyDisabledauto-destroy-disabledboolean
barStylebar-style"line" | "ruler"
iconiconstring
labellabelstring
messageOverridesRecord<string, unknown>
position
deprecatedreflected
position"bottom-leading" | "bottom-left" | "bottom-right" | "bottom-trailing" | "manual" | "top-leading" | "top-left" | "top-right" | "top-trailing"
referenceElementreference-elementHTMLArcgisLinkChartElement | HTMLArcgisMapElement | HTMLArcgisSceneElement | string
unitunit"dual" | "imperial" | "metric"
viewMapView

autoDestroyDisabled

Property
autoDestroyDisabled: boolean

If true, the component will not be destroyed automatically when it is disconnected from the document. This is useful when you want to move the component to a different place on the page, or temporarily hide it. If this is set, make sure to call the destroy method when you are done to prevent memory leaks.

Attribute
auto-destroy-disabled
Default value
false

barStyle

Property
barStyle: "line" | "ruler"

The style for the scale bar. When unit is set to dual, the style will always be line.

Attribute
bar-style
Default value
"line"

icon

Property
icon: string

Icon which represents the component. Typically used when the component is controlled by another component (e.g. by the Expand component).

See also
Attribute
icon
Default value
"actual-size"

label

Property
label: string

The component's default label.

Attribute
label

messageOverrides

Property
messageOverrides: Record<string, unknown>

Replace localized message strings with your own strings.

Note: Individual message keys may change between releases.

position

deprecatedreflected
Property
position: "bottom-leading" | "bottom-left" | "bottom-right" | "bottom-trailing" | "manual" | "top-leading" | "top-left" | "top-right" | "top-trailing"
Deprecatedsince 4.34, use slot instead.
Attribute
position

referenceElement

Property

By assigning the id attribute of the Map or Scene component to this property, you can position a child component anywhere in the DOM while still maintaining a connection to the Map or Scene.

See also
Attribute
reference-element

unit

Property
unit: "dual" | "imperial" | "metric"

Units to use for the scale bar. When using dual, the scale bar displays both metric and imperial units. When metric, distances will be shown in either kilometers, meters, centimeters, or millimeters depending on the scale. Similarly, imperial units will be shown in either miles, feet, or inches.

Attribute
unit

view

Property
view: MapView

The view associated with the component.

Note: The recommended approach is to fully migrate applications to use map and scene components and avoid using MapView and SceneView directly. However, if you are migrating a large application from widgets to components, you might prefer a more gradual transition. To support this use case, the SDK includes this view property which connects a component to a MapView or SceneView. Ultimately, once migration is complete, the Scale Bar component will be associated with a map or scene component rather than using the view property.

Methods

MethodSignature
componentOnReadycomponentOnReady(): Promise<void>
destroydestroy(): Promise<void>

componentOnReady

Method
componentOnReady(): Promise<void>

Create a promise that resolves once component is fully loaded.

Example
Use dark colors for code blocksCopy
1
2
3
4
const arcgisScaleBar = document.querySelector("arcgis-scale-bar");
document.body.append(arcgisScaleBar);
await arcgisScaleBar.componentOnReady();
console.log("arcgis-scale-bar is ready to go!");
Returns
Promise<void>

destroy

Method
destroy(): Promise<void>

Permanently destroy the component.

Returns
Promise<void>

Events

EventType
arcgisReadyCustomEvent<void>

arcgisReady

Event
arcgisReady: CustomEvent<void>

Emitted when the component associated with a map or scene view is ready to be interacted with.

bubbles
composed
cancelable

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.