-
Notifications
You must be signed in to change notification settings - Fork 241
/
GeometryService.js
25 lines (24 loc) · 12.4 KB
/
GeometryService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// COPYRIGHT © 2020 Esri
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// This material is licensed for use under the Esri Master License
// Agreement (MLA), and is bound by the terms of that agreement.
// You may redistribute and use this code without modification,
// provided you adhere to the terms of the MLA and include this
// copyright notice.
//
// See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
//
// For additional information, contact:
// Environmental Systems Research Institute, Inc.
// Attn: Contracts and Legal Services Department
// 380 New York Street
// Redlands, California, USA 92373
// USA
//
// email: [email protected]
//
// See http://js.arcgis.com/4.15/esri/copyright.txt for details.
define(["require","exports","../core/tsSupport/declareExtendsHelper","../core/tsSupport/decorateHelper","../core/tsSupport/paramHelper","../core/tsSupport/assignHelper","../geometry","../request","../core/jsonMap","../core/accessorSupport/decorators","../core/accessorSupport/ensureType","../geometry/support/jsonUtils","./Task","./operations/generalize","./operations/lengths","./operations/offset","./operations/relation","./operations/trimExtend","./support/GeneralizeParameters","./support/LengthsParameters","./support/OffsetParameters","./support/ProjectParameters","./support/RelationParameters","./support/TrimExtendParameters"],(function(e,t,r,s,n,i,o,a,p,N,u,f,_,T,c,l,I,d,O,U,S,h,y,m){var g=new p.JSONMap({MGRS:"mgrs",USNG:"usng",UTM:"utm",GeoRef:"geo-ref",GARS:"gars",DMS:"dms",DDM:"ddm",DD:"dd"}),R=u.ensureType(h);return function(e){function t(t){var r=e.call(this,t)||this;return r.url=null,r}return r(t,e),t.prototype.areasAndLengths=function(e,t){var r=i({},this.parsedUrl.query,{f:"json"},e.toJSON()),s=this._asValidOptions(r,t);return a(this.parsedUrl.path+"/areasAndLengths",s).then((function(e){return e.data}))},t.prototype.autoComplete=function(e,t,r){var s=e[0].spatialReference,n=i({},this.parsedUrl.query,{f:"json",sr:JSON.stringify(s.toJSON()),polygons:JSON.stringify(this._encodeGeometries(e).geometries),polylines:JSON.stringify(this._encodeGeometries(t).geometries)}),p=this._asValidOptions(n,r);return a(this.parsedUrl.path+"/autoComplete",p).then((function(e){return(e.data.geometries||[]).map((function(e){return new o.Polygon({spatialReference:s,rings:e.rings})}))}))},t.prototype.buffer=function(e,t){var r=i({},this.parsedUrl.query,{f:"json"},e.toJSON()),s=e.outSpatialReference||e.geometries[0].spatialReference,n=this._asValidOptions(r,t);return a(this.parsedUrl.path+"/buffer",n).then((function(e){return(e.data.geometries||[]).map((function(e){return new o.Polygon({spatialReference:s,rings:e.rings})}))}))},t.prototype.convexHull=function(e,t){var r=e[0].spatialReference,s=i({},this.parsedUrl.query,{f:"json",sr:JSON.stringify(r.toJSON()),geometries:JSON.stringify(this._encodeGeometries(e))}),n=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/convexHull",n).then((function(e){var t=e.data;return f.fromJSON(t.geometry).set({spatialReference:r})}))},t.prototype.cut=function(e,t,r){var s=e[0].spatialReference,n=e.map((function(e){return e.toJSON()})),o=i({},this.parsedUrl.query,{f:"json",sr:JSON.stringify(s.toJSON()),target:JSON.stringify({geometryType:f.getJsonType(e[0]),geometries:n}),cutter:JSON.stringify(t.toJSON())}),p=this._asValidOptions(o,r);return a(this.parsedUrl.path+"/cut",p).then((function(e){var t=e.data,r=t.geometries||[];return{cutIndexes:t.cutIndexes,geometries:r.map((function(e){return f.fromJSON(e).set({spatialReference:s})}))}}))},t.prototype.densify=function(e,t){var r=e.geometries[0].spatialReference,s=i({},this.parsedUrl.query,{f:"json"},e.toJSON()),n=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/densify",n).then((function(e){return(e.data.geometries||[]).map((function(e){return f.fromJSON(e).set({spatialReference:r})}))}))},t.prototype.difference=function(e,t,r){var s=e[0].spatialReference,n={query:i({},this.parsedUrl.query,{f:"json",sr:JSON.stringify(s.toJSON()),geometries:JSON.stringify(this._encodeGeometries(e)),geometry:JSON.stringify({geometryType:f.getJsonType(t),geometry:t.toJSON()})})};return(this.requestOptions||r)&&(n=i({},this.requestOptions,r,n)),a(this.parsedUrl.path+"/difference",n).then((function(e){return(e.data.geometries||[]).map((function(e){return f.fromJSON(e).set({spatialReference:s})}))}))},t.prototype.distance=function(e,t){var r=i({},this.parsedUrl.query,{f:"json"},e.toJSON()),s=this._asValidOptions(r,t);return a(this.parsedUrl.path+"/distance",s).then((function(e){var t=e.data;return t&&t.distance}))},t.prototype.fromGeoCoordinateString=function(e,t){var r={};null!=e.sr&&"object"==typeof e.sr?r.sr=e.sr.wkid||JSON.stringify(e.sr):r.sr=e.sr,r.strings=JSON.stringify(e.strings);var s=e.conversionType||"mgrs";r.conversionType=g.toJSON(s),r.conversionMode=e.conversionMode;var n=i({},this.parsedUrl.query,{f:"json"},r),o=this._asValidOptions(n,t);return a(this.parsedUrl.path+"/fromGeoCoordinateString",o).then((function(e){return e.data.coordinates}))},t.prototype.generalize=function(e,t){var r=(e=O.from(e)).toJSON(),s=T.generalizeToRESTParameters(e),n=i({},this.parsedUrl.query,{f:"json"},s),o=r.geometries[0].spatialReference,p=this._asValidOptions(n,t);return a(this.parsedUrl.path+"/generalize",p).then((function(e){return(e.data.geometries||[]).map((function(e){return f.fromJSON(e).set({spatialReference:o})}))}))},t.prototype.intersect=function(e,t,r){var s=e[0].spatialReference,n=i({},this.parsedUrl.query,{f:"json",sr:JSON.stringify(s.toJSON()),geometries:JSON.stringify(this._encodeGeometries(e)),geometry:JSON.stringify({geometryType:f.getJsonType(t),geometry:t.toJSON()})}),o=this._asValidOptions(n,r);return a(this.parsedUrl.path+"/intersect",o).then((function(e){return(e.data.geometries||[]).map((function(e){return f.fromJSON(e).set({spatialReference:s})}))}))},t.prototype.labelPoints=function(e,t){var r=e.map((function(e){return e.toJSON()})),s=e[0].spatialReference,n=i({},this.parsedUrl.query,{f:"json",sr:s.wkid?s.wkid:JSON.stringify(s.toJSON()),polygons:JSON.stringify(r)}),o=this._asValidOptions(n,t);return a(this.parsedUrl.path+"/labelPoints",o).then((function(e){return(e.data.labelPoints||[]).map((function(e){return f.fromJSON(e).set({spatialReference:s})}))}))},t.prototype.lengths=function(e,t){e=U.from(e);var r=c.lengthsToRESTParameters(e),s=i({},this.parsedUrl.query,{f:"json"},r),n=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/lengths",n).then((function(e){return e.data}))},t.prototype.offset=function(e,t){e=S.from(e);var r=l.offsetToRESTParameters(e),s=i({},this.parsedUrl.query,{f:"json"},r),n=e.geometries[0].spatialReference,o=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/offset",o).then((function(e){return(e.data.geometries||[]).map((function(e){return f.fromJSON(e).set({spatialReference:n})}))}))},t.prototype.project=function(e,t){var r=this;e=R(e);var s=i({},this.parsedUrl.query,{f:"json"},e.toJSON()),n=e.outSpatialReference,o=f.getJsonType(e.geometries[0]),p=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/project",p).then((function(e){var t=e.data;return r._decodeGeometries(t,o,n)}))},t.prototype.relation=function(e,t){e=y.from(e);var r=I.relationToRESTParameters(e),s=i({},this.parsedUrl.query,{f:"json"},r),n=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/relation",n).then((function(e){return e.data.relations}))},t.prototype.reshape=function(e,t,r){var s=e.spatialReference,n=i({},this.parsedUrl.query,{f:"json",sr:JSON.stringify(s.toJSON()),target:JSON.stringify({geometryType:f.getJsonType(e),geometry:e.toJSON()}),reshaper:JSON.stringify(t.toJSON())}),o=this._asValidOptions(n,r);return a(this.parsedUrl.path+"/reshape",o).then((function(e){var t=e.data;return f.fromJSON(t.geometry).set({spatialReference:s})}))},t.prototype.simplify=function(e,t){var r=this,s=e[0].spatialReference,n=i({},this.parsedUrl.query,{f:"json",sr:s.wkid?s.wkid:JSON.stringify(s.toJSON()),geometries:JSON.stringify(this._encodeGeometries(e))}),o=f.getJsonType(e[0]),p=this._asValidOptions(n,t);return a(this.parsedUrl.path+"/simplify",p).then((function(e){var t=e.data;return r._decodeGeometries(t,o,s)}))},t.prototype.toGeoCoordinateString=function(e,t){var r={};null!=e.sr&&"object"==typeof e.sr?r.sr=e.sr.wkid||JSON.stringify(e.sr):r.sr=e.sr,r.coordinates=JSON.stringify(e.coordinates);var s=e.conversionType||"mgrs";r.conversionType=g.toJSON(s),r.conversionMode=e.conversionMode,r.numOfDigits=e.numOfDigits,r.rounding=e.rounding,r.addSpaces=e.addSpaces;var n=i({},this.parsedUrl.query,{f:"json"},r),o=this._asValidOptions(n,t);return a(this.parsedUrl.path+"/toGeoCoordinateString",o).then((function(e){return e.data.strings}))},t.prototype.trimExtend=function(e,t){e=m.from(e);var r=d.trimExtendToRESTParameters(e),s=i({},this.parsedUrl.query,{f:"json"},r),n=e.sr,p=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/trimExtend",p).then((function(e){return(e.data.geometries||[]).map((function(e){var t=e.paths;return new o.Polyline({spatialReference:n,paths:t})}))}))},t.prototype.union=function(e,t){var r=e[0].spatialReference,s=i({},this.parsedUrl.query,{f:"json",sr:JSON.stringify(r.toJSON()),geometries:JSON.stringify(this._encodeGeometries(e))}),n=this._asValidOptions(s,t);return a(this.parsedUrl.path+"/union",n).then((function(e){var t=e.data;return f.fromJSON(t.geometry).set({spatialReference:r})}))},t.prototype._asValidOptions=function(e,t){var r={query:e};return(this.requestOptions||t)&&(r=i({},this.requestOptions,t,r)),r},t.prototype._encodeGeometries=function(e){for(var t=[],r=e.length,s=0;s<r;s++)t.push(e[s].toJSON());return{geometryType:f.getJsonType(e[0]),geometries:t}},t.prototype._decodeGeometries=function(e,t,r){var s=f.getGeometryType(t),n=e.geometries,o=[],a={spatialReference:r.toJSON()};return n.forEach((function(e,t){o[t]=new s(i({},e,a))})),o},t.prototype._toProjectGeometry=function(e){var t=e.spatialReference.toJSON();return e instanceof o.Extent?new o.Polygon({rings:[[[e.xmin,e.ymin],[e.xmin,e.ymax],[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin]]],spatialReference:t}):new o.Polyline({paths:[[].concat(e.points)],spatialReference:t})},t.prototype._fromProjectedGeometry=function(e,t,r){if("extent"===t){var s=e.rings[0];return new o.Extent(s[0][0],s[0][1],s[2][0],s[2][1],r)}return new o.Multipoint({points:e.paths[0],spatialReference:r.toJSON()})},t.UNIT_METER=9001,t.UNIT_GERMAN_METER=9031,t.UNIT_FOOT=9002,t.UNIT_SURVEY_FOOT=9003,t.UNIT_CLARKE_FOOT=9005,t.UNIT_FATHOM=9014,t.UNIT_NAUTICAL_MILE=9030,t.UNIT_SURVEY_CHAIN=9033,t.UNIT_SURVEY_LINK=9034,t.UNIT_SURVEY_MILE=9035,t.UNIT_KILOMETER=9036,t.UNIT_CLARKE_YARD=9037,t.UNIT_CLARKE_CHAIN=9038,t.UNIT_CLARKE_LINK=9039,t.UNIT_SEARS_YARD=9040,t.UNIT_SEARS_FOOT=9041,t.UNIT_SEARS_CHAIN=9042,t.UNIT_SEARS_LINK=9043,t.UNIT_BENOIT_1895A_YARD=9050,t.UNIT_BENOIT_1895A_FOOT=9051,t.UNIT_BENOIT_1895A_CHAIN=9052,t.UNIT_BENOIT_1895A_LINK=9053,t.UNIT_BENOIT_1895B_YARD=9060,t.UNIT_BENOIT_1895B_FOOT=9061,t.UNIT_BENOIT_1895B_CHAIN=9062,t.UNIT_BENOIT_1895B_LINK=9063,t.UNIT_INDIAN_FOOT=9080,t.UNIT_INDIAN_1937_FOOT=9081,t.UNIT_INDIAN_1962_FOOT=9082,t.UNIT_INDIAN_1975_FOOT=9083,t.UNIT_INDIAN_YARD=9084,t.UNIT_INDIAN_1937_YARD=9085,t.UNIT_INDIAN_1962_YARD=9086,t.UNIT_INDIAN_1975_YARD=9087,t.UNIT_FOOT_1865=9070,t.UNIT_RADIAN=9101,t.UNIT_DEGREE=9102,t.UNIT_ARCMINUTE=9103,t.UNIT_ARCSECOND=9104,t.UNIT_GRAD=9105,t.UNIT_GON=9106,t.UNIT_MICRORADIAN=9109,t.UNIT_ARCMINUTE_CENTESIMAL=9112,t.UNIT_ARCSECOND_CENTESIMAL=9113,t.UNIT_MIL6400=9114,t.UNIT_BRITISH_1936_FOOT=9095,t.UNIT_GOLDCOAST_FOOT=9094,t.UNIT_INTERNATIONAL_CHAIN=109003,t.UNIT_INTERNATIONAL_LINK=109004,t.UNIT_INTERNATIONAL_YARD=109001,t.UNIT_STATUTE_MILE=9093,t.UNIT_SURVEY_YARD=109002,t.UNIT_50KILOMETER_LENGTH=109030,t.UNIT_150KILOMETER_LENGTH=109031,t.UNIT_DECIMETER=109005,t.UNIT_CENTIMETER=109006,t.UNIT_MILLIMETER=109007,t.UNIT_INTERNATIONAL_INCH=109008,t.UNIT_US_SURVEY_INCH=109009,t.UNIT_INTERNATIONAL_ROD=109010,t.UNIT_US_SURVEY_ROD=109011,t.UNIT_US_NAUTICAL_MILE=109012,t.UNIT_UK_NAUTICAL_MILE=109013,t.UNIT_SQUARE_INCHES="esriSquareInches",t.UNIT_SQUARE_FEET="esriSquareFeet",t.UNIT_SQUARE_YARDS="esriSquareYards",t.UNIT_ACRES="esriAcres",t.UNIT_SQUARE_MILES="esriSquareMiles",t.UNIT_SQUARE_MILLIMETERS="esriSquareMillimeters",t.UNIT_SQUARE_CENTIMETERS="esriSquareCentimeters",t.UNIT_SQUARE_DECIMETERS="esriSquareDecimeters",t.UNIT_SQUARE_METERS="esriSquareMeters",t.UNIT_ARES="esriAres",t.UNIT_HECTARES="esriHectares",t.UNIT_SQUARE_KILOMETERS="esriSquareKilometers",s([N.property()],t.prototype,"url",void 0),t=s([N.subclass("esri.tasks.GeometryService")],t)}(N.declared(_))}));