AnsweredAssumed Answered

Displaying Points on Different Projections

Question asked by jet_cm@jetisre.com on Feb 3, 2017
Latest reply on Feb 7, 2017 by MKennedy-esristaff

I'm trying to do something very simple and can not seem to figure out what the problem is.  I have a REST service that retrieves locations with decimal lat/long's.  I want to add a point to a map for each of these locations.  As long as the spatial reference is 4326, everything is fine.  If I try to add points in any other spatial reference, they are added incorrectly.  Specifically, I am trying to add points to a 102021 projection (Antarctica).  Even when I set the map's spatial reference to 102021 and use a layer whose projection is defined as 102021, and specify 102021 as the spatial reference in my Point constructor, the points are not added to the correct locations.  Through various attempts, I have been able to get the correct projection with the wrong points, the correct points on the wrong projection, and the wrong projection with the wrong points.  All other resources have shown this to be a fairly easy task, but I am at a loss as to why this isn't working, and any help would be greatly appreciated.  Code snippet below.

 

var map;

require([
"esri/geometry/Point",
"esri/geometry/Extent",
"esri/tasks/GeometryService",
"esri/tasks/ProjectParameters",
"esri/SpatialReference",
"esri/symbols/SimpleMarkerSymbol",
"esri/graphic",
"esri/Color",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/map",
"dojo/parser",
"dojo/request/xhr",
"dojo/_base/array",
"esri/geometry/webMercatorUtils",
"dojo/domReady!",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane"],
function(Point, Extent, GeometryService, ProjectParameters, SpatialReference, SimpleMarkerSymbol, Graphic, Color, ArcGISDynamicMapServiceLayer,
ArcGISTiledMapServiceLayer, Map, parser, xhr, Array, webMercUtils)
{
gsvc = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
params = new ProjectParameters();


// a map layer defined as 102021
var antarcLayer = new ArcGISDynamicMapServiceLayer("https://gis.icao.int/ArcGIS/rest/services/ANTARCTIC/MapServer");
var symbol = new SimpleMarkerSymbol();
symbol.setColor(new Color("#00FFFF"));

parser.parse();

// coords are passed in
map = new Map("mapDiv", {
   extent: new Extent({
   xmin: <%=minX%>,
   ymin: <%=minY%>,
   xmax: <%=maxX%>,
   ymax: <%=maxY%>,
   spatialReference:{wkid: 102021}
   })
});
map.addLayer(antarcLayer);

// I have tried webMercatorUtils to convert from geometry to mercator and back and lat/long to xy and back, and these do not work either
// I have also tried using Geometry Service "project"
map.on("load",function(){
   xhr("<rest_url>", {
   method: "GET",
   handleAs: "json"
   }).then(function(jsonData){
     Array.forEach(jsonData, function(entry,i){
     console.log(entry.platformId + "," + entry.latitude + "," + entry.longitude + " at index " + i );
     var pt = new Point(entry.longitude, entry.latitude, new SpatialReference(102021));
     map.graphics.add(new Graphic(pt, symbol));
     });
   });
});
});

</script>
<body class="claro">
<div id="mapDiv"></div>
</body>

Outcomes