I have a widget that calculate map extent or lat/long.
I need to convert these values to UTM (Mercator). Could you please help. I have included my code below.
define([
'dojo/_base/declare',
'dojo/_base/lang',
'jimu/BaseWidget',
'jimu/WidgetManager'
],
function (
declare,
lang,
BaseWidget,
WidgetManager) {
var clazz = declare([BaseWidget], {
name: 'UrlButton',
baseClass: 'widget-urlbutton',
isOpening: false,
onOpen: function () {
if (!this.isOpening) {
this.isOpening = true;
//Get lat,long,scale start
var mapCeneter = this.map.extent.getCenter();
var lat = mapCeneter.getLatitude();
var lon = mapCeneter.getLongitude();
var minxx = this.map.extent.xmin;
var minyy = this.map.extent.ymin;
var maxxx = this.map.extent.xmax;
var maxyy = this.map.extent.ymax;
Do I have to use toUtm(point, conversionMode, addSpaces)
I would just take the geometry and use the GeometryService to project it to the UTM zone you are interested in.
Thanks for prompt response. Could you share code or steps please.
Raju,
The documentation has some code for that:
https://developers.arcgis.com/javascript/3/jsapi/geometryservice-amd.html#project
require([
"esri/tasks/ProjectParameters", ...
], function(ProjectParameters, ... ) {
var params = new ProjectParameters();
params.geometries = [point];
params.outSR = outSR;
params.transformation = transformation;
gsvc.project(params);
...
});
I didn't imagine It would be tough to convert lat,long into bbox. I am trying to use this function but getting stuck on gsvc. Could you please guide me what I is wrong in my code.
var params = new ProjectParameters();
params.geometries = [lat, lon];
params.outSR = 4326; // is it source transformation?
params.transformation = 4326; // is it destination transformation?
console.log(params)
var gsvc; // what kind of variable is required?
gsvc.project(params); // how I can get bbox from gsvc varaible?
Raju,
The geometry service geometries property is expecting an array of geometries. You have giving it an array of Lat, Lon coordinates. Create a point class from your coordinates and then add that point class to the geometries array.
Thanks Rob for being helpful. I am getting error TypeError: Cannot read property 'spatialReference' of undefined
var outSR = new SpatialReference({ wkid: 4326 });
var mapPnt = new Point(lon, lat);
var params = new ProjectParameters();
params.geometries = mapPnt;
params.outSR = 4326;
params.transformation = 4326;
var geometryService = esri.tasks.GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryService.project(params);
Raju,
You have not specified a SR when you created the Point.
var mapPnt = new Point(lon, lat, missing SpatialReference);
I hope you have a nice weekend. I am still getting same error after adding spatial reference.
var outSR = new SpatialReference({ wkid: 4326 });
var mapPnt = new Point(lon, lat, outSR);
var params = new ProjectParameters();
params.geometries = mapPnt;
params.outSR = outSR;
params.transformation = 4326;
var geometryService = esri.tasks.GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryService.project(params);
Do I have to use daw-complete to re-project?
// geometry service
var toolbar = new Draw(this.map);
toolbar.on("draw-omplete", addToMap);
addtoMap: function (evt) {
var graphic = new Graphic(evt.geometry, symbol);
map.graphics.add(graphic);
console.log(dojo.toJson(geometry.toJson()));