Displaying Points on Different Projections

2091
14
02-03-2017 11:15 AM
DianeJorgensen
New Contributor

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>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
14 Replies
MelitaKennedy
Esri Notable Contributor

Using Project is the right idea. You need to identify the incoming points as 4326, then Project them to 102021. 

If you can give a sample input point, plus its output coordinates for various workflows, we might be able to tell what's happening.

Melita

DianeJorgensen
New Contributor

I'm not sure what you mean by "output coordinates for various workflows", but an input point would look like this if the value weren't a variable:

new Point(172.5322, -43.4892, new SpatialReference(102021));
0 Kudos
MelitaKennedy
Esri Notable Contributor

Hi Diane, 

You were trying a bunch of different things which is what I meant by "workflows." This line:

new Point(172.5322, -43.4892, new SpatialReference(102021));

should be

new Point(172.5322, -43.4892, new SpatialReference(4326));

Then the point needs to be projected using geometry server to 102021.

0 Kudos
DianeJorgensen
New Contributor

Thanks for the reply!  I've made some progress trying to follow your advice and use the geometry server.  The points display now!  Thank you very much for this.  The problem now, though, is that on initial load as well as every time I zoom in or out, I get two errors: 

Error: <circle> attribute cx: Expected length, "NaN".

Error: <circle> attribute cy: Expected length, "NaN".

I'm not sure what the cause of this is, since I am only drawing Points on the map and not Circles.  Here's the updated method:

map.on("load",function(){
  console.log(map.extent);
  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(4326));
 
      gsvc.project([pt], new SpatialReference(102021), function(projectedPoints){
        map.graphics.add(new Graphic(projectedPoints[0], symbol));
      });
    });
  });
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks again for the help!

0 Kudos
MelitaKennedy
Esri Notable Contributor

Maybe the symbol isn't defined correctly? But that's a wild guess on my part.

0 Kudos