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)
};
Solved! Go to Solution.
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);
Muhammed,
Are you using 4.x or 3.x API?
Dear Robert,
I am using v 3.23 api.
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)
});
Ken Buja,
I tried it this way, but still not working. Following is the error i get:
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);
Thank you, it worked for me!
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.