-
Notifications
You must be signed in to change notification settings - Fork 67
Adding a Turf function
These instructions assume you are adding a Turf operation that returns NEW GEOMETRY If you plan to add a Turf operation that returns something other than geometry, such as count
, please look at this issue thread first.
Turf functions are their own geoprocesses within this application. Since each spatial operation requires different data types, parameters, and options, each Turf option must be specified individually.
Too add a new operation, find its relevant page in the Turf documentation. Here is buffer
for example.
We need to open /src/js/operations/Geo.js
and add a new object that describes the particular operation you want. Below is an example of buffer
:
buffer: {
maxFeatures: 1,
description: 'Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees.',
parameters: [
{
name: 'distance',
description: 'Distance to draw the buffer.',
type: 'number',
default: 10
},
{
name: 'unit',
type: 'select',
description: '',
options: ['miles', 'feet', 'kilometers', 'meters', 'degrees'],
default: 'miles'
}
]
},
Notice that there are two parameters, distance
and unit
. Each of these is optional according to Turf's documentation. Distance can be any number, but Unit can only be a particular set of options. Make sure if you want the user to only choose certain options to use type: 'select'
and list your options
accordingly. createsLayer
represents whether the operation returns a layer that should be placed on the map.
A greater list of possibly operation configurations can be seen below:
operationName: {
minFeatures: 1, // Validation: Minimum number of layers that this operation requires
maxFeatures: 2, // Validation: Maximum number of layers that this operation requires
description: 'Do something', // Form: Textual description of operation
disableForm: false, // Skip input form
parameters: [ // Form: Fields for input form
{
description: 'First field.', // Textual description of input field
type: 'text', // Type of input field (corresponds to HTML input types)
extra: 'maxlength=3', // Any extra string to be placed in input field tag element
default: 'blah', // Default value for field
}
]
}
To add the task to the menu, open /src/js/controller/AppController.js
. On this line you will see an array of different items. Add your new item here. Be sure it is named exactly the same as the turf operation!
You should now be able to rebuild the application and test out your new operation. Make sure you have some test data to work with. You can find some in the test
folder. If these files aren't working, making quick features at geojson.io typically works well.
If things aren't working, make sure to check out your console for javascript errors. If you are unable to solve the issue feel free to submit a ticket on the repository issues! Please include the error that you are receiving, the operation you are trying to add, and the data that you were testing with.
In order to make sure our operations are running as expected you should write some tests. MORE TO COME HERE!