// information about server communication. This sample webservice is provided by Wikitude and returns random dummy places near given location var ServerInformation = { POIDATA_SERVER: "http://gdurl.com/qou6", POIDATA_SERVER_ARG_LAT: "lat", POIDATA_SERVER_ARG_LON: "lon", POIDATA_SERVER_ARG_NR_POIS: "nrPois" };
// implementation of AR-Experience (aka "World") var World = {
// user's latest known location, accessible via userLocation.latitude, userLocation.longitude, userLocation.altitude userLocation: null,
// you may request new data from server periodically, however: in this sample data is only requested once isRequestingData: false,
// true once data was fetched initiallyLoadedData: false,
// different POI-Marker assets markerDrawable_idle: null, markerDrawable_selected: null, markerDrawable_directionIndicator: null,
// list of AR.GeoObjects that are currently shown in the scene / World markerList: ,
// set distance slider to 100% $("#panel-distance-range").val(100); $("#panel-distance-range").slider("refresh"); },
// sets/updates distances of all makers so they are available way faster than calling (time-consuming) distanceToUser() method all the time updateDistanceToUserValues: function updateDistanceToUserValuesFn() { for (var i = 0; i < World.markerList.length; i++) { World.markerList.distanceToUser = World.markerList.markerObject.locations.distanceToUser(); } },
// updates status message shon in small "i"-button aligned bottom center updateStatusMessage: function updateStatusMessageFn(message, isWarning) {
var themeToUse = isWarning ? "e" : "c"; var iconToUse = isWarning ? "alert" : "info";
// location updates, fired every time you call architectView.setLocation() in native environment locationChanged: function locationChangedFn(lat, lon, alt, acc) {
// store user's current location in World.userLocation, so you always know where user is World.userLocation = { 'latitude': lat, 'longitude': lon, 'altitude': alt, 'accuracy': acc };
// request data if not already present if (!World.initiallyLoadedData) { World.requestDataFromServer(lat, lon); World.initiallyLoadedData = true; } else if (World.locationUpdateCounter === 0) { // update placemark distance information frequently, you max also update distances only every 10m with some more effort World.updateDistanceToUserValues(); }
// helper used to update placemark information every now and then (e.g. every 10 location upadtes fired) World.locationUpdateCounter = (++World.locationUpdateCounter % World.updatePlacemarkDistancesEveryXLocationUpdates); },
// fired when user pressed maker in cam onMarkerSelected: function onMarkerSelectedFn(marker) { World.currentMarker = marker;
// screen was clicked but no geo-object was hit onScreenClick: function onScreenClickFn() { // you may handle clicks on empty AR space too },
// returns distance in meters of placemark with maxdistance * 1.1 getMaxDistance: function getMaxDistanceFn() {
// sort palces by distance so the first entry is the one with the maximum distance World.markerList.sort(World.sortByDistanceSortingDescending);
// use distanceToUser to get max-distance var maxDistanceMeters = 500;
// return maximum distance times some factor >1.0 so ther is some room left and small movements of user don't cause places far away to disappear return maxDistanceMeters * 1.1; },
// udpates values show in "range panel" updateRangeValues: function updateRangeValuesFn() {
// get current slider value (0..100); var slider_value = $("#panel-distance-range").val();
// max range relative to the maximum distance of all visible places var maxRangeMeters = Math.round(World.getMaxDistance() * (slider_value / 100));
// range in meters including metric m/km var maxRangeValue = (maxRangeMeters > 999) ? ((maxRangeMeters / 1000).toFixed(2) + " km") : (Math.round(maxRangeMeters) + " m");
// number of places within max-range var placesInRange = World.getNumberOfVisiblePlacesInRange(maxRangeMeters);
// update culling distance, so only palces within given range are rendered AR.context.scene.cullingDistance = Math.max(maxRangeMeters, 1);
// update radar's maxDistance so radius of radar is updated too PoiRadar.setMaxDistance(Math.max(maxRangeMeters, 1)); },
// returns number of places with same or lower distance than given range getNumberOfVisiblePlacesInRange: function getNumberOfVisiblePlacesInRangeFn(maxRangeMeters) {
// sort markers by distance World.markerList.sort(World.sortByDistanceSorting);
// loop through list and stop once a placemark is out of range ( -> very basic implementation ) for (var i = 0; i < World.markerList.length; i++) { if (World.markerList.distanceToUser > maxRangeMeters) { return i; } };
// in case no placemark is out of range -> all are visible return World.markerList.length; },
handlePanelMovements: function handlePanelMovementsFn() {
// open panel $("#panel-distance").trigger("updatelayout"); $("#panel-distance").panel("open", 1234); } else {
// no places are visible, because the are not loaded yet World.updateStatusMessage('No places available yet', true); } },
// request POI data requestDataFromServer: function requestDataFromServerFn(lat, lon) {
// set helper var to avoid requesting places while loading World.isRequestingData = true; World.updateStatusMessage('Requesting places from web-service');
// helper to sort places by distance sortByDistanceSorting: function(a, b) { return a.distanceToUser - b.distanceToUser; },
// helper to sort places by distance, descending sortByDistanceSortingDescending: function(a, b) { return b.distanceToUser - a.distanceToUser; }
};
/* forward locationChanges to custom function */ AR.context.onLocationChanged = World.locationChanged;
/* forward clicks in empty area to World */ AR.context.onScreenClick = World.onScreenClick;
A
Andreas Fötschl
said
about 7 years ago
Note that the html code in the samples is based on JQueryMobile and independent from Wikitude's AR-features.
I hope you understand that this forum is focusing on AR namespace specific questions. Please have a look at JQuery Mobile Panel samples and forums instead.
In theory you can place any content in the panel and set picture origin using jquery and data from the JSON.
Adi Nugraha