Skip to main content

SDK Modules

The following modules allow you to interact with the different SDK components

General Data Module

Provides functions that provide general information about the user and about the farms and fields visible in the interface.

getUserData()

Provides general information about the user.

Parameters

No parameters required.

Returns

An object with all the information about the logged in user:

  • id: string
  • tipo_usuario: string
  • datos: object
    • nombre: string
    • apellido: string
    • email: string
    • locale: string
  • admin: boolean
  • supervisor: boolean

getFarms()

Provides general information about the user's fields and farms.

Parameters

No parameters required.

Returns

Array of objects with information about each of the farms the user has access to:

  • id: String
  • nombre: String
  • bounds: Array [ xmin, ymin, xmax, ymax ]
  • permisos: Number[]
  • role: Number
  • supervised: Object[]
  • lotes: Object[]
    • id: number
    • nombre: String
    • country: String
    • wkt: String
    • bounds: Array [ xmin, ymin, xmax, ymax ]
    • centroide: string
    • area: Number
    • permisos: Number[]
    • role: Number

getFarmById()

Provides information about a specific farm.

Parameters

ParameterTypeDescription
farmIDnumberid of the farm for which information is required

Returns

Object with the requested farm information:

  • id: number
  • bounds: Array [ xmin, ymin, xmax, ymax ]
  • nombre: string
  • lotes: Array [object,...]
    • id: number
    • bounds: Array [ xmin, ymin, xmax, ymax ]
    • centroide: string
    • area: number
    • nombre: string
    • wkt: string

getFieldById()

Provides information about a specific field

Parameters

ParameterTypeDescription
fieldIDnumberid of the field for which information is required

Returns

Object with the requested field information:

  • id: number
  • bounds: Array [ xmin, ymin, xmax, ymax ]
  • centroide: string
  • area: number
  • nombre: string
  • wkt: string

getSpacesData()

Provides information about the space, if any, of the logged in user.

Parameters

No parameters required.

Returns

Object with the requested field information:

  • id: number
  • logo: string
  • thumbnail: string
  • color: string
  • name: string

getGlobalUnits()

Provides the logged user units.

Parameters

No parameters required.

Returns

Array of objects with each unit data. Each object contains:

  • group: string (The unit class group)
  • description: string (Extended description of the unit)
  • unit: string (Unit)

async_refreshFarmsData()

Refreshes the information about the farms held by the user.

Parameters

No parameters required.

Returns

A promise with user's farms information:

  • result: String ('success'|'error')
  • info: Object[]
    • id: String
    • nombre: String
    • bounds: Array [ xmin, ymin, xmax, ymax ]
    • permisos: Number[]
    • role: Number
    • supervised: Object[]
    • lotes: Object[]
      • id: number
      • nombre: String
      • country: String
      • wkt: String
      • bounds: Array [ xmin, ymin, xmax, ymax ]
      • centroide: string
      • area: Number
      • permisos: Number[]
      • role: Number

async_getComponentsData()

Provides information about the interface the user is interacting with on the platform. It returns map and sidenav height and width. Also, indicates if the sidenav is open or not.

Parameters

No parameters required.

Returns

A promise with the information mentioned before:

  • result: string ('success'|'error')
  • info: Object
    • map: Object
      • width: number
      • height: number
    • sidenav: Object
      • width: number
      • height: number

async_getScreenData()

Provides information about the map interface the user is interacting with.

Parameters

No parameters required.

Returns

A promise with the information mentioned before:

  • result: string ('success'|'error')
  • info: Object
    • width: number
    • height: number

async_getSamplings()

Provides information about the samplings corresponding to the fields sent as an argument.

Parameters

ParameterTypeDescription
fieldsIdnumber[]Ids of the fields whose samplings are to be obtained

Returns

A promise with the samplings from the corresponding fields grouped by field.

successfull operation:

  • result: string;
  • info: {[key: string]: Sampling[]};

Each sampling has the following interface:

interface Sampling {
groups: {
samples?: {
code?: string;
spot_data?: {
code?: string;
spot_data?: {
variables?: {
name?: string;
value?: number;
unit_id?: number;
[key: string]: any;
}[];
sampling?: {
analysis?: string;
[key: string]: any;
};
};
spot_uuid?: string;
};
spot_uuid?: string;
}[];
group_data?: {
[key: string]: {
color?: string;
name?: string;
};
};
group_uuid?: string;
}[];
yeargroup: number;
created_at: string;
field_id: number;
zoning: {
info?: {
date?: string;
layer?: string;
operation?: string;
hour?: string;
provider?: string;
};
type?: string;
};
analysis: {
[key: string]: {
name?: string;
unit_id?: number;
}[];
};
field_uuid: string;
sampling_name: string;
points: {
geometry?: string;
point_uuid?: string;
checked?: number;
created_at?: string;
group_uuid?: string;
}[];
group_assigned_id: number;
sampling_uuid: string;
closed_at: any;
sample_set_uuid: string;
}

async_createField

⚠️ Not available for mobile yet.

Creates a field based on the configuration object sent.

Parameters

Receives a configuration object with the following properties:

  • fieldName: string. New field name.
  • polygon: string. New field WKT.
  • farmId:: number. (Optional) Id of the farm to which the new field belongs.
  • farmName: string. (Optional) Name of the new farm to which the field belongs, in case of creating a new farm.

Note: At least one of the 'farmId' or 'farmName' properties must be sent.

Returns

In case of a successful operation:

  • result: success
  • info:
    • res: string. Operation result.
    • fieldId: number. Id of the created field.
    • farmId: farmId. Id of the farm to which the field was added (Useful in case of creating a farm).
    • info: string. Description of the result of the operation.

In case of an unsuccessful operation:

  • result: error
  • info
    • res: string. Operation result.
    • code: number. Error code.
    • info: string. Description of the result of the operation.

State Module

Provides functions that provide information about, or allow modification of, the state of the interface.

async_getActualFarm()

Returns the data for the currently selected farm in the interface.

Parameters

No parameters required.

Returns

A promise with the farm object in its information

  • result: string ('success'|'error')
  • info: objeto
    • id: number
    • bounds: Array [ xmin, ymin, xmax, ymax ]
    • nombre: string
    • lotes: Array [object,...]
      • id: number
      • bounds: Array [ xmin, ymin, xmax, ymax ]
      • centroide: string
      • area: number
      • nombre: string
      • wkt: string

async_getActualField()

Returns the data of the currently selected field in the interface.

Parameters

No parameters required.

Returns

A promise with the field object in its information

  • result: string ('success'|'error')
  • info: object
    • id: number
    • bounds: Array [ xmin, ymin, xmax, ymax ]
    • centroide: string
    • area: number
    • nombre: string
    • wkt: string

async_getCurrentCampaign()

Returns data from the current selected campaign.

Parameters

No parameters required.

Returns

A promise containing an object with the current campaign information.

  • result: string ('success'|'error')
  • info: object
    • text: string
    • value: number

setFarm()

Selects a farm in the main interface

Parameters

ParameterTypeDescription
farmIDnumberid of the farm to be selected

Returns

...

setField()

Selects a field in the main interface

Parameters

ParameterTypeDescription
fieldIDnumberid of the field to be selected

Returns

...

closeApp()

Closes the app window

Parameters

No parameters required.

Returns

...

openFeature()

Opens a standard platform feature. Calling this feature will close the currently running app!!

Parameters

ParameterTypeDescription
featureCodenumberid of the feautre to open

The codes may be as follows:

Feature CodeFeature
100New Field
200Farm Record
300Management Zones
400Clima
500Histogram
600Zoning
700Report
800My Maps
900New Layer

Returns

...

async_getConnectivityStatus

Returns the state of the platform's conectivity

Parameters

No parameters required.

Returns

A promise with the conection state in its information. May be "ONLINE" or "OFFLINE"

  • result: "success",
  • info: "ONLINE"

Map Module

Provides functions that offer information, or allow to operate on the interface map.

async_selectImage_v2()

⚠️ Not available for mobile

Selects an image within the existing layers in the interface.

Parameters

JSON object containing the following data:

{
"field": number // field id,
"source": string // string with image source,
"operation": string // string with the id of the layer/image type
"date": string, formated as "YYYY-MM-DDTHH:mm:ssZ" // image exact date,
"forCompare": boolean // (optional) if set to true, the comparative viewer is enabled
}

Returns

Returns a promise with information about the image selection.

focusField()

Moves the map camera over the currently selected field.

Parameters

No parameters required.

Returns

...

focusBounds()

Moves the map camera over the bounds passed as parameter.

Parameters

JSON object containing the following data:

{
"xmin": number, // minimum latitude of the extension
"xmax": number, // maximum latitude of the extension
"ymin":number, // minimum length of the extension
"ymax":number, // maximum length of the extension
}

Returns

...

setViewMap()

Moves the map camera over a specific point passed as parameter.

Parámetros

JSON object containing the following data:

{
"point": Array, // The first two positions indicates the position of the point. They must be type: number.
"x": number, // x-offset.
"y": number, // y-offset.
}

In case "x" and "y" are not defined or are equal to zero, each one takes the value 0.5 by default.

⚠️ It is possible that the function returns an error (error 25) in case the selected view exeeds the map. For example: when the coordinates of the point sent in the object as a parameter are close to the limits of the map, so it requires showing a non-existent part of it.

Returns

...

async_drawFeature()

Draws on the map a series of vector features (in geojson format).

Parameters

GeoJSON Object

Returns

Promise with the result of the drawing made on the map and its ID

Example of use

avt.map
.async_drawFeature({
type: "Feature",
geometry: {
type: "Point",
coordinates: [125.6, 10.1],
},
properties: {
name: "Dinagat Islands",
},
})
.then(console.log("mapa dibujado correctamente"));

clearFeatures()

Clears every drawn feature.

Parameters

No parameters required.

Example of use

// Draw the feature
avt.map
.async_drawFeature({
type: "Feature",
geometry: {
type: "Point",
coordinates: [125.6, 10.1],
},
properties: {
name: "Dinagat Islands",
},
})
.then(() => {
console.log("mapa dibujado correctamente");
avt.map.clearFeatures(); // Immediatly clear the drawn feature
};

async_startDraw()

Enables user to draw a point or polygon into the map

Parameters

  1. mode: string which may take "Polygon" or "Point" as value

Returns

A Promise with the result of the drawing in its information

  • type: type of object
  • id: integer that identifies the figure
  • geometry : GeoJSON object
    • type: type of figure
    • coordinates: coordinates array
  • properties: properties object
    • distancias: array of distances of the lines (in case it's a polygon)

Example of use

avt.map
.async_startDraw({
mode: "Polygon",
})
.then((res) => console.log(res));

async_setStyle()

Allows the user to assign a custom style to a drawn polygon or point.

Parameters

  1. featureID: id of the polygon or point, obtained from the response of async_startDraw.
  2. style: object with two style keys..
    1. fill: polygon / point fill style.
    2. stroke: polygon / point outline style.

Ejemplo de uso

avt.map.async_setStyle({
featureID: "69FdCe0a-Cf52-1C5B-a80f-d09AE9bd3dDE",
style: {
fill: { color: "red" },
stroke: { color: "#4986d2" },
},
});

stopDraw()

Should be called after async_startDraw. It cancels the drawing.

Parameters

No parameters are required

Example of use

avt.map
.async_startDraw({
mode: "Polygon",
})
.then((res) => console.log(res));
// The user starts drawing

// After 3 seconds the drawing is cancelled
setTimeout(() => {
avt.map.stopDraw();
}, 3000);

async_drawFeatureFromWKT()

Draws a feature into the map based on a WKT string feature.

Parameters

Takes a WKT string which defines the feature to be drawn.

Returns

Promise with the UUID of the drawn feature in its info.

  • info: string, UUID

Use example

let wkt_polygon = "POLYGON(( -65 -33, -65.7 -33, -65.7 -33.5, -65 -33 ))";
avt.map.async_drawFeatureFromWKT(wkt_polygon).then((res) => console.log(res));

// console:
// {
// "result": "success",
// "info": "dB3E5fF8-cead-13fc-a905-ECF0211bc2A8"
// }

addTooltipToFeature()

Adds a tooltip to an existing feature drawn on the map, using, for example, the async_drawFeatureFromWKT() function

Parameters

Takes an object with the following properties:

  • featureID : string, UUID of the drawn feature
  • content: string, Tooltip content (could be HTML)

Example of use

let text = "Here is your tooltip text!";
avt.map.addTooltipToFeature({
featureID: "dB64B880-d4c1-1B8C-A0e9-DcFB4E6FA5e3",
content: `
<div style="background:white;color:black;border-radius:5px;width:100%;padding:5px;">
${text}
</div>`,
});

async_getMapExtent()

Returns the current visualized map bounding box.

Parameters

No parameters required.

Returns

Promise with the bbox coordinates array in its info.

Use example

avt.map.async_getMapExtent().then((res) => console.log(res));

// console:
// {
// "result": "success",
// "info": [
// minLongitude,
// minLatitude,
// maxLongitude,
// maxLatitude
// ]
// }

async_removeFeature()

Deletes a drawn feature.

Parameters

  • string: UUID of the feature to be deleted

Returns

Promise that indicates success or failure

Use example

avt.map
.async_removeFeature("Dac7eD0c-8B1d-1e1b-B4B4-FEEfBab8Af6B")
.then((res) => console.log(res));

// console:
// {
// "result": "success",
// }

async_getActualPosition()

Returns the coordinates of your current position.

Parameters

No parameters required.

Returns

Promise with array of coordinates in its information.

Use example

avt.map.async_getActualPosition().then((res) => console.log(res));

// console:
// {
// "result": "success",
// "info": [
// <lat>,
// <long>
// ]
// }

hideFeatures()

Hide all drawn features of the map.

Parameters

No parameters required.

Returns

No values returned

Use example

avt.map.hideFeatures();

showFeatures()

Shows all features previously defined. If all defined features are drawn, does nothing.

Parameters

No parameters required.

Returns

No values returned

Use example

avt.map.showFeatures();

async_drawMarker()

Draws a marker with an icon at the defined position.

Parameters

An object containing the following parameters:

  • point: Array, contains two elements that specify latitude and longitude
  • icon: string, name of the icon
  • b64: string, b64 format icon, in case of including this parameter, icon will be ignored.

Available icons:

  • 'FARMER'
  • 'PIN'

Returns

Promise with the marker id in its information

Use example

avt.map
.async_drawMarker({
point: [-32, -62],
icon: "FARMER",
})
.then((res) => console.log(res));

avt.map
.async_drawMarker({
point: [-32, -62],
b64: "data:image/png;base64,iVBORw0...",
})
.then((res) => console.log(res));
// console:
// {
// "result": "success",
// "info": {
// "id": "Dcfd87b7-CED3-1620-A78e-a0E8cEf55239"
// }
// }

async_drawMarkerWithTooltip()

Draws a marker with an icon at the defined position with a tooltip.

Parameters

An object containing the following parameters:

  • point: Array, contains two elements that specify latitude and longitude
  • icon: String, name of the icon
  • content: String, HTML text that renders inside the tooltip
  • backgroundColor: String, hexa code of the tooltip's background color
  • metadata: Any
  • b64: string, b64 format icon, in case of including this parameter, icon will be ignored.

Available icons:

  • 'FARMER'
  • 'PIN'

Returns

A promise with the id in its information.

Use example

avt.map
.async_drawMarkerWithTooltip({
point: [-34, -62],
content: "<div style='color: #fff;'>Tooltip</div>",
metadata: "icon id or description, etc.",
backgroundColor: "#ffffff",
icon: "FARMER",
})
.then((res) => console.log(res));

// console:
// {
// "result": "success",
// "info": {
// "id": "Ba8C6edb-BFc9-1fD9-BFDA-30EAFDCe75a9"
// }
// }

async_drawMarkersWithTooltip()

Draws many markers, each with its tooltip, at the same time.

Parameters

Takes an array of objects, each of which represents an individual marker.

Each object contains the following parameters:

  • point: Array, contains two elements that specify latitude and longitude
  • icon: String, name of the icon
  • content: String, HTML text that renders inside the tooltip
  • backgroundColor: String, hexa code of the tooltip's background color
  • metadata: Any
  • b64: string, b64 format icon, in case of including this parameter, icon will be ignored.

Available icons:

  • 'FARMER'
  • 'PIN'

Returns

A promise with an array in its information that contains the ids of the icons in the same order as the array of objects that takes as parameter.

Use example

avt.map
.async_drawMarkersWithTooltip([
{
point: [-34, -62.5],
icon: "FARMER",
},
{
point: [-33.5, -62.5],
icon: "PIN",
},
{
point: [-33, -62.5],
icon: "FARMER",
},
])
.then((res) => console.log(res));

// console:
// {
// "result": "success",
// "info": {
// "ids": [
// "7d7e6DE5-d1dC-142F-B29B-2FF41ebedade",
// "f09B8970-feA5-102A-bcF8-b4aBFAadD0F6",
// "40A9A52C-Bba7-1905-86D0-CC78a9b29656"
// ]
// }
// }

Storage Module

It provides functions that allow information to be stored on our servers and then retrieved when needed.

The information is stored in Key-Value format, i.e. a JSON object (Value) under a name (Key).

In addition, each Key-Value is associated with a scope: Users, Fields or Farms. This scope defines who can access the data. For example, if a Key-Value associated to a Field is created, all users who have read access to that Field will be able to retrieve that data, regardless of the user who stored it.

It is important to think correctly about the scope to be assigned to the Key-Value in order not to expose data.

On the scope of a User, Key-Values can be:

  • created/retrieved by the user in question.

  • created/retrieved by the administrator of the space to which the user belongs (in case of belonging to a space).

  • retrieved by the supervisor with read permission of the group to which the user belongs (in case of belonging to a supervisory group).

  • created/retrieved by the supervisor with edit permission of the group to which the user belongs (in case of belonging to a supervisory group).

  • deleted by the user itself or the supervisor or administrator (in case of belonging to a space)

    Over the scope of a Field, Key-Values can be:

  • created/retrieved by users owning or having edit/add/administration permission on the Field.

  • retrieved by users with read permission on the Field.

  • deleted by users owning or having administration permission on the Field.

Over the scope of a Farm, Key-Values can be:

  • created/retrieved by users who own or have edit/add/administration permission on the Farm.
  • retrieved by the owning users or with some permission on the Farm.
  • deleted by users owning or having administration permission on the Farm.

Object names can be combinations of letters a-Z, numbers or underscore (_). You must check the regex "\w+".

For the same scope, the object name cannot be repeated.

put()

Allows an object to be stored under a name (Key). Depending on the scope:

  • avt.storage.user.put()
  • avt.storage.field.put()
  • avt.storage.farm.put()

NOTE: In the mobile app, PUT and PATCH operations are enqueued by a handler so that, in case of being offline, they could be executed when the connection is reestablished. This handler takes the operations regardless of being offline or online. The response to the promise returned by these corresponds to if the handler could successfully enqueue them or not. This produces that, in the mobile app version, the response to PUT or PATCH operations does not contain information about them being succesfully fulfilled, but rather if they could be accepted by the handler. In order to see the tasks queue, you must click the user's image at the top right corner and enter the "Synchronize" section.

Parameters:

Receives an object that has the following properties:

  1. id: Resource ID (User, Field or Farm) according to the scope.
  2. key: Key of the object to be stored
  3. data: Object to be stored
  4. overwrite: (optional) bool indicating whether to overwrite the object if it already exists. If not specified, it is false by default.

Response:

Promise with the response JSON object under the "info" key. This object has the "code" property indicating the result of the operation:

codedescription
1data missing
2the Key is invalid, as it does not respect regex '^\w+$'
3the user does not have permissions on the resource according to the scope requested
4invalid Extension version
5the Key already exists for the given scope. (Only possible if overwrite is false)
6Error

In case "code" < 0, check general response codes

Example of use:

avt.storage.user
.put({
id: "UID-dbaefe8503fe6cdb7909611e8953e74f",
key: "test_key",
value: { name: "juan", lastname: "perez" },
overwrite: true,
})
.then((response) => console.log(response));

avt.storage.field
.put({
id: 1000,
key: "other_test_key",
value: { fieldInfo: { valid: false } },
})
.then((response) => console.log(response));

patch()

Allows to modify an object under an existing name (Key). Depending on the scope:

  • avt.storage.user.patch()
  • avt.storage.field.patch()
  • avt.storage.farm.patch()

NOTE: In the mobile app, PUT and PATCH operations are enqueued by a handler so that, in case of being offline, they could be executed when the connection is reestablished. This handler takes the operations regardless of being offline or online. The response to the promise returned by these corresponds to if the handler could successfully enqueue them or not. This produces that, in the mobile app version, the response to PUT or PATCH operations does not contain information about them being succesfully fulfilled, but rather if they could be accepted by the handler. In order to see the tasks queue, you must click the user's image at the top right corner and enter the "Synchronize" section.

Parameters:

Receives an object that has the following properties:

  1. id: Resource ID (User, Field or Farm) according to the scope.
  2. key: Key of the object to be modified
  3. data: new object
  4. append: false by default, boolean that, in case of being true, indicates that value must be added to the previous value saved under the same key. In case of false, indicates that the new value must replace the previous value saved under the same key.
  5. create: false by default, boolean that indicates if key should or not be created if it didn't exist before.

Response:

Promise with the response JSON object under the "info" key. This object has the "code" property indicating the result of the operation:

codedescription
0object successfully modified
1data missing
2the Key is invalid, as it does not respect regex '^\w+$'
3the user does not have permissions on the resource according to the scope requested
4invalid Extension version
5the Key already exists for the given scope
6Error

In case "code" < 0, check general response codes

Example of use:

avt.storage.user
.patch({
id: "UID-dbaefe8503fe6cdb7909611e8953e74f",
key: "test_key",
value: {
name: "juan",
lastname: "perez",
otherAttribute: 50,
},
append: true,
create: false,
})
.then((response) => console.log(response));

avt.storage.field
.patch({
id: 1000,
key: "other_test_key",
value: { fieldInfo: { valid: true } },
append: true,
create: false,
})
.then((response) => console.log(response));

get()

Allows to retrieve objects under one or several names (Keys). Depending on the scope:

  • avt.storage.user.get()
  • avt.storage.field.get()
  • avt.storage.farm.get()

It is possible to obtain multiple Keys for multiple IDs in a single call.

Parameters:

Receives an object that has the following properties:

  1. ids: array of resource IDs (User, Field or Farm) according to the scope.
  2. keys: array of Keys to be recovered.

Each Key of the keys array shall be retrieved for each ID of the ids array, if they exist. In addition, in case of sending in ids an empty array for the scope Fields of Farms, the specified keys will be fetched for all the Fields/Farms for which the user has read permission.

Response:

Promise with the response JSON object under the "info" key. This object has the "code" property indicating the result of the operation, and the "objects" property with the data:

codedescription
0object successfully recovered
1data missing
2at least one requested Key is invalid, as it does not respect regex '\w+'
3user does not have permissions on at least one resource according to the requested scope
4invalid Extension version
5at least one requested ID is invalid

In case "code" < 0, check general response codes.

Example of response:


avt.storage.field.get(
{
ids:[1000, 1050],
keys:['test_key', 'other_test_key', 'another_test_key']
}
).then( response => console.log( response['info'] ) )
//output:
{
"code": 0,
"objects": {
1000: {
"test_key": {...},
"other_test_key": {...}
}
},
1050: {
"another_test_key": {...}
"other_test_key": {...}
}
}

Example of use:

avt.storage.user
.get({
ids: ["UID-dbaefe8503fe6cdb7909611e8953e74f"],
keys: ["test_key"],
})
.then((response) => console.log(response));

avt.storage.field
.get({
ids: [1000, 1050],
keys: ["test_key", "other_test_key", "another_test_key"],
})
.then((response) => console.log(response));

delete()

Allows to delete of one or multiple objects under existing names (Keys). Depending on the scope:

  • avt.storage.user.delete()
  • avt.storage.field.delete()
  • avt.storage.farm.delete()

Parameters:

Receives an object that has the following properties:

  1. id: ID of the resource (User, Field or Farm) depending on the scope.
  2. keys: array with the Keys to delete.

For the id provided, all existing keys shall be deleted.

Response:

Promise with the response JSON object under the "info" key. This object has the "code" property indicating the result of the operation:

codedescription
0object successfully modified
1the Key was not provided
2the Key is invalid, as it does not respect regex '^\w+$'
3the user does not have permissions on the resource according to the scope requested
4Extension version invalid
6Error

In case "code" < 0, check the general response codes

Example of use:

avt.storage.user
.delete({
id: "UID-dbaefe8503fe6cdb7909611e8953e74f",
key: ["test_key"],
})
.then((response) => console.log(response));

avt.storage.field
.delete({
id: 1000,
keys: ["other_test_key", "unexisting_key"],
})
.then((response) => console.log(response));

Interface Module

This module provides tools that allow you to interact with the platform interface.

testMessage()

Allows to display a message in the browser console. It is useful to verify if we are correctly connected to the SDK.

  • avt.interface.testMessage()

Parameters:

  • string text to display in the console.

Example of use:

avt.interface.testMessage("This is a test");

async_toast()

Allows to display an alert in the browser, to inform the user about an event.

  • avt.interface.async_toast()

Parameters:

  1. type: (string) type of alert you want to send. //warning, info, success, error
  2. message: (string) alert message.
  3. options: (object) object with optional settings to customize the alert.
    1. timeOut: (integer) alert duration (expressed in milliseconds).
    2. closeButton: (boolean) show button to close the alert.
    3. newestOnTop: (boolean) place the most recent alert at the top of the list.

Example of use:

avt.interface.async_toast({
type: "warning",
message: "field removed.",
});

avt.interface.async_toast({
type: "success",
message: "information saved successfully.",
});

avt.interface.async_toast({
type: "error",
message: "Something went wrong",
options: {
timeOut: 5000,
closeButton: true,
newestOnTop: true,
},
});

download_file()

It allows users to download a file, from both web and mobile applications.

  • avt.interface.download_file()

Parameters:

  1. url: (string) url of the file to download.
  2. filename: (optional) custom filename.

Example of use:

avt.interface.download_file(URL, "Download");

setWindow()

Allows you to edit basic styles of the window that contains the extension.

Example of use:

avt.interface.setWindow({
width: "600px",
});
//we are modifying the extension size.

openWindow()

It allows to open a new tab in the browser, having the url as a parameter.

Example of use:

avt.interface.openWindow("https://google.com");

openPopupWindow()

It allows to open a new window, as a Pop-up in the browser, having the url as a parameter.

Example of use:

avt.interface.openPopupWindow("https://google.com");

minimizeWindow()

It allows to minimize the extension, without the need to close it.

Example of use:

avt.interface.minimizeWindow();

maximizeWindow()

Lets you maximize the previously minimized extension.

Example of use:

avt.interface.maximizeWindow();

collapseSidenav()

Collapses the platform navigation sidebar.

Ejemplo de uso:

avt.interface.collapseSidenav();

expandSidenav()

Expands the platform navigation sidebar if it is collapsed.

Ejemplo de uso:

avt.interface.expandSidenav();

startCompare()

Enables the comparison between two layers, selected by the user.

Example of use:

avt.interface.startCompare();

finishCompare()

Disables the comparison between two layers.

Example of use:

avt.interface.finishCompare();

async_getLayerTypes()

Returns an array with the layers available for the selected field. It does not receive parameters. It is necessary to have a selected field.

Example of use:

avt.interface.async_getLayerTypes().then((res) => {
console.log(res);
});

Response example

{
"result": "success",
"info": [
"NDVI",
"GNDVI",
"Visible",
"MSAVI2",
"NDRE",
"NDWI"
]
}

Events

There are some predefined events which could be listened to interact with the platform too.

readySDK

It activates when the SDK is ready to use. May be useful wait this event to happen before loading the entire application, so that the SDK functions will be available and no error will be thrown.

mapClicked

It activates when the user click the map

Returns

  • event.detail: Object
    • coord: Array, clicked point coordinates
    • mapSize: Array, current map size [width, height]
    • pixel: Array, clicked pixel

farmSelected

It activates when the user selects a farm

Returns

  • event.detail: Object
    • id: Integer, selected farm id

fieldSelected

It activates when the user selects a field

Returns

  • event.detail: Object
    • id: Integer, selected field id

campaignChanged

It activates when the user changes de campaign selected.

Returns

  • event.detail: Object
    • yeargroup: Integer, new campaign selected value.

featureClicked

It activates when the user clicks on a drawn feature

Returns

  • event.detail: String, feature UUID

Example of use

// Logs the id of the selected field
window.addEventListener("fieldSelected", () => {
console.log(event.detail.id);
});