Advertisement
Guest User

test

a guest
May 6th, 2021
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. openSafeZone:function(button,pressed){
  2.         var position, deviceId, deviceName, lat, long, safezoneRadius, circle, projection, feature, isSafezone = false;
  3.         deviceId = this.selectedMarker.get('record').get('id');
  4.         deviceName = this.selectedMarker.get('record').get('name');
  5.         if (this.lookupReference('ShowsafezoneButton').pressed) {
  6.             position = Ext.getStore('LatestPositions').findRecord('deviceId',this.selectedMarker.get('record').get('id'),0,false,false,true);
  7.             lat = position.get('latitude');
  8.             long = position.get("longitude");
  9.             safezoneRadius = 30;
  10.             projection = this.getView().getMapView();
  11.  
  12.             Ext.getStore('Geofences').each(function (geofence) {
  13.                 if(geofence.get('name') == deviceName) {
  14.                     Traccar.app.showToast("Safezone já está Ligada!");
  15.                     isSafezone = true;
  16.                 }
  17.             }, this);
  18.  
  19.             circle = "CIRCLE ("+lat+" "+long+", "+safezoneRadius+")";
  20.  
  21.             var data = { "id": 0, "name": deviceName, "description": "SafeZone", "area": circle, "calendarId": 0, "attributes": {"speedLimit":10} };
  22.             if(!isSafezone) {
  23.                 Ext.Ajax.request({
  24.                     scope: this,
  25.                     method: 'POST',
  26.                     url: 'api/geofences',
  27.                     jsonData: Ext.util.JSON.encode(data),
  28.                     callback: function (options, success, response) {
  29.                         if (!success) {
  30.                             Traccar.app.showError(response);
  31.                         }else{
  32.                             const geofenceID = JSON.parse(response.responseText);//Função aguardando criação de api para trocar devicegeofence
  33.                             Traccar.app.showToast("Safezone Ligada!");
  34.                             Ext.getStore('Geofences').load();
  35.                         }
  36.                     }
  37.                 });
  38.  
  39.                 //Não está funcionando
  40.                 feature = new ol.Feature(Traccar.GeofenceConverter.wktToGeometry(projection, circle));
  41.                 feature.setStyle(this.getAreaStyle(deviceName, null));
  42.                 this.getView().getGeofencesSource().addFeature(feature);
  43.             }
  44.  
  45.         }else{
  46.             this.getView().getGeofencesSource().clear();
  47.             Ext.getStore('Geofences').each(function (geofence) {
  48.                if(deviceName == geofence.get('name')) {
  49.                  var id = geofence.get('id');
  50.                  Ext.Ajax.request({
  51.                     scope: this,
  52.                     method: 'DELETE',
  53.                     url: 'api/geofences/'+id+'',
  54.                     headers: { 'Content-Type': 'application/json' },
  55.                     callback: function (options, success, response) {
  56.                         if (!success) {
  57.                             Traccar.app.showError(response);
  58.                         }else{
  59.                            Ext.getStore('Geofences').load();
  60.                            Traccar.app.showToast("Safezone Desligada!");
  61.                         }
  62.                     }
  63.                 });
  64.                }
  65.             }, this);
  66.         }
  67.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement