apps/web-app-template/app.js
/**
     * Search view model. Uses the MapQuest Nominatim API. 
     * Requires an access key. See: https://developer.mapquest.com/
     * @param {Globe} globe
     * @param {Function} preview Function to preview the results
     * @returns {SearchViewModel}
     */
Search view model. Uses the MapQuest Nominatim API.
Requires an access key.
Search view model . Uses the MapQuest Nominatim API . Requires an access key .
function SearchViewModel(globe, preview) {
        var self = this;
        self.geocoder = new WorldWind.NominatimGeocoder();
        self.searchText = ko.observable('');
        self.performSearch = function () {
            if (!MAPQUEST_API_KEY) {
                console.error("SearchViewModel: A MapQuest API key is required to use the geocoder in production. Get your API key at https://developer.mapquest.com/");
            }
            let queryString = self.searchText();
            if (queryString) {
                if (queryString.match(WorldWind.WWUtil.latLonRegex)) {
                    let tokens = queryString.split(",");
                    let latitude = parseFloat(tokens[0]);
                    let longitude = parseFloat(tokens[1]);
                    globe.wwd.goTo(new WorldWind.Location(latitude, longitude));
                } else {
                    self.geocoder.lookup(queryString, function (geocoder, results) {
                        if (results.length > 0) {
                            preview(results);
                        }
                    }, MAPQUEST_API_KEY);
                }
            }
        };
    }
function SearchViewModel ( globe , preview ) { var self = this ; self . geocoder = new WorldWind . NominatimGeocoder ( ) ; self . searchText = ko . observable ( '' ) ; self . performSearch = function ( ) { if ( ! MAPQUEST_API_KEY ) { console . error ( "SearchViewModel: A MapQuest API key is required to use the geocoder in production. Get your API key at https://developer.mapquest.com/" ) ; } let queryString = self . searchText ( ) ; if ( queryString ) { if ( queryString . match ( WorldWind . WWUtil . latLonRegex ) ) { let tokens = queryString . split ( "," ) ; let latitude = parseFloat ( tokens [ 0 ] ) ; let longitude = parseFloat ( tokens [ 1 ] ) ; globe . wwd . goTo ( new WorldWind . Location ( latitude , longitude ) ) ; } else { self . geocoder . lookup ( queryString , function ( geocoder , results ) { if ( results . length > 0 ) { preview ( results ) ; } } , MAPQUEST_API_KEY ) ; } } } ; }
Search view model.
Search view model .
// Get the value from the observable // Treat the text as a lat, lon pair  // Center the globe on the lat, lon // Treat the text as an address or place name // Open the modal dialog to preview and select a result