2020-10-13 00:54:34 +02:00
< ? php
// Notes
// The api key from Scooty's app/account: iPtAHWdOVLEtgkaymXoMHVVg
2020-10-13 01:56:45 +02:00
// Below is the static html to generate the map, it can also be done more dynamically using https://github.com/LuminFire/leaflet-php but that might be overkill
2020-10-13 00:54:34 +02:00
// array of scooters
$scooters = array (
//'https://platform.tier-services.io/v1/vehicle/fbd739d6-554f-4eaf-bd9c-afe3d501c94b',
'https://opencoil.show/test-json.php?scooterID=1' ,
'https://opencoil.show/test-json.php?scooterID=2'
);
2020-10-13 16:59:56 +02:00
//make it like this
$scooters = array (
//'https://platform.tier-services.io/v1/vehicle/fbd739d6-554f-4eaf-bd9c-afe3d501c94b',
'https://opencoil.show/test-json.php?scooterID=1' ,
'https://opencoil.show/test-json.php?scooterID=2'
);
2020-10-13 01:56:45 +02:00
// for each scooter in array get the json (TODO, for each, safe to file/database?)
$getJSON = callAPI ( $scooters [ 0 ]);
2020-10-13 00:54:34 +02:00
2020-10-13 01:56:45 +02:00
// decode JSON data to PHP associative array
$arr = json_decode ( $getJSON , true );
// access values from the associative array
$lat = $arr [ " data " ][ " attributes " ][ " lat " ]; // get lattitude
$lng = $arr [ " data " ][ " attributes " ][ " lng " ]; // get longitude
$lst = $arr [ " data " ][ " attributes " ][ " lastLocationUpdate " ]; // get time of last position
2020-10-13 16:59:56 +02:00
$rnt = $arr [ " data " ][ " attributes " ][ " isRentable " ]; // check if scooter is rentable,
$act = $arr [ " data " ][ " attributes " ][ " state " ]; // check if scooter is ACTIVE or MAINTAINANCE
2020-10-13 01:56:45 +02:00
2020-10-13 16:59:56 +02:00
//check if scooter is rentable
// if($rnt == true){
// echo "rentable";
// } else {
// echo "gallery not available";
// };
//check if scooter status (if ACTIVE)
// if($act === "ACTIVE"){
// echo "scooter is active";
// } else {
// echo "scooter is in repair";
// };
2020-10-13 01:56:45 +02:00
2020-10-13 00:54:34 +02:00
2020-10-13 16:59:56 +02:00
//// make date time file------
2020-10-13 00:54:34 +02:00
2020-10-13 16:59:56 +02:00
// construct lat/lon for use in leafet
$pos = $lat . ', ' . $lng ;
2020-10-13 00:54:34 +02:00
2020-10-13 16:59:56 +02:00
// TODO save json to file?...mmm one big one? seperate ones, timestamped ones?
// 60 second update interval
2020-10-13 00:54:34 +02:00
2020-10-13 16:59:56 +02:00
// make timestamp file like original python one! to check for updates
// make new custom json:
// scooter 1/marker time1 { lat long }
// time2 { lat long }
// scooter 2/marker time1 { lat long }
// time2 { lat long }
//
//
2020-10-13 00:54:34 +02:00
2020-10-13 16:59:56 +02:00
// for each
// check if lastlocation is different...if update > latest file (map file..)
// check if is rentable
2020-10-13 00:54:34 +02:00
2020-10-13 16:59:56 +02:00
// 2 json files: is retantable, latlong, id, status
// historical: every 60 sec needs update..even tho no state changes
2020-10-13 00:54:34 +02:00
// Custom functions
2020-10-13 01:56:45 +02:00
function checkModified ( $file , $expiration ){ //check if file is older than expiration time
}
function parseJSON (){
}
2020-10-13 00:54:34 +02:00
function callAPI ( $url ){
$curl = curl_init ( $url );
curl_setopt ( $curl , CURLOPT_FAILONERROR , true );
curl_setopt ( $curl , CURLOPT_FOLLOWLOCATION , true );
curl_setopt ( $curl , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $curl , CURLOPT_SSL_VERIFYHOST , false );
curl_setopt ( $curl , CURLOPT_SSL_VERIFYPEER , false );
curl_setopt ( $curl , CURLOPT_HTTPHEADER , array (
'x-api-key: bpEUTJEBTf74oGRWxaIcW7aeZMzDDODe1yBoSxi2' ,
'Content-Type: application/json' ,
)); // set the api key
curl_setopt ( $curl , CURLOPT_USERAGENT , 'ProductionRelease/3.8.2 (app.tier.sharing; build:3.8.2.0; iOS 12.4.4) Alamofire/4.9.1' ); // set user-agent to that of the Tier.app, sniffed by burpsuite
$result = curl_exec ( $curl );
if ( ! $result ){ die ( " Connection Failure " );}
curl_close ( $curl );
return $result ;
}
?>
2020-10-13 01:56:45 +02:00
< html >
< head >
< meta charset = " utf-8 " >
2020-10-13 16:59:56 +02:00
< meta name = " viewport " content = " width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=no " />
< script src = " https://code.jquery.com/jquery-1.12.4.min.js " ></ script >
2020-10-13 01:56:45 +02:00
< link rel = " stylesheet " type = " text/css " href = " https://unpkg.com/leaflet@1.3.3/dist/leaflet.css " >
< script src = 'https://unpkg.com/leaflet@1.3.3/dist/leaflet.js' ></ script >
2020-10-13 16:59:56 +02:00
<!-- icons -->
< script src = " https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js " ></ script >
< script src = " https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js " ></ script >
< link rel = " stylesheet " href = " https://cdn.jsdelivr.net/npm/leaflet@1.6.0/dist/leaflet.css " />
< link rel = " stylesheet " href = " https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css " />
< link rel = " stylesheet " href = " https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css " />
< link rel = " stylesheet " href = " https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css " />
< link rel = " stylesheet " href = " https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css " />
< link rel = " stylesheet " href = " https://rawcdn.githack.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css " />
<!-- begin timeslider -->
< script src = " SliderControl.js " ></ script >
< script src = " http://code.jquery.com/ui/1.9.2/jquery-ui.js " ></ script >
< link rel = " stylesheet " href = " http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css " />
< script src = " //cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.2/jquery.ui.touch-punch.min.js " ></ script >
<!-- end of timeslider -->
2020-10-13 01:56:45 +02:00
< style >
#map {
height : 500 px
}
</ style >
2020-10-13 16:59:56 +02:00
< script >
L_NO_TOUCH = false ;
L_DISABLE_3D = false ;
</ script >
2020-10-13 01:56:45 +02:00
</ head >
< body >
< div id = " map " ></ div >
< script >
2020-10-13 16:59:56 +02:00
// define icons (glyphicon = bootstrap, list can be found here: https://getbootstrap.com/docs/3.3/components/)
var availableIcon = L . AwesomeMarkers . icon (
{ " extraClasses " : " fa-rotate-0 " , " icon " : " remove " , " iconColor " : " white " , " markerColor " : " purple " , " spin " : " true " , " prefix " : " glyphicon " }
);
var isRentedIcon = L . AwesomeMarkers . icon (
{ " extraClasses " : " fa-rotate-0 " , " icon " : " imdb " , " iconColor " : " white " , " markerColor " : " gray " , " prefix " : " fa " }
);
2020-10-13 01:56:45 +02:00
var map = L . map ( 'map' ) . setView ([ 52.516190 , 13.377693 ], 13 );
var Stamen_Toner = L . tileLayer ( 'https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.{ext}' , {
attribution : 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' ,
subdomains : 'abcd' ,
minZoom : 0 ,
maxZoom : 20 ,
ext : 'png'
});
map . addLayer ( Stamen_Toner );
2020-10-13 16:59:56 +02:00
//for each...
var scooter1 = L . marker ([ < ? php echo $pos ; ?> ],
{ time : " 2020-10-09T08:00:29Z " },
{ icon : availableIcon }) . addTo ( map )
2020-10-13 01:56:45 +02:00
. bindPopup ( 'Last updated <?php echo $lst; ?>' )
2020-10-13 16:59:56 +02:00
. bindTooltip ( 'artist name' )
//.setIcon(availableIcon); // scooter is available
. setIcon ( isRentedIcon ); // scooter is rented
//.openPopup();
// scooter1.setIcon(icon_7e68fd836a604f9481171759656817aa);
// time slider
//test markers
//var marker1 = L.marker([52.504926, 13.358061], {time: "2020-10-09T08:00:29Z"});
var marker2 = L . marker ([ 52.506926 , 13.358061 ], { time : " 2020-10-09T09:00:29Z " });
var marker3 = L . marker ([ 52.508926 , 13.358061 ], { time : " 2020-10-09T10:00:29Z " });
// var map = marker1;
// layerGroup = L.layerGroup([marker_e7a96a6d6b08479ba6d17d42769e5202]);
layerGroup = L . layerGroup ([ scooter1 , marker2 , marker3 ]);
var sliderControl = L . control . sliderControl ({ layer : layerGroup });
map . addControl ( sliderControl );
sliderControl . startSlider ();
2020-10-13 01:56:45 +02:00
</ script >
</ body >
</ html >