|
|
en:pro:remoteapi:codesamples:messages [27/05/2013 11:54] zuve |
en:pro:remoteapi:codesamples:messages [29/11/2013 13:31] |
{{indexmenu_n>9}} | |
====== Messages ====== | |
You can operate messages with the help of a special object -- the message loader. First, you load messages into the message loader using command [[../apiref/messages/load_interval|messages/load_interval]]. Then you can work with them. However, if you need to load other messages, you must clear the loader first, using the command [[../apiref/messages/unload|messages/unload]]. | |
| |
| |
===== Loading messages ===== | |
Let's load three first messages for some interval with the help of the request [[../apiref/messages/load_interval|messages/load_interval]]: | |
<code> | |
<your_wialon_pro_address>/ajax.html?svc=messages/load_interval& | |
params={ | |
"itemId":48, | |
"type":1, | |
"ival1":1361912400, | |
"ival2":1361998799, | |
"flags":0, | |
"flagsMask":0, | |
"loadLocations":false, | |
"loadCount":3 | |
}&sssid=<your_sid> | |
</code> | |
| |
Response: | |
<code javascript> | |
{ | |
"count": 20, | |
"messages": [{ | |
"t": 1361964965, | |
"f": 512, | |
"tp": "ucr", | |
"cn": "query_pos", | |
"cp": "", | |
"ug": "8793338c1389cc6c1bb7c64e3fdc565f", | |
"ln": "", | |
"lt": "gsm", | |
"et": 1361964966, | |
"p": {} | |
"p": {} | |
}, { | |
"t": 1361964969, | |
"f": 256, | |
"tp": "us", | |
"st": "PC,0001,27\/02\/13,11:36:07,5350.5499,N,02728.1261,E,29.0km,0.0,A,010043", | |
"mp": "+375290000000", | |
"p": {} | |
}, { | |
"t": 1361964981, | |
"f": 512, | |
"tp": "ucr", | |
"cn": "query_pos", | |
"cp": "", | |
"ug": "8793338c1389cc6c1bb7c64e3fdc565f", | |
"ln": "", | |
"lt": "gsm", | |
"et": 1361964982, | |
"p": {} | |
}] | |
} | |
</code> | |
| |
There 20 messages for the specified period, however, only 3 first are in the message loader. | |
| |
After loading messages, you can choose any number of them for further processing. For example, let's choose the first two messages from the loader. For this, use the request [[../apiref/messages/get_messages|messages/get_messages]]: | |
<code> | |
<your_wialon_pro_address>/ajax.html?svc=messages/get_messages& | |
params={ | |
"indexFrom":0, | |
"indexTo":1, | |
"loadLocations":false | |
}&ssid=<your_sid> | |
</code> | |
| |
Response: | |
<code javascript> | |
[{ | |
"t": 1361964965, | |
"f": 512, | |
"tp": "ucr", | |
"cn": "query_pos", | |
"cp": "", | |
"ug": "8793338c1389cc6c1bb7c64e3fdc565f", | |
"ln": "", | |
"lt": "gsm", | |
"et": 1361964966, | |
"p": {} | |
}, { | |
"t": 1361964969, | |
"f": 256, | |
"tp": "us", | |
"st": "PC,0001,27\/02\/13,11:36:07,5350.5499,N,02728.1261,E,29.0km,0.0,A,010043", | |
"mp": "+375290000000", | |
"p": {} | |
}] | |
</code> | |
| |
===== Deleting messages ===== | |
Now we will try to delete the first message using the request [[../apiref/messages/delete_message|messages/delete_message]]: | |
<code> | |
<your_wialon_pro_address>/ajax.html?svc=messages/delete_message& | |
params={ | |
"index":0 | |
}&ssid=<your_sid> | |
</code> | |
| |
Response: | |
<code> | |
0 | |
</code> | |
| |
===== Clear message loader ===== | |
| |
If you want to load messages for other interval or unit, [[../apiref/messages/unload|clear]] the message loader first: | |
<code> | |
<your_wialon_pro_address>/ajax.html?svc=messages/unload¶ms={}&ssid=<your_sid> | |
</code> | |
| |
Response: | |
<code javascript> | |
{} | |
</code> | |
| |
If you try to query messages from empty loader, the following error code will be returned: | |
<code> | |
<your_wialon_pro_address>/ajax.html?svc=messages/get_messages& | |
params={ | |
"indexFrom":0, | |
"indexTo":1, | |
"loadLocations":false | |
}&ssid=<your_sid> | |
</code> | |
| |
Response: | |
<code javascript> | |
{ | |
"error": 1001 | |
} | |
</code> | |
| |
===== Rendering track layer ===== | |
| |
If loaded messages contain geographic coordinates, a track can be built on their basis. To do this, you should load messages into a special graphic layer. Track layer can be used in the same way as the message loader. The only difference between them is graphics. | |
| |
| |
Before creating track layer we should [[../apiref/renderer/create_image_renderer|create image renderer]]: | |
| |
<code> | |
<your_wialon_pro_address>/ajax.html?svc=renderer/create_image_renderer& | |
params={ | |
"tzOffset":134228528, | |
"lang":"ru" | |
}&ssid=<your_sid> | |
</code> | |
| |
Response: | |
<code javascript> | |
{ | |
"name": "avl-74d5ab0-0x206a7d0-0x7ff83cd97700", | |
"layers": [], | |
"bounds": [0, 0, 0, 0] | |
} | |
</code> | |
| |
Let's create a track layer. We can do it using the request [[../apiref/renderer/create_messages_layer|renderer/create_messages_layer]]: | |
| |
<code> | |
<your_wialon_pro_address>/ajax.html?svc=renderer/create_messages_layer& | |
params={ | |
"lname":"messages", | |
"rname":"avl-74d5ab0-0x206a7d0-0x7ff83cd97700", | |
"itemId":48, | |
"timeFrom":1360875600, | |
"timeTo":1361998799, | |
"tripDetector":1, | |
"trackColor":cc713cff, | |
"trackWidth":5, | |
"arrows":1, | |
"points":0, | |
"pointColor":0, | |
"annotations":0, | |
"roadLock":false | |
}&ssid=<your_sid> | |
</code> | |
| |
Response: | |
<code javascript> | |
{ | |
"name": "messages", | |
"bounds": [53.8327466667, 27.4098016667, 53.97141, 27.696855], | |
"units": [{ | |
"id": 9, | |
"msgs": { | |
"count": 71, | |
"first": { | |
"time": 1361275577, | |
"lat": 53.8424987793, | |
"lon": 27.4687690735 | |
}, | |
"last": { | |
"time": 1361965107, | |
"lat": 53.8801002502, | |
"lon": 27.4176311493 | |
} | |
}, | |
"mileage": 130117.245939, | |
"max_speed": 80 | |
}] | |
} | |
</code> | |
| |
You can get the tiles of a track layer using the request [[../apiref/requests/avl_render|avl_render]]. | |