Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 1x 1x 8x 8x 8x 6x 6x 6x 6x 3x 3x 6x 6x 6x 2x 4x 4x 6x 4x 4x 4x | import Cartesian3 from "./Cartesian3.js";
import Check from "./Check.js";
/**
* Geocodes queries containing longitude and latitude coordinates and an optional height.
* Query format: `longitude latitude (height)` with longitude/latitude in degrees and height in meters.
*
* @alias CartographicGeocoderService
* @constructor
*/
function CartographicGeocoderService() {}
Object.defineProperties(CartographicGeocoderService.prototype, {
/**
* Gets the credit to display after a geocode is performed. Typically this is used to credit
* the geocoder service.
* @memberof CartographicGeocoderService.prototype
* @type {Credit|undefined}
* @readonly
*/
credit: {
get: function () {
return undefined;
},
},
});
/**
* @function
*
* @param {string} query The query to be sent to the geocoder service
* @returns {Promise<GeocoderService.Result[]>}
*/
CartographicGeocoderService.prototype.geocode = function (query) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.string("query", query);
//>>includeEnd('debug');
const splitQuery = query.match(/[^\s,\n]+/g);
if (splitQuery.length === 2 || splitQuery.length === 3) {
let longitude = +splitQuery[0];
let latitude = +splitQuery[1];
const height = splitQuery.length === 3 ? +splitQuery[2] : 300.0;
if (isNaN(longitude) && isNaN(latitude)) {
const coordTest = /^(\d+.?\d*)([nsew])/i;
for (let i = 0; i < splitQuery.length; ++i) {
const splitCoord = splitQuery[i].match(coordTest);
Eif (coordTest.test(splitQuery[i]) && splitCoord.length === 3) {
if (/^[ns]/i.test(splitCoord[2])) {
latitude = /^[n]/i.test(splitCoord[2])
? +splitCoord[1]
: -splitCoord[1];
} else Eif (/^[ew]/i.test(splitCoord[2])) {
longitude = /^[e]/i.test(splitCoord[2])
? +splitCoord[1]
: -splitCoord[1];
}
}
}
}
if (!isNaN(longitude) && !isNaN(latitude) && !isNaN(height)) {
const result = {
displayName: query,
destination: Cartesian3.fromDegrees(longitude, latitude, height),
};
return Promise.resolve([result]);
}
}
return Promise.resolve([]);
};
export default CartographicGeocoderService;
|