Find more Examples here

All searches: Full Text, Filter, Nearby, Toptipps (Map-API)

Version reduced to minimal set of HTML Read Example Description


Description

The result sets (id list) of full text searches, tour filters, near by searches and the top tipps of an Outdooractive API project are all requested by the method oa.api.requestIds().

<div id="buttons"></div>
<hr/>
<ul id="resultList">
</ul>
// example requests:
// a list of different request objects
var requests = {

    // full text search
    "search":   { search : "igel" },

    // tour filter: tours with ascending meters >= 500
    "filter":   { filter : { asc_s : 500 } },

    // project's top tipps
    "toptipps": "toptipps",

    // nearBy search: location (center; lat/lng), radius (meters)
    "nearby":   {
        searchNearby : {
            location : {
                lat:47.547,
                lng:10.293},
            radius : 10000 }
    }
};

// send a search request on page load
sendRequest( requests["search"] );

// find the parent dom node for a little menu
var div = document.getElementById("buttons");

// iterate over all requests and add a button to the menu
for(var k in requests) {

    if ( requests.hasOwnProperty(k) ) {

        // create button html element
        var button = document.createElement("button");

        // call sendRequest function with the button's request object
        button.onclick = sendRequest.bind( null, requests[k] );

        // set the button title
        button.innerHTML = k;

        // append button to the menu div container
        div.appendChild(button);
    }
}

// function that sends an request to the Outdooractive Platform
// request: request object (see above)
function sendRequest( request ) {

    // reference to last request to handle race conditions
    var last_request = request;

    // find document element of unordered list
    var ul = document.getElementById("resultList");

    // remove all list items
    while (ul.firstChild) {
        ul.removeChild(ul.firstChild);
    }

    // send request to Outdooractive Platform
    oa.api.requestIds( request, callback );

    // ids request callback
    function callback( answer ) {

        // check wether the request was successfull
        // and if another request was sent in the meanwhile
        if (answer.success && answer.request === last_request) {

            // grab ids from answer object
            var ids = answer.data.ids;

            // load some data of the OOIs of the result set
            loadOOIs( ids );
        }
    }

}

// load minimal data subset
// ids: array of OOI ids
function loadOOIs( ids ) {

    // copy the first 10 items of the id list
    ids = ids.slice( 0, 10 );

    // new content request object
    var ooiRequest = new oa.api.OOIs( 
        {
            // list of string ids
            idlist:  ids,
            
            // only load a minimal subset of OOI attributes and data
            // (e.g. title, category, etc.)
            minimal: true
        });

    // tell the Objects API to load the data
    ooiRequest.load( callback );

    // content request callback
    function callback( status, oois ) {

        // find unordered list dom element
        var ul = document.getElementById("resultList");

        // iterate over result set
        for(var i=0; i<oois.length; i++) {

            // create list item
            var li = document.createElement("li");
            
            // create hyper link
            var a = document.createElement("a");

            // add href attribute with redirect url to detail page on Outdooractive Portal
            a.setAttribute("href", "http://www.outdooractive.com/r/"+oois[i].id);

            // set link title
            a.innerHTML = oois[i].title;

            // append link to list item
            li.appendChild(a);

            // append list item to unordered list
            ul.appendChild(li);
        }
    }

}