1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <meta charset="utf-8" />
5
    <title>Wialon Playground - Create geofence</title>
6
    <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script>
7
    <script type="text/javascript" src="https://hst-api.wialon.com/wsdk/script/wialon.js"></script>
8
</head>
9
<body>
10
11
<!-- load map -->
12
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.2/leaflet.css" />
13
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.2/leaflet.js"></script>
14
15
<div id="map"></div>
16
<table>
17
    <tr><td>Resource</td><td><select id="res"><option></option></select></td></tr>
18
    <tr><td>Name</td><td><input type="text" id="n" placeholder="Name"/></td></tr>
19
    <tr><td>Radius</td><td><input type="number" id="r" min="1" value="500" placeholder="Radius"/></td></tr>
20
    <tr><td colspan="2" style="text-align:center;">
21
        <input type="button" value="New circle" id="new_btn"/>
22
        <input type="button" value="Save" id="save_btn"/>
23
    </td></tr>
24
</table>
25
<div id="log"></div>
26
27
28
</body>
29
</html>
HTML
2
 
1
#log{ border: 1px solid #c6c6c6; }
2
#map{ width:100%; height:300px; float:left;}
CSS
120
 
1
var map = null, circle_zone = null, enableNewCircle  = false; // global variables
2
3
// Print message to log
4
function msg(text) { $("#log").prepend(text + "<br/>"); }
5
6
function init() { // Execute after login succeed
7
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
8
    // specify what kind of data should be returned
9
    var flags = wialon.item.Item.dataFlag.base | wialon.item.Resource.dataFlag.zones;
10
    
11
    sess.loadLibrary("resourceZones");  // load Geofences Library 
12
    sess.updateDataFlags( // load items to current session
13
        [{type: "type", data: "avl_resource", flags: flags, mode: 0}], // Items specification
14
        function (code) { // updateDataFlags callback
15
            if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code  
16
            // get loaded 'avl_resource's items with edit geofences access 
17
            var res = wialon.util.Helper.filterItems(sess.getItems("avl_resource"),
JS
Result
Source code of example Close ✕
1
 
1
/*source*/