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 |
- Mixes In:
Extends
Members
-
<static> DefaultDisplayOptions
-
Display options to match ALS style
Properties:
Name Type Default Description NormalDisplayOptions {"backgroundColor":"white","borderColor":"#ccc","fontColor":"black"} Normal label, looks like WidgetLayer
ErrorDisplayOptions {"backgroundColor":"#ffbebe","borderColor":"darkred","fontColor":"black"} Represents error message
WarningDisplayOptions {"backgroundColor":"#fff4c3","borderColor":"goldenrod","fontColor":"black"} Represents warning message
SuccessDisplayOptions {"backgroundColor":"#e3ffd3","borderColor":"green","fontColor":"black"} Represents success message
MessageDisplayOptions {"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()
-
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 idstring 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.
latLngArray.<number> | L.LatLng Position of a label
textany Label text
displayOptionsDisplayOptions Label display options
-
addTo(map)
-
Adds this layer to a given map
Parameters:
Name Type Description mapMap to add this layer to.
- Inherited From:
Returns:
this
-
canvasCoordsToLatLng(coords)
-
Converts canvas coordinates to latLng.
Parameters:
Name Type Description coordsArray.<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()ordeserialize(). Should not be called in the middle of serialization or deserialization, for example, atserialize().Parameters:
Name Type Description seenObjectsObject seenObjectsargument 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 idstring 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 serializedObject Serialized object or primitive
seenObjectsObject 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 primitivePrimitive 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 dataContains information about the canvas
Properties
Name Type Description layerthis
canvasHTMLCanvasElement Canvas
boundsCurrent map bounds, see
L.Map.getBounds()sizeCurrent map size, see
L.Map.getSize()zoomnumber 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 propertystring Property name
objectObject 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 propertystring Property name
objectObject 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 idstring 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
serializationIDto the object and adds it toseenObjects.Parameters:
Name Type Description serializedObject Serialized Serializable object
seenObjectsAlready seen objects' ids. Intended only for internal use.
Returns:
Instance of given object or
serializedargument if constructor hasn't been found- Type
- L.ALS.Serializable | Object
-
getSerializableConstructor(className)
-
Finds a constructor by given class name
Parameters:
Name Type Description classNamestring Full class name. Just pass serialized.serializableClassName.
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 latLngCoordinate 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 mapMap to add this layer to.
- Inherited From:
-
onRemove(map)
-
Called upon layer removal. If overridden, parent method must be called!
Parameters:
Name Type Description mapMap to remove this layer from
- Inherited From:
-
redraw()
-
Redraws content of this layer.
- Inherited From:
Returns:
this
-
serializeAnyObject(object, seenObjects)
-
Generic serialization mechanism. Tries to serialize everything possible
Parameters:
Name Type Description objectAny object or primitive to serialize
seenObjectsObject 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 primitivePrimitive 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 automaticallyRedrawboolean If set to true, this canvas will automatically redraw itself.
-
setInteractive(interactive)
-
Sets this layer to be interactive or not.
Parameters:
Name Type Description interactiveboolean If true, this layer will be interactive. Otherwise layer will be static.
- Inherited From:
-
setLabelDisplayOptions(id, displayOptions)
-
Sets display options of a label with given ID.
Parameters:
Name Type Description idstring ID of a label to set display options of.
displayOptionsDisplayOptions Options to set
-
setLabelLatLng(id, latLng)
-
Sets position of a label with given ID.
Parameters:
Name Type Description idstring ID of a label to set position of.
latLngArray.<number> | L.LatLng Position of a label
-
setLabelText(id, text)
-
Sets text of a label with given ID
Parameters:
Name Type Description idstring ID of a label to set text of.
textany 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 propertyParameters:
Name Type Description propertystring Name of the property
objectL.ALS.Serializable | Object Object containing ignore lists
isGetterboolean Indicates whether given property is getter or not
checkOnlyIgnoreListboolean 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