Oskari API Documentation

Select event

admindown-arrow
cataloguedown-arrow
frameworkdown-arrow
mappingdown-arrow
statisticsdown-arrow
uidown-arrow

DrawingEvent RPC

Notifies that sketch has been changed or drawing is finished.

Description

Used to notify that sketch is changed or drawing finished. Event is sent every time that sketch changes (cursor is moved while drawing) and when drawing is finished.

Parameters

(* means the parameter is required)

Name Type Description Default value
\* id String drawing id as given in StartDrawingRequest
\* geojson Object Drawn features in GeoJson format
\* data Object additional info
\* isFinished Boolean True if drawing is finished

RPC

Unfinished event is sent every time that sketch changes.


{
  "name": "DrawingEvent",
  "id": "my functionality id",
  "geojson": {...},
  "data": {
    "area": 594933884.35, // The sum of all areas in square meters
    "buffer": 0, // requested buffer
    "bufferedGeoJson": {...}, // contains buffered features if buffer is requested
    "length": 264071.08700662444, // The sum of all line lengths in meters
    "showMeasureOnMap": true,
    "shape": "Polygon" // requested shape
  },
  "isFinished": false
}

Finished event occurs when sketch is finished. For example after StopDrawingRequest, double-click or end drag on modify.


{
  "name": "DrawingEvent",
  "id": "my functionality id",
  "geojson": { ... },
  "data": { ... },
  "isFinished": true
}

Event methods

getName()

Returns name of the event

getId()

Returns id of the drawing

getGeoJson)

Returns geojson of the drawing

getData()

Returns data of the drawing

getIsFinished()

Returns true if drawing is finished

getParams()

Returns all the params of the event.


{
    name: this.getName(),
    id: this.getId(),
    geojson: this.getGeoJson(),
    data: this.getData(),
    isFinished: this.getIsFinished()
};

Examples

Event handler for own finished drawings:

    handleDrawingEvent (event) {
        if (event.getId() === MY_ID && event.getIsFinished()) {
            const geojson = event.getGeoJson();
            const data = event.getData();
            // do something with data and features
        }
    }

DrawTools.StartDrawingRequest with id measure and shape Polygon. Event for valid finished drawing:


{
  "name": "DrawingEvent",
  "id": "measure",
  "isFinished": true,
  "data": {
      "area": 10527600800.565893,
      "buffer": 0,
      "shape": "Polygon",
      "showMeasureOnMap": false,
      "bufferedGeoJson": {
        "type": "FeatureCollection",
        "crs": "EPSG:3067",
        "features": []
      }
    },
  "geojson": {
    "type": "FeatureCollection",
    "crs": "EPSG:3067",
    "features": [
      {
        "type": "Feature",
        "id": "drawFeature0",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [330356.9714432531,6903137.5567356525],
            [328820.9714432531,6823265.5567356525],
            [422004.9714432531,6818145.5567356525],
            [439924.9714432531,6875489.5567356525],
            [383352.9611277134,6932447.561893423],
            [335224.9611277134,6934495.561893423],
            [310136.9611277134,6924767.561893423],
            [330356.9714432531,6903137.5567356525]
          ]
        },
        "properties": {
          "area": 10527600800.565893,
          "valid": true
        }
      }
    ]
  }
}

DrawTools.StartDrawingRequest with id measure and shape Polygon. Event for invalid finished drawing:


{
  "name": "DrawingEvent",
  "id": "measure",
  "isFinished": true,
  "data": {
      "area": 594933884.3552058,
      "buffer": 0,
      "shape": "Polygon",
      "showMeasureOnMap": false,
      "bufferedGeoJson": {
        "type": "FeatureCollection",
        "crs": "EPSG:3067",
        "features": []
      }
    },
  "geojson": {
    "type": "FeatureCollection",
    "crs": "EPSG:3067",
    "features": [
      {
        "type": "Feature",
        "id": "drawFeature0",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
              [350208,7011328],
              [385024,6982144],
              [330240,6947328],
              [386560,6924800],
              [350208,7011328]
          ]
        },
        "properties": {
          "area": "Polygon self-intersection is not allowed. Edit current polygon or draw a new polygon.",
          "valid": false
        }
      }
    ]
  }
}