new Layer(wizardResults, settings)
Base class for all layers for the Layer System.
Basically, it's a wrapper around L.FeatureGroup. It doesn't provide all of it's methods because they're used internally in the layer system, and their usage will break it. So do NOT touch the actual FeatureGroup object.
Every layer has its own menu which you can modify by using methods inherited from L.ALS.Widgetable.
Usage:
- Set
L.ALS.Layer#defaultNameproperty to the default name of your layer. - Create wizard by extending
L.ALS.Wizard. - Set
L.ALS.Layer.wizardto an instance of your wizard. - If you need to implement settings for your layer, extend
L.ALS.Settingsand setL.ALS.Layer.settingsto an instance of your settings. - Implement
L.ALS.Layer#initmethod. It's used as a constructor. - Modify layer menu by using methods inherited from
L.ALS.Widgetable. - Implement your own methods or extend current ones. Basically, make it work :D
Please, read the docs for each public method, you might need to (if not should) override most of them.
Important notes:
- NEVER use
L.LayerGroupbecause it breaks layer system! - Use
L.ALS.Layer#addLayersandL.ALS.Layer#removeLayersto add and remove Leaflet layers. - To hide Leaflet layers from the map, use
this.map.remove()andthis.map.add(). - Use
L.ALS.Layer#addEventListenerToandL.ALS.Layer#removeEventListenerFromto add and remove event listeners from objects and map. - Use
L.ALS.ControlManagermethods to manage controls. - Unless your layer is super simple, you'll most likely need to implement custom serialization and deserialization mechanisms. Please, refer to the
L.ALS.Serializabledocs and example project for this.
Parameters:
| Name | Type | Description |
|---|---|---|
wizardResults |
Object | Results compiled from the wizard. It is an object who's keys are IDs of your widgets and values are, well, their values. |
settings |
SettingsObject | Current layer settings. |
- Mixes In:
Extends
Members
-
<static> settings :L.ALS.Settings
-
Settings instance
Type:
-
<static> wizard :function
-
Wizard class which gives a layer its initial properties
Type:
- function
-
<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:
-
creationCancelled
-
Whether creation of this layer has been cancelled at
L.ALS.Layer#initby callingcancelCreation(). -
<readonly> defaultName :string
-
Name to be assigned to this layer by default. Set it to locale property to localize it.
Type:
- string
-
<readonly> id :string
-
Unique ID of this layer
Type:
- string
-
<readonly> isSelected :boolean
-
Indicates whether this layer is selected or not. Should not be modified!
Type:
- boolean
-
<readonly> isShown :boolean
-
Indicates whether this layer is shown or not. Do NOT modify!
Type:
- boolean
-
layerSystem :L.ALS.System
-
Layer system managing this layer
Type:
-
<protected> map :L.Map
-
Map on which this layer is being added
Type:
- L.Map
-
pane :string
-
Pane name for this layer
Type:
- string
-
paneElement :HTMLDivElement
-
Pane element for this layer
Type:
- HTMLDivElement
-
<protected> serializationIgnoreList :Array.<string>
-
Contains properties that won't be serialized. Append your properties at the constructor.
Type:
- Array.<string>
- Inherited From:
-
writeToHistoryOnInit
-
Whether ALS should write an entry to the history when this layer is created or duplicated, i.e. when
L.ALS.Layer#initis called.Setting it to
falseallows you to control when an action should be added to the history. Useful for things like dynamic content loading. You also may want to useL.ALS.operationsWindowto display loading text and animation.You should always call
L.ALS.Layer#writeToHistorywhen you're done!You can always change the value of this property back to
trueto make ALS write to history automatically.Example
Read file from a wizard asynchronously. Write to the history when file is read. L.ALS.MyLayer = L.ALS.Layer.extend({ writeToHistoryOnInit: false, // Disable writing to the history on initialization init: function (wizardResults, settings) { // Read a file from a wizard let file = wizardResults["fileWidget"][0], fileReader = new FileReader(); fileReader.addEventListener("load", (event) => { // File reading logic here... writeToHistory(); // File is read, time to write layer creation to the history }); } });
Methods
-
<static> deserialize()
-
<static> deserializeImportantProperties(serialized, instance)
-
Deserializes some important properties. Must be called at
deserializein any layer!Parameters:
Name Type Description serializedObject Serialized object
instanceL.ALS.Layer | Object New instance of your layer
-
<protected> _onDeselect()
-
Called whenever user deselects this layer.
-
<protected> _onSelect()
-
Called whenever user selects this layer.
-
addEventListenerTo(object, type, handler)
-
Adds event listener (handler) to the object. Use it instead of
object.on().Note: we use object's methods as handlers to be able to save and restore them when user saves the project.
Parameters:
Name Type Description objectObject Object to add listener to
typestring Event type, string in format used by Leaflet
handlerstring Your object's method that will handle this event
-
addLayers(layers)
-
Adds Leaflet layers to this layer.
Do NOT override!
Parameters:
Name Type Description layersL.Layer Layers to add
-
addWidget(widget)
-
Adds widget to this widgetable
Parameters:
Name Type Description widgetL.ALS.Widgets.BaseWidget Widget to add
- Inherited From:
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
-
applyNewSettings(settings)
-
Called whenever user updates the settings. Use it to update your layer depending on changed settings.
Parameters:
Name Type Description settingsSettingsObject Same as settings passed to
L.ALS.Layer#init -
<protected> copySettingsToThis(settings)
-
Copies settings to this layer as properties
Parameters:
Name Type Description settingsSettingsObject settingsargument passed toL.ALS.Layer#init -
deleteLayer(shouldAskUser, writeToHistory)
-
Deletes this layer
Parameters:
Name Type Description shouldAskUserboolean If set to true, the message asking if user wants to delete selected layer will be displayed. Otherwise, layer will be silently deleted.
writeToHistoryboolean If true, will write deletion to the history
-
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:
-
eachLayer()
-
- See:
-
- FeatureGroup.eachLayer
Returns:
this
- Type
- L.ALS.Layer
-
getBounds()
-
- See:
-
- FeatureGroup.getBounds
-
getName()
-
Returns:
Name of this layer
- Type
- string
-
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:
- Overrides:
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.
-
init(wizardResults, settings, cancelCreation)
-
Use this method instead of
L.ALS.Layer#initializeParameters:
Name Type Description wizardResultsObject Results compiled from the wizard. It is an object who's keys are IDs of your controls and values are values of your controls.
settingsSettingsObject Current layer settings and both default and custom general settings.
cancelCreationfunction A function that will safely cancel creation of this layer. If your initialization calls other layer methods, consider using
L.ALS.Layer#creationCancelledproperty to detect whether creation has been cancelled and to avoid getting errors. You should call this function only in synchronous code, only atL.ALS.Layer#initand only before adding any widgets! -
onDelete()
-
Called upon deletion. Here you can clean up everything you've done which can't be undone by the system (i.e., layers added directly to the map or created elements on the page)
-
onDeselect()
-
Called whenever user deselects this layer.
-
onHide()
-
Called whenever layer is being hidden
-
onNameChange()
-
Called whenever user changes this layer's name
-
onSelect()
-
Called whenever user selects this layer.
-
onShow()
-
Called whenever layer is being shown
-
removeAllWidgets()
-
Removes all widgets from the container
- Inherited From:
Returns:
This
- Type
- L.ALS.Widgetable
-
removeEventListenerFrom(object, type, handler)
-
Removes event listener (handler) to the specified event type from the object. Use it instead object.off().
Parameters:
Name Type Description objectobject Object to remove event listener from
typestring Event type
handlerstring Event listener (handler) to remove
- See:
-
- Layer.addEventListenerTo For more information
-
removeLayers(layers)
-
Removes added Leaflet layers with its event handlers.
Parameters:
Name Type Description layersL.Layer Layers to remove. If layer extends LayerGroup, will also remove Leaflet layers contained in it.
-
removeWidget(id)
-
Removes widget from the container
Parameters:
Name Type Description idstring ID of a widget to remove
- Inherited From:
Returns:
This
- Type
- L.ALS.Widgetable
-
serialize(seenObjects)
-
Serializes this layer.
Default implementation is:
let serialized = L.ALS.Widgetable.prototype.serialize.call(this, seenObjects); this.serializeImportantProperties(serialized); return serialized;Parameters:
Name Type Description seenObjectsObject Already seen objects
- Overrides:
Returns:
- 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
-
serializeImportantProperties(serialized)
-
Serializes some important properties. Must be called at
L.ALS.Layer#serializein any layer!Deprecated in favor of
L.ALS.Serializable.getObjectFromSerializedwhich uses this function under-the-hood.Parameters:
Name Type Description serializedObject Your serialized object
- Deprecated:
-
- Yes
-
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:
-
setName(name)
-
Sets name of this layer
Parameters:
Name Type Description namestring Name to set
-
setStyle()
-
- See:
-
- FeatureGroup.setStyle
Returns:
this
- Type
- L.ALS.Layer
-
toGeoJSON()
-
Called when layer is being exported. If you want to export more than only geometry, override this method.
Default implementation is:
return this._leafletLayers.toGeoJSON();- See:
-
- L.FeatureGroup.toGeoJSON
-
writeToHistory()
-
Writes a record to the history. Call it at the end of each action.
This method interferes with serialization and deserialization. It won't do anything, if called when serialization or deserialization hasn't finished, for example, when restoring from history.
Basically, an alias for
L.ALS.System#writeToHistory.