Class: LabelLayer

.ALS.LeafletLayers. LabelLayer


new LabelLayer(automaticallyRedraw)

A fast label rendering layer. Works well with LOADS (50K-100K) of labels on a mid-class PC.

This is preferable option for rendering labels. Use it instead of L.ALS.LeafletLayers.WidgetLayer.

Parameters:
Name Type Description
automaticallyRedraw boolean

If set to true, every method will automatically redraw the canvas. If you're repeatedly changing labels, consider setting it to false and redrawing canvas manually by calling L.ALS.LeafletLayers.LabelLayer#redraw method. Doing so will considerably improve performance.

Mixes In:

Extends

Members


<static> DefaultDisplayOptions

Display options to match ALS style

Properties:
Name Type Default Description
Normal DisplayOptions {"backgroundColor":"white","borderColor":"#ccc","fontColor":"black"}

Normal label, looks like WidgetLayer

Error DisplayOptions {"backgroundColor":"#ffbebe","borderColor":"darkred","fontColor":"black"}

Represents error message

Warning DisplayOptions {"backgroundColor":"#fff4c3","borderColor":"goldenrod","fontColor":"black"}

Represents warning message

Success DisplayOptions {"backgroundColor":"#e3ffd3","borderColor":"green","fontColor":"black"}

Represents success message

Message DisplayOptions {"backgroundColor":"#e4f7ff","borderColor":"cornflowerblue","fontColor":"black"}

Represents informative message


<protected> fontSize

Font size in pixels. You can extend this class and modify it, but it's not recommended because it will introduce inconsistency between everything.


<protected> padding

Padding around text in pixels. You can extend this class and modify it, but it's not recommended because it will introduce inconsistencies.

Methods


<static> deserialize()

See:

addLabel(id, latLng, text, displayOptions)

Adds label to this layer. If label with given ID already exists, won't do anything.

Parameters:
Name Type Description
id string

ID of a label for easy later access. Must be unique for this layer. If you don't need it, set it to an empty string, and it will be autogenerated.

latLng Array.<number> | L.LatLng

Position of a label

text any

Label text

displayOptions DisplayOptions

Label display options


addTo(map)

Adds this layer to a given map

Parameters:
Name Type Description
map

Map to add this layer to.

Inherited From:
Returns:

this

Type
L.ALS.LeafletLayers.CanvasLayer

canvasCoordsToLatLng(coords)

Converts canvas coordinates to latLng.

Parameters:
Name Type Description
coords Array.<number>

Coordinates to convert, array in format [x, y]

Inherited From:
Returns:

Converted coordinates.

Type
Object

cleanUp(seenObjects)

Cleans up seen objects. Must be called after first call of serialize(), serializeAnyObjects() or deserialize(). Should not be called in the middle of serialization or deserialization, for example, at serialize().

Parameters:
Name Type Description
seenObjects Object

seenObjects argument that you've passed to serialization and deserialization methods

Mixes In:

deleteAllLabels()

Deletes all labels on this layer.


deleteLabel(id)

Deletes label with given ID

Parameters:
Name Type Description
id string

ID of a label to delete


deserialize(serialized, seenObjects)

Generic deserialization method, can be used to deserialize any object or primitive anywhere by calling L.ALS.Serializable.deserialize.

Parameters:
Name Type Description
serialized Object

Serialized object or primitive

seenObjects Object

Already seen objects' ids. Intended only for internal use.

Mixes In:
Returns:

Deserialized object or primitive


deserializePrimitive(primitive)

Deserializes primitives including types unsupported by JSON

Parameters:
Name Type Description
primitive

Primitive to deserialize

Mixes In:
Returns:

Deserialized primitive

Type
bigint | number | *

draw(data)

Being called upon layer redrawing. Override this method and implement your stuff here.

Parameters:
Name Type Description
data

Contains information about the canvas

Properties
Name Type Description
layer

this

canvas HTMLCanvasElement

Canvas

bounds

Current map bounds, see L.Map.getBounds()

size

Current map size, see L.Map.getSize()

zoom number

Current map zoom, see L.Map.getZoom()

Inherited From:
Overrides:

findGetter(property, object)

Finds getter name for given property in a given object

Parameters:
Name Type Description
property string

Property name

object Object

Object to find getter in

Mixes In:
Returns:

Either getter name or undefined if nothing has been found

Type
string | undefined

findSetter(property, object)

Finds setter name for given property in a given object

Parameters:
Name Type Description
property string

Property name

object Object

Object to find setter in

Mixes In:
Returns:

Either setter name or undefined if nothing has been found

Type
string | undefined

getAutomaticallyRedraw()

Returns:

True, if this layer automatically redraws its content. False otherwise.

Type
boolean

getInteractive()

Inherited From:
Returns:

True, if this layer is interactive. False otherwise.

Type
boolean

getLabelProperties(id)

Gets properties of a label with given ID.

Parameters:
Name Type Description
id string

ID of a label to get properties of

Returns:

Properties of a label. Returned object is not linked to the actual label.

Type
LabelProperties

getObjectFromSerialized(serialized, seenObjects)

Constructs new instance of Serializable and passes serialized arguments to the constructor. Assigns serializationID to the object and adds it to seenObjects.

Parameters:
Name Type Description
serialized Object

Serialized Serializable object

seenObjects

Already seen objects' ids. Intended only for internal use.

Mixes In:
Returns:

Instance of given object or serialized argument if constructor hasn't been found

Type
L.ALS.Serializable | Object

getSerializableConstructor(className)

Finds a constructor by given class name

Parameters:
Name Type Description
className string

Full class name. Just pass serialized.serializableClassName.

Mixes In:
Returns:

Found constructor or undefined

Type
function | undefined

isInteractive()

Alias for @{link L.Layer.getInteractive}

Inherited From:
Returns:

True, if this layer is interactive. False otherwise.

Type
boolean

latLngToCanvasCoords(latLng)

Converts latLng coordinates to canvas coordinates. Basically, returns map.latLngToContainerPoint(latLng).

Parameters:
Name Type Description
latLng

Coordinate to convert

Inherited From:
Returns:

Converted coordinates.

Type
Object

onAdd(map)

Called when layer is being added to the map. If overridden, parent method must be called!

Parameters:
Name Type Description
map

Map to add this layer to.

Inherited From:

onRemove(map)

Called upon layer removal. If overridden, parent method must be called!

Parameters:
Name Type Description
map

Map to remove this layer from

Inherited From:

redraw()

Redraws content of this layer.

Inherited From:
Returns:

this

Type
L.ALS.LeafletLayers.CanvasLayer

serializeAnyObject(object, seenObjects)

Generic serialization mechanism. Tries to serialize everything possible

Parameters:
Name Type Description
object

Any object or primitive to serialize

seenObjects Object

Already seen objects' ids. Intended only for internal use.

Mixes In:
Returns:

Serialized object or primitive

Type
Object

serializePrimitive(primitive)

Serializes primitives including types unsupported by JSON

Parameters:
Name Type Description
primitive

Primitive to serialize

Mixes In:
Returns:

Serialized primitive


setAutomaticallyRedraw(automaticallyRedraw)

Sets whether this layer should automatically redraw its content when any of its methods called or not.

Parameters:
Name Type Description
automaticallyRedraw boolean

If set to true, this canvas will automatically redraw itself.


setInteractive(interactive)

Sets this layer to be interactive or not.

Parameters:
Name Type Description
interactive boolean

If true, this layer will be interactive. Otherwise layer will be static.

Inherited From:
Author:
  • Piero "Jadaw1n" Steinger. Home page: https://github.com/Jadaw1n

setLabelDisplayOptions(id, displayOptions)

Sets display options of a label with given ID.

Parameters:
Name Type Description
id string

ID of a label to set display options of.

displayOptions DisplayOptions

Options to set


setLabelLatLng(id, latLng)

Sets position of a label with given ID.

Parameters:
Name Type Description
id string

ID of a label to set position of.

latLng Array.<number> | L.LatLng

Position of a label


setLabelText(id, text)

Sets text of a label with given ID

Parameters:
Name Type Description
id string

ID of a label to set text of.

text any

Text to set


shouldIgnoreProperty(property, object, isGetter, checkOnlyIgnoreList)

Checks if property should be ignored when serializing or deserializing.

If you're deserializing, call it for both serialized object and new instance like this:

if (this.shouldIgnoreProperty(property, serialized) || this.shouldIgnoreProperty(property, newObject, false, true))
    // Ignore this property
Parameters:
Name Type Description
property string

Name of the property

object L.ALS.Serializable | Object

Object containing ignore lists

isGetter boolean

Indicates whether given property is getter or not

checkOnlyIgnoreList boolean

If true, will only check if property is in the ignore lists

Mixes In:
Returns:

True, if property is in ignore lists. False otherwise.

Type
boolean