The addEventListener()
method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Optional
options: boolean | AddEventListenerOptionsComputes the properties (statistics) of a track, including total time, distance, ascent, descent, physical demand, time and distance for each stopover.
Delete the hiking from the server
The dispatchEvent()
method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.
Returns the uuid of the hiking. If the hiking is not saved yet, this function returns undefined.
Handle import of GPX and KML files
Load the hiking from the server.
Redo the last action
The removeEventListener()
method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.
Optional
options: boolean | EventListenerOptionsRemove a stopover from the stopover list
Reverse the track
Create or update the hiking to the server
Set the distance of a stopover in meters or reset it to the computed value (if undefined
is passed)
Set the duration of a stopover in minutes or reset it to the computed value (if undefined
is passed)
Set the features of a stopover
Change the name of a stopover
Set the type of the hiking. The type can be one of hiking
, hiking_activity
or hiking_proposition
.
Undo the last action
Update the hiking properties.
HikingEditor
Demos
Description
The HikingEditor class is responsible for editing hiking tracks and stopovers.
To construct a new HikingEditor, you need to pass an OpenLayers map instance:
This will allow the user to create a new hiking proposition.
To edit an existing hiking activity, you need to pass the uuid of the hiking and the type:
When the hiking is loaded, a
loaded
event is fired. The event detail contains the same properties as thechange
event.The constructor takes an option object HikingEditor.HikingEditorOptions with the following properties:
map
: the OpenLayers map instancetype
: the type of the hiking, one ofhiking
,hiking_activity
orhiking_proposition
uuid
: the optional uuid of the hiking to editThe
type
property can be changed with the HikingEditor.setType function:An other hiking can be loaded with the HikingEditor.loadHiking function:
Create or update hiking
To save the hiking, call the HikingEditor.save function, this will create or update the hiking on the server.
Deleting
To delete the hiking, call the HikingEditor.delete function, this will delete the hiking from the server.
Update hiking properties
To update the properties of the hiking that are not related to the geometries (for example the title, description, or any other property), call the HikingEditor.updateHikingProperties function and pass an object with the properties to update:
FIXME: what if the the hiking is not saved yet ?
User interaction
After each user interaction, a
change
event is fired.Edit mode
By default, the editor is in
edit
mode. In this mode, the user can add, move and remove control points. To switch toview
mode, set theedit
property tofalse
:Snapping mode
The lines are automatically snapped to the closest hiking path. To disable snapping, set the
snapping
property tofalse
:Reverse the track
To reverse the track, call the HikingEditor.reverse function:
The reverse function will trigger a
change
event.Undo/Redo
The editor can undo or redo the actions to the geometries of the control points. To undo the last action, call the HikingEditor.undo function:
To redo the last action, call the HikingEditor.redo function:
canUndo
: true if the user can undo the last actioncanRedo
: true if the user can redo the last actionThe undo and redo functions will trigger a
change
event.Control points
The control points are the points that are between the segments of the track, they can be added, moved and removed by the user. They are represented by a small circle on the map.
Stopovers
The stopovers are a special type of control points that the user chooses to create by clicking on a control point. The first and last control points are always stopovers. They are represented by a big circle on the map.
A stopover has a name and and an optional list of features. A duration and a distance from the previous stopover is computed for each stopover.
Change Event
Every time a change is made to the stopovers, a
change
event is fired. The event detail contains the values of the stopovers.To register an event listener for the
change
event, use theaddEventListener
method:All the stopovers are returned in the
stopovers
property of the event detail, each stopover has the following properties:uid
: the unique id of the stopover. this id is used to identify the stopover in the other methods.swissNames
: an array of swiss names for this locationname
: the name of the stopover, if the name was not set by the HikingEditor.setStopOverName function, the first swiss name is used.features
: an array of features that the user can add to the stopoverduration
: the walking time duration of the stopover from the previous stopover in minutes. This value can be overwritten by using the HikingEditor.setStopOverDuration function.distance
: the distance of the stopover from the previous stopover in meters. This value can be overwritten by using the HikingEditor.setStopOverDistance function.coordinates
: the coordinates of the stopover in EPSG:4326 projectionIn addition to the stopovers, the event detail contains the following properties:
type
: the type of the hiking, one ofhiking
,hiking_activity
orhiking_proposition
canUndo
: true if the user can undo the last actioncanRedo
: true if the user can redo the last actionChange a stopover name
To change the name of a stopover, use the HikingEditor.setStopOverName function and pass the uid of the stopover:
Calling this method will trigger a
change
event.Set features to a stopover
Every stopover can have a list of features representing a point of interest at this location. A feature is an object with a
type
property and an optionaltitle
property.To set the features of a stopover, use the HikingEditor.setStopOverFeatures function and pass the uid of the stopover:
When calling this function, existing features are replaced by the new list.
Calling this method will trigger a
change
event.Set duration to a stopover
To set a custom duration of a stopover in minutes, use the HikingEditor.setStopOverDuration function and pass the uid of the stopover:
Can also be used to reset the duration to the computed value by passing
undefined
:Calling this method will trigger a
change
event.Set distance to a stopover
To set a custom distance of a stopover in meters, use the HikingEditor.setStopOverDistance function and pass the uid of the stopover:
Can also be used to reset the distance to the computed value by passing
undefined
:Calling this method will trigger a
change
event.Remove stopover
To remove a stopover, use the HikingEditor.removeStopOver function and pass the uid of the stopover:
When a stopover is removed, the custom name and features are also removed and cannot be recovered. Calling this method will trigger a
change
event.Reset custom facts
To reset the custom facts for the hiking and stopovers, use the HikingEditor.resetCustomFacts function:
This will recalculate the duration, distance, ascent, descent and physical_demand based only in the geometry.
GPX and KML Import
To create a hiking from a GPX or a KML file, use the HikingEditor.importGpxOrKml function and pass the file. For GPX, the line coordinates will be primarily extracted from tracks and if no tracks are found, from routes. Control points for both formats are snapped to the line - meaning that every control point has a corresponding point on the line. The first and last control points are always created as stopovers, even if no waypoints are found. The coordinates are expected to be in EPSG:4326 projection and in Cartesian order (lon, lat).