sww
    Preparing search index...

    Class HikingEditor

    HikingEditor

    The HikingEditor class is responsible for editing hiking tracks and stopovers.

    To construct a new HikingEditor, you need to pass an OpenLayers map instance:

    const hikingEditor = new sww.HikingEditor({
    map: map,
    type: "hiking_proposition",
    });

    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:

    const hikingEditor = new sww.HikingEditor({
    map: map,
    type: "hiking_activity",
    uuid: "12345678-1234-1234-1234-123456789012",
    });

    When the hiking is loaded, a loaded event is fired. The event detail contains the same properties as the change event.

    The constructor takes an option object HikingEditor.HikingEditorOptions with the following properties:

    • map: the OpenLayers map instance
    • type: the type of the hiking, one of hiking, hiking_activity or hiking_proposition
    • uuid: the optional uuid of the hiking to edit

    The type property can be changed with the HikingEditor.setType function:

    hikingEditor.setType("hiking");
    

    An other hiking can be loaded with the HikingEditor.loadHiking function:

    hikingEditor.loadHiking("12345678-1234-1234-1234-123456789012");
    

    To save the hiking, call the HikingEditor.save function, this will create or update the hiking on the server.

    To delete the hiking, call the HikingEditor.delete function, this will delete the hiking from the server.

    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:

    hikingEditor.updateHikingProperties({
    title: {"fr": "title fr", "de": "title de", "it": "title it", "en": "title en"},
    best_hiking_time: [1, 2],
    });

    FIXME: what if the the hiking is not saved yet ?

    • A new control point is added with a single click on the map.
    • A new control point is added between on a line by dragging the line.
    • The control points and stopovers can be moved by dragging.
    • The control points and stopovers can be removed by double clicking on them.
    • A new stopover is created by clicking on a control point.

    After each user interaction, a change event is fired.

    By default, the editor is in edit mode. In this mode, the user can add, move and remove control points. To switch to view mode, set the edit property to false:

    hikingEditor.edit = false;
    

    The lines are automatically snapped to the closest hiking path. To disable snapping, set the snapping property to false:

    hikingEditor.snapping = false;
    

    To reverse the track, call the HikingEditor.reverse function:

    hikingEditor.reverse();
    

    The reverse function will trigger a change event.

    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:

    hikingEditor.undo();
    

    To redo the last action, call the HikingEditor.redo function:

    hikingEditor.redo();
    
    • canUndo: true if the user can undo the last action
    • canRedo: true if the user can redo the last action

    The undo and redo functions will trigger a change event.

    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.

    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.

    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 the addEventListener method:

    hikingEditor.addEventListener("change", (event) => {
    for (const stopover of event.detail.stopovers) {
    console.log(stopover);
    }
    });

    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 location
    • name: 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 stopover
    • duration: 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 projection

    In addition to the stopovers, the event detail contains the following properties:

    • type: the type of the hiking, one of hiking, hiking_activity or hiking_proposition
    • canUndo: true if the user can undo the last action
    • canRedo: true if the user can redo the last action

    To change the name of a stopover, use the HikingEditor.setStopOverName function and pass the uid of the stopover:

    hikingEditor.setStopOverName(123, "Bümpliz Nord Bahnhof");
    

    Calling this method will trigger a change event.

    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 optional title property.

    To set the features of a stopover, use the HikingEditor.setStopOverFeatures function and pass the uid of the stopover:

    hikingEditor.setStopOverFeatures(123, [
    { type: "shopping", title: "Food and Stuff" },
    { type: "parking" },
    ]);

    When calling this function, existing features are replaced by the new list.

    Calling this method will trigger a change event.

    To set a custom duration of a stopover in minutes, use the HikingEditor.setStopOverDuration function and pass the uid of the stopover:

    hikingEditor.setStopOverDuration(123, 30);
    

    Can also be used to reset the duration to the computed value by passing undefined:

    hikingEditor.setStopOverDuration(123, undefined);
    

    Calling this method will trigger a change event.

    To set a custom distance of a stopover in meters, use the HikingEditor.setStopOverDistance function and pass the uid of the stopover:

    hikingEditor.setStopOverDistance(123, 1000);
    

    Can also be used to reset the distance to the computed value by passing undefined:

    hikingEditor.setStopOverDistance(123, undefined);
    

    Calling this method will trigger a change event.

    To remove a stopover, use the HikingEditor.removeStopOver function and pass the uid of the stopover:

    hikingEditor.removeStopOver(123);
    

    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.

    To reset the custom facts for the hiking and stopovers, use the HikingEditor.resetCustomFacts function:

    hikingEditor.resetCustomFacts();
    

    This will recalculate the duration, distance, ascent, descent and physical_demand based only in the geometry.

    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).

    Hierarchy

    • EventTarget
      • HikingEditor
    Index

    Constructors

    • Parameters

      • options: HikingEditorOptions

      Returns HikingEditor

    Accessors

    • get edit(): boolean

      Returns boolean

    • set edit(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get snapping(): boolean

      Returns boolean

    • set snapping(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    Methods

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Parameters

      • type: string
      • callback: null | EventListenerOrEventListenerObject
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Computes the properties (statistics) of a track, including total time, distance, ascent, descent, physical demand, time and distance for each stopover.

      Returns TrackProperties

    • Delete the hiking from the server

      Returns void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Returns HikingProfile

    • Returns the uuid of the hiking. If the hiking is not saved yet, this function returns undefined.

      Returns undefined | string

    • Handle import of GPX and KML files

      Parameters

      • file: File

      Returns void

    • Load the hiking from the server.

      Parameters

      • uuid: undefined | string

      Returns Promise<void>

    • Redo the last action

      Returns void

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

      MDN Reference

      Parameters

      • type: string
      • callback: null | EventListenerOrEventListenerObject
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Remove a stopover from the stopover list

      Parameters

      • uid: string

      Returns void

    • Returns void

    • Reverse the track

      Returns void

    • Create or update the hiking to the server

      Returns Promise<string>

    • Set the distance of a stopover in meters or reset it to the computed value (if undefined is passed)

      Parameters

      • uid: string
      • distance: string | number

      Returns void

    • Set the duration of a stopover in minutes or reset it to the computed value (if undefined is passed)

      Parameters

      • uid: string
      • duration: string | number

      Returns void

    • Set the features of a stopover

      Parameters

      • uid: string
      • features: unknown[]

      Returns void

    • Change the name of a stopover

      Parameters

      • uid: string
      • name: string

      Returns void

    • Set the type of the hiking. The type can be one of hiking, hiking_activity or hiking_proposition.

      Parameters

      • type: "hiking" | "hiking_activity" | "hiking_proposition"

      Returns void

    • Undo the last action

      Returns void

    • Update the hiking properties.

      • Adds new properties that don't exist in hikingProperties
      • Updates existing properties with new values
      • Removes properties when their value is undefined

      Parameters

      • properties: Record<string, unknown>

      Returns void