Skip to content

Working with Resources

AdrianP edited this page Apr 19, 2024 · 9 revisions

Home


Freeboard-SK supports all of the resource types defined in the Signal K specification:

  • Routes
  • Waypoints
  • Charts
  • Notes
  • Regions

To display, create, update & delete resources Freeboard-SK requires that the Signal K server is able to service the relevant ../api/resources/<resource type> path using HTTP GET, PUT, POST and DELETE operations.

Signal K server v2 has built-in support for:

  • Routes
  • Waypoints
  • Notes
  • Regions

A provider plugin (e.g.@signalk/charts-plugin) is required for:

  • Charts

Freeboard-SK also provides some support for non Signal K standard resource paths, more specifically:

  1. Tracks: Geo-JSON MultiLineString feature data contained within a Signal K specification aligned resource entry available at the ../api/resources/tracks endpoint.
  2. ResourceSets: Geo-JSON FeatureCollection data contained within a Signal K specification aligned resource entry available at a user defined endpoint under ../api/resources/ e.g. ../api/resources/fishing.
  3. Load Resource: Allows the contents of a file to be uploaded to a non-standard resource path. Note: file contents is not validated prior to being uploaded to the Signal K server!

To use this additional functionality you will need to:

  • Ensure that the Resource Provider plug-in has been configured with the necessary Custom Resource types.
  • The required resource paths have been enabled (selected) in Freeboard-SK Settings.

Note: Freeboard-SK considers all enabled paths to contain ResourceSets except for the tracks path!

Tracks

If the ../api/resources/tracks path is present and enabled, this will present options to import and display Track data.

Track data operations can be found:

  • In the Layers list: a Tracks entry is displayed as an available resource type. Available tracks can be selected for display or removed from the server.
  • When using the Load from GPX or Load from GeoJSON operations to import this file data as Signal K resources.

Resource Sets

Data from all other resource paths that you enable in Freeboard Settings will be treated as ResourceSets.

ResourceSets are a non-standard Signal K resource format that can be created to form collections of features that can be displayed in layers on the map. They are a JSON file with a specific structure which can be created using any text editor.

The JSON structure chosen:

  1. Aligns closely with the current Signal K resource specification
  2. Adopts the use of GeoJSON FeatureCollection.

The ResourceSet file would be stored on the Signal K server in the folder used as the source for that path.

The file name should be a valid uuid (e.g. 0d95e282-3e1f-4521-8c30-8288addbdb69).

A minimal file would consist of the following:

{
   "type": "ResourceSet",
   "name": "My resource set name",
   "description": "Description of my resource set",
   "styles": { 
      "default": {
         "width": <number of pixels>,
         "stroke": "<valid css color value>",
         "fill": "<valid css color value>"
      }
   },
   "values": { 
      "type": "FeatureCollection",
      "features": [ ..GeoJSON Features... ]
   }
}
  • type: (mandatory) Must contain the text ResourceSet to identify the payload correctly to Freeboard.
  • name: (mandatory) Text containing the name of the ResourceSet (displayed when selecting which resources to display).
  • description: (optional) Text describing the content of the ResourceSet (displayed when selecting which resources to display).
  • styles: (mandatory) Object containing at minimum a default style definition. User defined styles are placed in this section.
  • values: (mandatory) Object containing a valid GeoJSON FeatureCollection.

GeoJSON Features:

All of the defined GeoJSON feature types are supported and are defined as per the GeoJSON specification within the FeatureCollection.

To enable a feature to be displayed with a particular style, assign a style in one of the following ways:

  1. Explicitly define the style within the feature properties.
  2. Reference a style defined in the styles section.
  3. Do not define an explicit style or reference a style to have the default style applied to the feature.

Example 1: Explicitly define a style using a style in properties

{
   ...
   "values": { 
      "type": "FeatureCollection",
      "features": [
         {
            "type": "Point",
            "geometry": { ... },
            "properties": {
               "style": {
                  "width": 10,
                  "stroke": "red",
                  "fill": "rgb(200,150,100)"
               }
            }
         }
      ]
   }

Example 2: Reference a defined style using styleRef in properties

{
   ...
   "styles": { 
      "default": {
         "width": 2,
         "stroke": "black",
         "fill": "yellow"
      },
      "mypointstyle": {
         "width": 6,
         "stroke": "blue",
         "fill": "cyan"
      },
      "green_dashed_line": {
         "stroke": "green",
         "fill": "cyan",
         "width": 3,
         "lineDash": [5,5]
     }
   },
   "values": { 
      "type": "FeatureCollection",
      "features": [
         {
            "type": "Point",
            "geometry": { ... },
            "properties": {
               "styleRef": "mypointstyle"
            }
         }
      ]
   }

Example 3: Use default style

{
   ...
   "styles": { 
      "default": {
         "width": 2,
         "stroke": "black",
         "fill": "yellow"
      }
   },
   "values": { 
      "type": "FeatureCollection",
      "features": [
         {
            "type": "Point",
            "geometry": { ... },
            "properties": { }
         }
      ]
   }

STYLE Attributes:

The following Style attributes are supported and are applied as follows:

"<styleId>": {
   "stroke": "green",
   "fill": "cyan",
   "width": 3, 
   "lineDash": [5,5]
}
  • stroke: Describes the color of the pen used to draw the feature. For a line feature it would be the color of the line, for a point it would be the color of the bounding circle.
  • fill: Describes the color used to fill a point feature or an area.
  • width: For a line feature it represents the width of the line drawn. For a point feature it represents the radius of the circle drawn.
  • lineDash: (Line features only) Used to draw a dashed line, supply an array of numbers to describe the length of the dash and the space between dashes. e.g. [5,5] = dash 5px long, space of 5px to the next dash