CanvasMap
Getting Started Tutorials 3D Reference

Class CMScaleBar extends CMItem

CMScaleBar
Class to render a scale bar into the scene. The scale bar will be automatically
repainted with the scale based on its position in the scene.
The algorithm is to find the two points at either end of the rectangle provided
for the scale bar and convert these points to geographic coordinates. Then,
a great arc calculation is performed to find the distance between the points.
The scale displayed is then found by reducing this distance to an even multiple
of 1, 2, or 5. If this distance does not fit in the area provided (including the
the labels), the next smaller distance is computed. This continues until a distance
is found that fits.

Note that the scale bar is placed into a DIV in the map container. Thus is uses a
CSS style (CM_ScaleBar) for the style of the containing box. The contents of the
DIV are drawn in a Canvas element.

Settings
TextStyle - used to write the text above the ticks on the scale bar


Copyright (C) 2020, Humboldt State University, Jim Graham

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see
.

Enumerated Types

    CMScaleBar.UNITS_ISO=0 - meters, kilometers
    CMScaleBar.UNITS_ENGLISH=1 - feet, miles

Settings Group: ScaleBar

Setting Name Type Options Default Comments
ClassName Class Name CMTYPE_STRING CM_ScaleBar

Settings Group: UnitText

Setting Name Type Options Default Comments
Text Text CMTYPE_STRING null
font Font CMTYPE_FONT 12px Arial
strokeStyle Line Style CMTYPE_CSS_STYLE rgb(0,0,0)
fillStyle Fill Style CMTYPE_CSS_STYLE rgb(0,0,0)
lineWidth Width CMTYPE_INTEGER 1
lineCap Line Cap CMTYPE_ENUMERATED butt, round, square round
lineJoin Line Join CMTYPE_ENUMERATED bevel, round, miter round

Settings Group: Factors

Setting Name Type Options Default Comments
UnitFontHeightFactor Corner Width CMTYPE_FLOAT 0.35 proportion of the height of the scale bar used for units
LabelFontHeightFactor Corner Height CMTYPE_FLOAT 0.3
ScaleBarHeightFactor Corner Height CMTYPE_FLOAT 0.3
ScaleBarBaseLineFromBottomFactor Corner Height CMTYPE_FLOAT 0.2 proportional distance of the bottom of the scale bar from the bottom of the background
Units Units CMTYPE_INDEXES 0 CMScaleBar.UnitOptions[0]
Margin Margin CMTYPE_FLOAT 4 margin around the scale bar

ScaleBarStyle Scale Bar Style CMTYPE_OBJECT style of the actual bar BoxStyle Box Style CMTYPE_OBJECT style of the actual bar