var requestHandle = esriRequest({
"url": "http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationAtLonLat",
"content": {
"lon": longitude,
"lat": latitude,
"format": "json"
},
"handeAs": "json",
"callbackParamName": "callback"
});
requestHandle.then(requestSucceeded, requestFailed);
}
function requestSucceeded(data){
elev = JSON.parse(data);
arrayUtils.forEach(elev, function(e) {
var elev_meter = e.elevation;
elev_ft = elev_meter * 3.2808399;
elevation += elev_ft ;
alert(elevation);
});
}
I must be missing something easy, as there are no examples of this.
I would like to retrieve the value of the elevation for a given lat/long. Do I really need a proxy or can't I just use the ESRI_Elevation_World -> GetElevationAtLonLat service?
Here's my code:var requestHandle = esriRequest({ "url": "http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationAtLonLat", "content": { "lon": longitude, "lat": latitude, "format": "json" }, "handeAs": "json", "callbackParamName": "callback" }); requestHandle.then(requestSucceeded, requestFailed); } function requestSucceeded(data){ elev = JSON.parse(data); arrayUtils.forEach(elev, function(e) { var elev_meter = e.elevation; elev_ft = elev_meter * 3.2808399; elevation += elev_ft ; alert(elevation); }); }
Thank you.
function requestSucceeded(data){
result= JSON.parse(data);
elevation = result.elevation;
}
XMLHttpRequest cannot load http://sampleserver4.arcgisonline.com/ArcGIS/rest/info?f=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://apps.wrd.state.or.us' is therefore not allowed access. index.html:1 Resource interpreted as Script but transferred with MIME type text/html: "http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_E�?�094&format=json&callback=dojo.io.script.jsonp_dojoIoScript9._jsonpCallback". init.js:1035 Uncaught SyntaxError: Unexpected token <
function getElevation(latitude, longitude) {
elevurl = decodeURIComponent("http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationAtLonLat");
elev_uri = elevurl + "?lon=" + longitude.toString() + "&lat=" + latitude.toString() + "&f=pjson";
var requestHandle = esriRequest({
url: elev_uri,
handeAs: "json",
callbackParamName: "callback"
});
requestHandle.then(requestSucceeded, requestFailed);
}
function requestSucceeded(data) {
elev_meter = data.elevation;
elev_ft = elev_meter * 3.2808399;
}
function requestFailed(error, io){
dojoJson.toJsonIndentStr = " ";
dom.byId("message").value = dojoJson.toJson(error, true);
}
var elevationServiceUrl = "http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationAtLonLat"
dojo.connect(map, 'onClick', function (evt) {
esri.request({
url: elevationServiceUrl,
content: {
lon: evt.mapPoint.getLongitude(),
lat: evt.mapPoint.getLatitude(),
f: "json"
},
callbackParamName: "callback",
}).then(function (response, io) {
alert("Elevation = " + response.elevation.toFixed(1) + " meters");
}, function (error, io) {
console.error("Unable to get elevation", error);
alert("Unable to get elevation...");
});
});