Class: ScaleBarView

ScaleBarView()

The scale bar is a legend for a map that shows the current longitude, latitude, and elevation, as well as a scale bar to indicate the relative size of geo-spatial features.

Screenshot

Constructor

new ScaleBarView()

Since:
  • 2.18.0
Source:

Extends

  • Backbone.View

Members

className :string

The HTML classes to use for this view's element
Type:
  • string
Source:

classes :Object

Classes that will be used to select elements from the template that will be updated with new coordinates and scale.
Type:
  • Object
Properties:
Name Type Description
longitude string The element that will contain the longitude measurement
latitude string The element that will contain the latitude measurement
elevation string The element that will contain the elevation measurement
bar string The element that will be used as a scale bar
distance string The element that will contain the distance measurement
Source:

distances :Array.<number>

Allowed values for the displayed distance measurement in the scale bar. The length (in pixels) of the scale bar will be adjusted so that it is proportional to one of the listed numbers in meters.
Type:
  • Array.<number>
Source:

events :Object

The events this view will listen to and the associated function to call.
Type:
  • Object
Source:

maxBarWidth :number

The maximum width of the scale bar element, in pixels
Type:
  • number
Source:

pointModel :GeoPoint

The model that holds the current position of the mouse on the map
Type:
Since:
  • 2.27.0
Source:

scaleModel :GeoScale

The model that holds the current scale of the map in pixels:meters
Type:
Since:
  • 2.27.0
Source:

template :Underscore.template

The primary HTML template for this view
Type:
  • Underscore.template
Source:

type :string

The type of View this is
Type:
  • string
Source:

Methods

initialize(optionsopt)

Executed when a new ScaleBarView is created
Parameters:
Name Type Attributes Description
options Object <optional>
A literal object with options to pass to the view
Source:

listenToPointModel()

Update the scale bar view when the lat and long change
Since:
  • 2.27.0
Source:

listenToScaleModel()

Update the scale bar when the pixel:meters ratio changes
Since:
  • 2.27.0
Source:

onClose()

Function to execute when this view is removed from the DOM
Since:
  • 2.27.0
Source:

prettifyScaleValues(pixels, meters) → {Object}

Takes a pixel:meters ratio and returns values ready to use in the scale bar.
Parameters:
Name Type Description
pixels number A length in pixels. Must be > 0.
meters number A distance, in meters, that is equivalent to the given distance in pixels. Must be > 0.
Properties:
Name Type Description
pixels number | null The updated pixel value that is less than the maxBarWidth and equivalent to the distance given by the label.
label string | null A string that gives a rounded distance measurement along with a unit, either meters or kilometers (when > 1000m).
Source:
Returns:
Returns the prettified values. Returns null for both values if a matching distance was not found (see ScaleBarView#distances)
Type
Object

render() → {ScaleBarView}

Renders this view
Source:
Returns:
Returns the rendered view element
Type
ScaleBarView

stopListeningToPointModel()

Stop listening to the point model
Source:

stopListeningToScaleModel()

Stop listening to the scale model
Since:
  • 2.27.0
Source:

updateCoordinates(latitude, longitude, elevation)

Updates the displayed coordinates on the scale bar view. Numbers are rounded so that long and lat have 5 digits after the decimal point.
Parameters:
Name Type Description
latitude number The north-south position of the point to show coordinates for
longitude number The east-west position of the point to show coordinates for
elevation number The distance from sea-level of the point to show coordinates for
Source:

updateScale(pixels, meters)

Change the width of the scale bar and the displayed measurement value based on a new pixel:meters ratio. This function ensures that the resulting values are 'pretty' - the pixel and meter measurements passed to this function do not need to be within any range or rounded, though both values must be > 0.
Parameters:
Name Type Description
pixels number A length in pixels
meters number A distance, in meters, that is equivalent to the given distance in pixels
Source: