/** * Used for the search address feature */ //load address var request = new XMLHttpRequest(); request.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var coordinate = JSON.parse(request.responseText); var lat = coordinate.results[0].geometry.lat; var lng = coordinate.results[0].geometry.lng; console.log(lat + " " + lng); fly(lat, lng); } } //sending a request to the opencage api to convert the input to coordinates function searchaddress() { var query = document.getElementById('SearchAddress').value; request.open("GET", 'https://api.opencagedata.com/geocode/v1/json?key=c73da14969e6408ab4535b3ad6dc43ea&pretty=1&no_annotations=1&q=' + query, true); request.send(); } //used to fly to the found position function fly(lat, lng) { var pinBuilder = new Cesium.PinBuilder(); var bluePin = viewer.entities.add({ name: "Blank blue pin", position: Cesium.Cartesian3.fromDegrees(lng, lat), billboard: { image: pinBuilder.fromColor(Cesium.Color.ROYALBLUE, 48).toDataURL(), verticalOrigin: Cesium.VerticalOrigin.BOTTOM, }, }); viewer.zoomTo(bluePin); viewer.flyTo(bluePin); }