Mapping Web Mercator coordinate as LatLng

339
7
Jump to solution
02-28-2018 12:30 AM
MuhammadFayaz
Occasional Contributor

Hello,

I want to take user coordinates as Web Mercator and place it as late long as point on map and zoom it but no success:

Following is my attempt:

app.addUserPnt = function (pointXY) {
console.info(pointXY);

map.graphics.remove();

var myPoint = {

"geometry": {
"x": pointXY[0], "y": pointXY[1],
"spatialReference": 32638,
}, "attributes": {
"XCoord": pointXY[0],
"YCoord": pointXY[1],
}, "symbol": {
"color": [255, 0, 0, 128],
"size": 12, "angle": 0, "xoffset": 0, "yoffset": 0, "type": "esriSMS",
"style": "esriSMSCircle", "outline": {
"color": [0, 0, 0, 255], "width": 1,
"type": "esriSLS", "style": "esriSLSSolid"
}
},
}
var outSR = new SpatialReference(4326);
var params1 = new ProjectParameters();
params1.geometries = [myPoint];
params1.outSR = outSR;

gsvc.project(params1, function(projectedPoints) {
myPoint = projectedPoints[0];
});

var gra = new Graphic(myPoint);

map.graphics.add(gra);
map.centerAndZoom(gra.geometry, 17)

};

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Muhammed,

   Your issue is that you are trying to reproject the mypoint var which is just a string. The project is expecting a geometry not a string.

  app.addUserPnt = function(pointXY) {
  console.info(pointXY);

  map.graphics.remove();

  var myGraphic = {
    "geometry": {
      "x": pointXY[0],
      "y": pointXY[1],
      "spatialReference": 32638,
    },
    "attributes": {
      "XCoord": pointXY[0],
      "YCoord": pointXY[1],
    },
    "symbol": {
      "color": [255, 0, 0, 128],
      "size": 12,
      "angle": 0,
      "xoffset": 0,
      "yoffset": 0,
      "type": "esriSMS",
      "style": "esriSMSCircle",
      "outline": {
        "color": [0, 0, 0, 255],
        "width": 1,
        "type": "esriSLS",
        "style": "esriSLSSolid"
      }
    },
  }
  var gra = new Graphic(myGraphic);
  var point = new Point( {"x": pointXY[0], "y": pointXY[1], "spatialReference": {"wkid": 32638} });
  var params1 = new ProjectParameters();
  params1.geometries = [point];
  params1.outSR = new SpatialReference(4326);

  gsvc.project(params1, function(projectedPoints) {
    point = projectedPoints[0];
  });

  var gra.setGeometry(point);

  map.graphics.add(gra);
  map.centerAndZoom(gra.geometry, 17);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Muhammed,

  Are you using 4.x or 3.x API?

MuhammadFayaz
Occasional Contributor

Dear Robert,

I am using v 3.23 api.

0 Kudos
KenBuja
MVP Honored Contributor

You have to add myPoint to the graphics layer inside the project function.

gsvc.project(params1, function(projectedPoints) { 
  myPoint = projectedPoints[0];
  var gra = new Graphic(myPoint);
  map.graphics.add(gra);
  map.centerAndZoom(gra.geometry, 17)
});
MuhammadFayaz
Occasional Contributor

Ken Buja, 

I tried it this way, but still not working. Following is the error i get:

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Muhammed,

   Your issue is that you are trying to reproject the mypoint var which is just a string. The project is expecting a geometry not a string.

  app.addUserPnt = function(pointXY) {
  console.info(pointXY);

  map.graphics.remove();

  var myGraphic = {
    "geometry": {
      "x": pointXY[0],
      "y": pointXY[1],
      "spatialReference": 32638,
    },
    "attributes": {
      "XCoord": pointXY[0],
      "YCoord": pointXY[1],
    },
    "symbol": {
      "color": [255, 0, 0, 128],
      "size": 12,
      "angle": 0,
      "xoffset": 0,
      "yoffset": 0,
      "type": "esriSMS",
      "style": "esriSMSCircle",
      "outline": {
        "color": [0, 0, 0, 255],
        "width": 1,
        "type": "esriSLS",
        "style": "esriSLSSolid"
      }
    },
  }
  var gra = new Graphic(myGraphic);
  var point = new Point( {"x": pointXY[0], "y": pointXY[1], "spatialReference": {"wkid": 32638} });
  var params1 = new ProjectParameters();
  params1.geometries = [point];
  params1.outSR = new SpatialReference(4326);

  gsvc.project(params1, function(projectedPoints) {
    point = projectedPoints[0];
  });

  var gra.setGeometry(point);

  map.graphics.add(gra);
  map.centerAndZoom(gra.geometry, 17);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

MuhammadFayaz
Occasional Contributor

Thank you, it worked for me!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Great,  Don’t forget to mark this question as answered by clicking on the correct answer link in the reply that answered your question then.

0 Kudos