Default JMap Web Actions
Dernière mise à jour
Dernière mise à jour
K2 Geospatial 2022
The JMap Web application template offers many actions to facilitate JMap Server interactions. This section will present some of them and how you can use them.
Note: The majority of actions require map state information as parameters. For the most part, these can be obtained using OpenLayers’s API.
All examples in this section refer to a deployment based on the The World project. The deployment covers the project’s complete extent and includes the following layers: “Base” and “Cities”. Refer yourself to the following screen shots in order to create a similar deployment.
The extractelements action provides a list of a JMap layer’s elements.
The geometry request will extract elements that intersect or are contained within a supplied geometry.
The following is the list of parameters that can be provided to the extractelements action.
request
{String} “geometry” requiredThis string identifies the type of request that’s being issued to the action. Other types of requests may be added to this action in the future.
geometry
{String} requiredA WKT geometry string defining the region for which to execute the element extraction process.
res
{Number} required The map’s current resolution.
bbox
{String} requiredThe map’s current extent as it’s displayed in the browser at the time of the request. Specified in a bounding box format (example: “-100,-50,100,50”).
drill
{Boolean} default: false Indicates whether or not you wish to continue analyzing the layer stack once the first match is found.
layers
{String} requiredSpecifies for which layer(s) you want to perform the element extraction.Many layers may be requested at once. In that case, you should separate the elements of your layer list using commas. Use the drill parameter accordingly in order to obtain elements across multiple layers.
Performs an element extraction request for the “Cities” layer around the Scotland area.
$.ajax(JMap.app.ajaxDispatcher, {data: {
'action': 'extractelements',
'request': 'geometry',
'geometry': 'POLYGON((-6.378882 54.903806,-1.336158 54.903806,-1.336158 59.540037,-6.378882 59.540037,-6.378882 54.903806))',
'res': JMap.app.map.getResolution(),
'bbox': JMap.app.map.getExtent().toBBOX(),
'layers': 'Cities'
}}).success(function(data, textStatus, jqXHR) {
console.log(data);
});
Each element’s ID, geometry (supplied as a WKT formatted string), attribute values, bounds and centered point are returned. The layer’s bound attributes are also included as well as their SQL type. An element’s attributes’s index corresponds to the layer’s attributes as configured in JMap Admin. If elements from many layers match the request parameters, an array of these object literals will be returned.
{
"layerId": 7,
"elementAttributes": [
{
"sqlType": 12,
"name": "CITY"
},
{
"sqlType": 12,
"name": "COUNTRY"
},
{
"sqlType": 12,
"name": "CAP"
},
{
"sqlType": 4,
"name": "POP2000"
}
],
"elements": [
{ "centeredPoint": {
"x": -1.3899999735879476,
"y": 54.910001831054686
},
"bounds": {
"x": -1.3899999735879476,
"width": 0,
"y": 54.910001831054686,
"height": 0
},
"attributeValues": [
"Sunderland",
"UK - England and Wales",
"0",
181100
],
"geometry": "POINT(-1.3899999735879476 54.910001831054686)",
"id": 622
},
{
"centeredPoint": {
"x": -4.2699998496102864,
"y": 55.87000091552734
},
"bounds": {
"x": -4.2699998496102864,
"width": 0,
"y": 55.87000091552734,
"height": 0
},
"attributeValues": [
"Glasgow",
"Scotland",
"0",
610700
],
"geometry": "POINT(-4.2699998496102864 55.87000091552734)",
"id": 624
},
{
"centeredPoint": {
"x": -3.2200001357125814,
"y": 55.949998931884764
},
"bounds": {
"x": -3.2200001357125814,
"width": 0,
"y": 55.949998931884764,
"height": 0
},
"attributeValues": [
"Edinburgh",
"UK - England and Wales",
"0",
382600
],
"geometry": "POINT(-3.2200001357125814 55.949998931884764)",
"id": 625
},
{
"centeredPoint": {
"x": -2.9999998686837728,
"y": 56.469999389648436
},
"bounds": {
"x": -2.9999998686837728,
"width": 0,
"y": 56.469999389648436,
"height": 0
},
"attributeValues": [
"Dundee",
"Scotland",
"0",
148900
],
"geometry": "POINT(-2.9999998686837728 56.469999389648436)",
"id": 627
},
{
"centeredPoint": {
"x": -2.1000000117349202,
"y": 57.14999969482422
},
"bounds": {
"x": -2.1000000117349202,
"width": 0,
"y": 57.14999969482422,
"height": 0
},
"attributeValues": [
"Aberdeen",
"Scotland",
"0",
188500
],
"geometry": "POINT(-2.1000000117349202 57.14999969482422)",
"id": 628
},
{
"centeredPoint": {
"x": -1.6000000117349202,
"y": 54.99999816894531
},
"bounds": {
"x": -1.6000000117349202,
"width": 0,
"y": 54.99999816894531,
"height": 0
},
"attributeValues": [
"Newcastle upon Tyne",
"UK - England and Wales",
"0",
980000
],
"geometry": "POINT(-1.6000000117349202 54.99999816894531)",
"id": 1899
}
]
}
The layerinfo action provides details regarding layers of the deployment’s associated project.
The geteditablelayers request will return layer various layer details on which the currently authenticated user may perform data editing tasks.
This action does not require any parameters. Instead, it uses the current session information to perform this operation.
$.ajax(JMap.app.ajaxDispatcher, {
data: {
'action': 'layerinfo',
'request': 'geteditablelayers'
}
}).success(function(data, textStatus, jqXHR) {
console.log(data);
});
The server response exposes an array of editableLayers object literals. Each of the array’s objects contains the following keys:
fields
{Array} Array of object literals exposing the name bound layer fields as well as their SQL data type.
forms
{Array} The layer’s configured forms.
id
{Number} The layer’s ID.
idFieldName
{String} The name of the layer attribute that serves as an identifier.
offset
{Object} An object literal that contains the layer’s current offset.
permissions
{Number} An integer between 0 and 15 (inclusive) that describes the current user’s permissions towards the layer. The following bit masks signify different permissions. • 0x0000: None. • 0x0001: May add layer elements. • 0x0010: May edit layer elements. • 0x0100: May delete layer elements. • 0x1000: May edit layer elements’s attributes.
forms are returned as an array of object literals. They have the following structure:
id
{Number} The form’s unique ID.
json
{String} A JSON representation of the form’s configuration.
name
{String} The form’s name as defined in JMap Admin.
permissions
{Number} An integer between 0 and 7 (inclusive) that describes the current user’s permissions towards the form. A form’s permissions only concerns external forms. Layer attributes forms’s permissions are defined as part of the layer permissions. • 0x000: None. • 0x001: May add data in external forms. • 0x010: May edit data in external forms. • 0x100: May delete data from external forms.
type
{String} Identifies the form type. One of the following: • LAYER_ATTRIBUTES_FORM • LAYER_ATTRIBUTES_SUB_FORM • EXTERNAL_ATTRIBUTES_FORM • EXTERNAL_ATTRIBUTES_SUB_FORM
uidAttributeName
{String} Only concerns external forms. Is the name of the layer’s attribute that will be used as a foreign key to establish child-parent relationships.
This is an example of a geteditablelayers response. You may have different results. In any case, they should reflect the state of your configured permissions and forms.
{
"editableLayers": [
{
"offset": {
"x": 9.5367431640625e-7,
"y": -3.186320304870577 },
"permissions": 0,
"id": 4,
"fields": [
{
"name": "COUNTRY",
"serverDataType": 12
},
{
"name": "CONTINENT",
"serverDataType": 12
},
{
"name": "POP_1994",
"serverDataType": 8
},
{
"name": "POP_GRW_RT",
"serverDataType": 8
},
{
"name": "POP_0_14",
"serverDataType": 8
},
{
"name": "POP_15_64",
"serverDataType": 8
},
{
"name": "POP_65PLUS",
"serverDataType": 8
},
{
"name": "POP_AREA",
"serverDataType": 8
}
],
"idFieldName": "JMAP_ID",
"forms": []
},
{
"offset": {
"x": 0.56195068359375,
"y": 13.687942504882812
},
"permissions": 0,
"id": 6,
"fields": [
{
"name": "LAKE_NAME",
"serverDataType": 12
},
{
"name": "VOLUME_CKM",
"serverDataType": 8
},
{
"name": "AREA_SKM",
"serverDataType": 8
}
],
"idFieldName": "JMAP_ID",
"forms": []
},
{
"offset": {
"x": 20.934576233500025,
"y": 10.050437668683657
},
"permissions": 0,
"id": 5,
"fields": [],
"idFieldName": "JMAP_ID",
"forms": []
},
{
"offset": {
"x": 16.215000694478334,
"y": 16.463705277985326
},
"permissions": 0,
"id": 3,
"fields": [
{
"name": "HYD_NAME", "
serverDataType": 12
},
{
"name": "LENGTH_KM",
"serverDataType": 4
}
],
"idFieldName": "JMAP_ID",
"forms": []
},
{
"offset": {
"x": 31.452202349999993,
"y": -14.421794805000005
},
"permissions": 0,
"id": 2,
"fields": [
{
"name": "CONTINENTNAME",
"serverDataType": 12
}
],
"idFieldName": "JMAP_ID",
"forms": []
},
{
"offset": {
"x": 1.6169597031546061,
"y": 8.079999999999998
},
"permissions": 15,
"id": 7,
"fields": [
{
"name": "CITY",
"serverDataType": 12
},
{
"name": "COUNTRY",
"serverDataType": 12
},
{
"name": "CAP",
"serverDataType": 12
},
{
"name": "POP2000",
"serverDataType": 4
}
],
"idFieldName": "JMAP_ID",
"forms": [
{
"permissions": 0,
"name": "Form",
"json": "{\"formSections\":[{\"name\":\"Section 1\",\"nbRows\":3,\"fields\":[{\"$ATTRIBUTE_NAME\":\"CITY\",\"$ROW\":0,\"$MASKFORMATTER\":\"\",\"$COL\":0,\"$INPUT_TYPE\":\"$INPUT\",\"$MULTILINE\":false,\"$PREFIX\":\"CITY\",\"$ALIGNMENT\":\"LEFT\",\"$REQUIRED\":true,\"$MAX_NUMBER_CHARACTERS\":255,\"$COLSPAN\":1,\"$WIDTH\":100,\"$TOOLTIP\":\"\",\"$ATTRIBUTE_SQL_TYPE\":12,\"$READ_ONLY\":false}]}",
"id": 1,
"type": "LAYER_ATTRIBUTES_FORM",
"uidAttributeName": null
}
]
}
]}
The loadformdata action provides external form data for a requested layer element.
loadformdata expects the following parameter:
data
{String} required JSON String that represents a Javascript object literal composed of the following properties: • elementId: {Number} The element (for which data is requested)’s unique ID. • formId: {Number} The external form’s ID. • layerId: {Number} The layer (on which the element exists/the form is configured)’s ID. • listFields: {Array[Strings]} A list of form fields for which you want values. An empty array will return data for all fields. • mapValues: Javascript object literal that contains the element’s layer’s layer attributes form’s fields values.
This example refers to another project for which external forms were configured.
var data = { elementId: 6, formId: 2, layerId: 1,
listFields: [],
"mapValues": {
"MOBILE_JMAP_ID": 6,
"MOBILE_JMAP_GEOMETRY": "POINT(-8189010.0 5701129.5)",
"AUTHOR": "jrhaddad",
"CREATION_TIME": 1415767972000,
"MODIFICATION_TIME": 1418400517000,
"ABR_CODE": "342",
"ABR_NAME": "ES34F",
"ABR_LOC_TYPE": "Arrêt bus",
"ABR_WHEEL_CHAIR": "Non accessible",
"ABR_DATE_INSP": null,
"ABR_STATUS": null
}
};
$.ajax(JMap.app.ajaxDispatcher, {data: {
'action': 'loadformdata',
'data': JSON.stringify(data)
}}).success(function(data, textStatus, jqXHR) {
console.log(data);
});
The server responds by providing a two dimensional rows array of Javascript object literals representing field values. Each item in the rows array represents a row of data. Multiple rows are returned when obtaining data that was entered using a EXTERNAL_ATTRIBUTES_SUB_FORM type form.
The name of the form field, its value and the data’s SQL type are returned.
{
"rows": [
[
{
"name": "insp_abribus.id_inspection",
"value": 5,
"type": 4
},
{
"name": "insp_abribus.id_abribus",
"value": 6,
"type": 4
},
{
"name": "insp_abribus.date_inspection",
"value": 1415854800000,
"type": 93
},
{
"name": "insp_abribus.etat",
"value": "Bon état",
"type": 12
},
{
"name": "insp_abribus.observations",
"value": "Tout est ok",
"type": 12
}
]
]
}