new WidgetLayer(latLng, origin)
A Widgetable that can be added to the map.
Before using this class, set map option keyboard to false! If you don't do that, you'll encounter numerous problems. Do it when you create map, like this:
let map = L.map("map", { keyboard: false });
Warning: If you're targeting older browsers and adding only L.ALS.Widgets.SimpleLabel to this layer, you may want to use non-breaking hyphen (UTF-8 symbol) to prevent unnecessary word wrapping.
Warning: If you want to use this only for labels, consider using L.ALS.LeafletLayers.LabelLayer since it's way faster than WidgetLayer.
Parameters:
| Name | Type | Description |
|---|---|---|
latLng |
Array.<number> | L.LatLng | Position of this object. |
origin |
"topLeft" | "topCenter" | "topRight" | "bottomLeft" | "bottomCenter" | "bottomRight" | "leftCenter" | "rightCenter" | "center" | Origin of this widget, i.e. which point of this widget will be placed at given latLng |
- Mixes In:
- L.Marker
Extends
Members
-
<protected> constructorArguments :Array.<any>
-
Contains arguments passed to this constructor
Type:
- Array.<any>
- Inherited From:
-
container :HTMLDivElement
-
Container to add widgets to. This element must be added to the page.
Type:
- HTMLDivElement
- Inherited From:
-
<protected> serializationIgnoreList :Array.<string>
-
Contains properties that won't be serialized. Append your properties at the constructor.
Type:
- Array.<string>
- Inherited From:
Methods
-
addWidget(widget)
-
Adds widget to this widgetable
Parameters:
Name Type Description widgetL.ALS.Widgets.BaseWidget Widget to add
- Inherited From:
- Overrides:
Returns:
This
- Type
- L.ALS.Widgetable
-
addWidgets(widgets)
-
Adds all widgets to this widgetable
Parameters:
Name Type Description widgetsL.ALS.Widgets.BaseWidget Widgets to add
- Inherited From:
Returns:
This
- Type
- L.ALS.Widgetable
-
deserializeWidgets(serializedWidgets, seenObjects)
-
Deserializes widgets and adds them to this object. Removes all previously added widgets. Use this if you want to deserialize only widgets in your own Widgetable.
Parameters:
Name Type Description serializedWidgetsObject Result of
L.ALS.Widgetable#serializeWidgetsseenObjectsObject Already seen objects' ids. Intended only for internal use.
- Inherited From:
-
getObjectToSerializeTo(newObject, seenObjects)
-
Registers this object for serialization and deserialization. Returns an object to serialize custom properties to.
Call it first, if you implement your own algrorithm, and serialize to the returned object!
Parameters:
Name Type Description newObjectObject Object to where you'll serialize
seenObjectsObject Already seen objects
- Inherited From:
Returns:
Object to serialize to.
- Type
- Object
-
getWidgetById(id)
-
Finds widget by ID
Parameters:
Name Type Description idstring ID of a control to find
- Inherited From:
Returns:
Widget with given ID.
-
removeAllWidgets()
-
Removes all widgets from the container
- Inherited From:
- Overrides:
Returns:
This
- Type
- L.ALS.Widgetable
-
removeWidget(id)
-
Removes widget from the container
Parameters:
Name Type Description idstring ID of a widget to remove
- Inherited From:
- Overrides:
Returns:
This
- Type
- L.ALS.Widgetable
-
serialize(seenObjects)
-
Serializes this object to JSON. If overridden, you MUST perform following operations before returning JSON:
let json = {} // Your JSON ... // Perform serialization json.constructorArguments = this.serializeConstrutorArguments(); // Serialize constructor arguments json.serializableClassName = this.serializableClassName; // Add class name to JSON return json; // Finally return JSONParameters:
Name Type Description seenObjectsObject Already seen objects
- Inherited From:
Returns:
This serialized object
- Type
- Object
-
serializeConstructorArguments()
-
Serializes constructor arguments. If your constructor is not empty, result of this method MUST be added to json at
L.ALS.Serializable#serializeas "_construtorArgs" property.Deprecated in favor of
L.ALS.Serializable#getObjectFromSerializedwhich uses this function under-the-hood.- Inherited From:
- Deprecated:
-
- Yes
Returns:
Serialized constructor arguments
- Type
- Array
-
serializeWidgets(seenObjects)
-
Serializes widgets.
If you're serializing
L.ALS.Layer, you don't need to call this method,L.ALS.Layer#getObjectToSerializeToalready does that.Parameters:
Name Type Description seenObjectsObject Already seen objects' ids. Intended only for internal use.
- Inherited From:
Returns:
Object where keys are widget's ids and values are serialized widgets themselves
- Type
- Object
-
setConstructorArguments(args)
-
Sets constructor arguments for serialization
Parameters:
Name Type Description argsArguments to set
- Inherited From:
-
setOrigin(origin)
-
Sets origin of this layer
Parameters:
Name Type Description origin"topLeft" | "topCenter" | "topRight" | "bottomLeft" | "bottomCenter" | "bottomRight" | "leftCenter" | "rightCenter" | "center" Origin to set
Returns:
This