I am using a Map service on ARcGIS Server 10.4.1 which is in this format
Spatial Reference: 102100 (3857)
Single Fused Map Cache: false
Initial Extent:
Full Extent:
Units: esriMeters
Now when I query the service it returns the data in Meter format which I can not display back them on the map as new graphics. Can you please let me know how I can change the service configuration or OutUnit in ArcGIS JavaScript API to be in Decimal Degree
Bengi,
Because the map service is in WKID 102100 that means that the units will be meters. If you use a Query task then you can specify the outSpatialReference to be in 4326 which will give you decimal degrees
Hi Robert,
Thanks for reply I change the out spatial to 4326 and as you can see from below I am getting geometry in wkid:4236 but I am getting the X and Y in Meter not in decimal degree!
Bengi,
Can you share your code on how you are changing the outSpatialReference?
Hi Robert,
Here is the code
I am able to console log the results but not able to display them on the map
var graphicsLayerTraceNetworkJunctions, graphicsLayerTraceNetworkEdges;
graphicsLayerTraceNetworkJunctions = new esri.layers.GraphicsLayer();
var rendererTraceNetworkJunctions = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkJunctions);
graphicsLayerTraceNetworkJunctions.setRenderer(rendererTraceNetworkJunctions);
map.addLayer(graphicsLayerTraceNetworkJunctions);
map.reorderLayer(graphicsLayerTraceNetworkJunctions, 1);
graphicsLayerTraceNetworkEdges = new esri.layers.GraphicsLayer();
var rendererTraceNetworkEdges = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkEdges);
graphicsLayerTraceNetworkEdges.setRenderer(rendererTraceNetworkEdges);
map.addLayer(graphicsLayerTraceNetworkEdges);
map.reorderLayer(graphicsLayerTraceNetworkEdges, 2);
function solve(traceSolverType, params) {
var gn = 'ElecGeomNet';
esri.request({
url: 'http://localhost/arcgis/rest/services/ENetNADPDWeb/MapServer/exts/GeometricNetworkUtility/GeometricN...' + traceSolverType,
content: params,
callbackParamName: "callback",
outSR: 4326,
load: function (result) {
//result = result.geometry = webMercatorUtils.webMercatorToGeographic(geometries[0]);
if (traceFlowElement == 'esriFEJunctionsAndEdges') {
var edgesResultFeatures = result.edges;
console.log(edgesResultFeatures);
var edgeGraphics;
for (var j = 0, jl = edgesResultFeatures.length; j < jl; j++) {
var featureSet = edgesResultFeatures[j].features;
for (var i = 0, il = featureSet.length; i < il; i++) {
edgeGraphics = new esri.Graphic(featureSet[i])
graphicsLayerTraceNetworkEdges.add(edgeGraphics);
}
}
var junctionsResultFeatures = result.junctions;
console.log(junctionsResultFeatures);
var junctionsGraphics;
for (var j = 0, jl = junctionsResultFeatures.length; j < jl; j++) {
var featureSet = junctionsResultFeatures[j].features;
for (var i = 0, il = featureSet.length; i < il; i++) {
junctionsGraphics = new esri.Graphic(featureSet[i]);
graphicsLayerTraceNetworkJunctions.add(junctionsGraphics);
}
}
}
}
Setting outSpatialReference somewhere might help you if you're trying to query a Feature Service.
Another option is to pull in webMercatorUtils from esri/geometry/support/webMercatorUtils and use that module to convert between Web Mercator and WGS84 Latitude/Longitude.
webMercatorUtils | API Reference | ArcGIS API for JavaScript 4.5
I would specifically look at the "webMercatorToGeographic" function, which will convert a geometry from Web Mercator to WGS84 longitude/latitude.
Thanks for comment Thomas,
I tried to do this in two ways
A_
load: function (result) {
result = result.geometry = webMercatorUtils.webMercatorToGeographic(geometries[0]);
....
}
and also tried this way B_
var junctionsResultFeatures = result.junctions;
junctionsResultFeatures = featureSet.map(function (s) {
s.geometry = webMercatorUtils.xyToLngLat(s.geometry.x, s.geometry.y, true);
return s;
})
the first way ireturns
nothing! no error but also nothing on console log. The second way is really converting the geometry to decimal degree but again I am not seeing the result graphics on map
Bengi,
I am not familiar with a the geometric network trace task and if you are specifying the outSR correctly. But as Thomas points out you can easily convert the results of your task (assuming they are returning in WKID 102100) to WGS84 by using web mercator utils.
Lines 32 and 45:
var graphicsLayerTraceNetworkJunctions, graphicsLayerTraceNetworkEdges;
graphicsLayerTraceNetworkJunctions = new esri.layers.GraphicsLayer();
var rendererTraceNetworkJunctions = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkJunctions);
graphicsLayerTraceNetworkJunctions.setRenderer(rendererTraceNetworkJunctions);
map.addLayer(graphicsLayerTraceNetworkJunctions);
map.reorderLayer(graphicsLayerTraceNetworkJunctions, 1);
graphicsLayerTraceNetworkEdges = new esri.layers.GraphicsLayer();
var rendererTraceNetworkEdges = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkEdges);
graphicsLayerTraceNetworkEdges.setRenderer(rendererTraceNetworkEdges);
map.addLayer(graphicsLayerTraceNetworkEdges);
map.reorderLayer(graphicsLayerTraceNetworkEdges, 2);
function solve(traceSolverType, params) {
var gn = 'ElecGeomNet';
esri.request({
url: 'http://localhost/arcgis/rest/services/ENetNADPDWeb/MapServer/exts/GeometricNetworkUtility/GeometricN...' + traceSolverType,
content: params,
callbackParamName: "callback",
outSR: 4326,
load: function (result) {
//result = result.geometry = webMercatorUtils.webMercatorToGeographic(geometries[0]);
if (traceFlowElement == 'esriFEJunctionsAndEdges') {
var edgesResultFeatures = result.edges;
console.log(edgesResultFeatures);
var edgeGraphics;
for (var j = 0, jl = edgesResultFeatures.length; j < jl; j++) {
var featureSet = edgesResultFeatures[j].features;
for (var i = 0, il = featureSet.length; i < il; i++) {
edgeGraphics = new esri.Graphic(esri.geometry.webMercatorUtils.webMercatorToGeographic(featureSet[i].geometry));
graphicsLayerTraceNetworkEdges.add(edgeGraphics);
}
}
var junctionsResultFeatures = result.junctions;
console.log(junctionsResultFeatures);
var junctionsGraphics;
for (var j = 0, jl = junctionsResultFeatures.length; j < jl; j++) {
var featureSet = junctionsResultFeatures[j].features;
for (var i = 0, il = featureSet.length; i < il; i++) {
junctionsGraphics = new esri.Graphic(esri.geometry.webMercatorUtils.webMercatorToGeographic(featureSet[i].geometry));
graphicsLayerTraceNetworkJunctions.add(junctionsGraphics);
}
}
}
}
Thanks for this Ribert but same thing! I am not even getting the result back oon console log
Bengi,
Have you ever been getting any results at all from your esriRequest?