Difference between revisions of "Widget:SpaceAPI"
m (Added Hackers on Tour SpaceAPI preparations (just for fun)) |
m (polyline needs a marker) |
||
Line 661: | Line 661: | ||
// Handle beacons | // Handle beacons | ||
− | if ( this.data.sensors && this.data.sensors.beacon && this.data.sensors.beacon.length < | + | if ( this.data.sensors && this.data.sensors.beacon && this.data.sensors.beacon.length < 25 ) |
{ | { | ||
var bHoaB = false; | var bHoaB = false; | ||
Line 718: | Line 718: | ||
else | else | ||
{ | { | ||
+ | var apiBeacon = this.data.sensors.beacon[ 0 ]; | ||
+ | var beacon = {}; | ||
+ | |||
+ | beacon.point = L.latLng( apiBeacon.location.lat,apiBeacon.location.lon ); | ||
+ | beacon.marker = L.marker( beacon.point, { icon: this._leaflet.icons[ apiBeacon.name ] || new L.Icon.Default() } ).addTo( this._leaflet.map ); | ||
+ | beacon.circle = L.circle( beacon.point, apiBeacon.location.accuracy, {stroke:0} ).addTo( this._leaflet.map ); | ||
+ | |||
+ | var delta = (Date.now() - new Date( apiBeacon.ext_lastchange * 1000 )) / 1000; | ||
+ | |||
+ | // Closure variable | ||
+ | if ( ( delta < 3600 ) && ( apiBeacon.name === "HoaB" || apiBeacon.name === "HoT" ) ) | ||
+ | bHoaB = true; | ||
+ | |||
+ | if ( this._leaflet.icons[ apiBeacon.name ] ) | ||
+ | this._leaflet.icons[ apiBeacon.name ].options.className = delta > 60 ? "disconnected" : ""; | ||
+ | |||
+ | var popup = beacon.marker.getPopup(); | ||
+ | if ( !popup ) | ||
+ | popup = beacon.marker.bindPopup().getPopup(); | ||
+ | |||
+ | popup.setContent( ( this._leaflet.descriptions[ apiBeacon.name ] || apiBeacon.name ) + "<br/>Last update: " + this._nlsTime( delta ) + " ago" ); | ||
+ | |||
+ | //beacon; | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // TODO: clean up old beacons!! | ||
+ | this._leaflet.beacons.forEach( function( _beacon ) | ||
+ | { | ||
+ | // Destroy popup | ||
+ | _beacon.marker.unbindPopup( ); | ||
+ | |||
+ | // Remove marker and circle | ||
+ | this._leaflet.map.removeLayer( _beacon.marker ); | ||
+ | this._leaflet.map.removeLayer( _beacon.circle ); | ||
+ | }, this ); | ||
+ | /* | ||
+ | for ( var b = 0; b < Math.min( this._leaflet.beacons.length, beacons, length ); b++ ) | ||
+ | { | ||
+ | // Update position, icon, radius, tooltip | ||
+ | this._leaflet.beacons[ b ] | ||
+ | } | ||
+ | */ | ||
+ | this._leaflet.beacons = [ beacon ]; | ||
+ | |||
this._drawBeaconPolyLine( ); | this._drawBeaconPolyLine( ); | ||
} | } |
Revision as of 08:40, 2 October 2018
This widget allows you to display the Space API data (provided as JSON)
Created by Xopr
Using this widget
To insert this widget, use the following code:
{{#widget:SpaceAPI |url=/spaceAPI/ |width=260px |height=20px |padding=8px |interval=20 |float=right |features=beacon }}
This will give the following result:
Notes
- url is mandatory, the rest is optional (leave out interval to make the data static).
- it also must be written without protocol since colon (:) is not allowed, and may be relative, for example: //ackspace.nl/spaceAPI/ or /spaceAPI/
- You must provide a unit for the sizes (i.e. px, %, etc.)
Copy to your site
To use this widget on your site, just install MediaWiki Widgets extension and copy full source code of this page to your wiki as Widget:SpaceAPI article.