// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define([],function(){function r(b){a:{var d=b[0];for(var a=0;a<d.length;a++)if(d[a]!==b[b.length-1][a]){d=!1;break a}d=!0}d||b.push(b[0]);return b}function t(b){var d=0,a=0,c=b.length,e=b[a];for(a;a<c-1;a++){var h=b[a+1];d+=(h[0]-e[0])*(h[1]+e[1]);e=h}return 0<=d}function v(b,d){for(var a=0;a<b.length-1;a++)for(var c=0;c<d.length-1;c++){a:{var e=b[a],h=b[a+1],f=d[c],k=d[c+1],m=(k[0]-f[0])*(e[1]-f[1])-(k[1]-f[1])*(e[0]-f[0]);var g=(h[0]-e[0])*(e[1]-f[1])-(h[1]-e[1])*(e[0]-f[0]);e=(k[1]-f[1])*(h[0]-
e[0])-(k[0]-f[0])*(h[1]-e[1]);if(0!==e&&(m/=e,g/=e,0<=m&&1>=m&&0<=g&&1>=g)){g=!0;break a}g=!1}if(g)return!0}return!1}function w(b){var d=[];b=b.slice(0);var a=r(b.shift().slice(0));if(4<=a.length)for(t(a)||a.reverse(),d.push(a),a=0;a<b.length;a++){var c=r(b[a].slice(0));4<=c.length&&(t(c)&&c.reverse(),d.push(c))}return d}function x(b){var d={},a;for(a in b)b.hasOwnProperty(a)&&(d[a]=b[a]);return d}var q={arcgisToGeoJSON:function(b,d){var a={};"number"===typeof b.x&&"number"===typeof b.y&&(a.type=
"Point",a.coordinates=[b.x,b.y]);b.points&&(a.type="MultiPoint",a.coordinates=b.points.slice(0));b.paths&&(1===b.paths.length?(a.type="LineString",a.coordinates=b.paths[0].slice(0)):(a.type="MultiLineString",a.coordinates=b.paths.slice(0)));if(b.rings){var c=b.rings.slice(0);a=[];var e=[],h,f;for(f=0;f<c.length;f++){var k=r(c[f].slice(0));4>k.length||(t(k)?a.push([k]):e.push(k))}for(k=[];e.length;){f=e.pop();var m=!1;for(c=a.length-1;0<=c;c--){var g=h=a[c][0],l=f;h=v(g,l);l=l[0];for(var u=!1,n=-1,
y=g.length,p=y-1;++n<y;p=n)(g[n][1]<=l[1]&&l[1]<g[p][1]||g[p][1]<=l[1]&&l[1]<g[n][1])&&l[0]<(g[p][0]-g[n][0])*(l[1]-g[n][1])/(g[p][1]-g[n][1])+g[n][0]&&(u=!u);g=u;if(!h&&g){a[c].push(f);m=!0;break}}m||k.push(f)}for(;k.length;){f=k.pop();e=!1;for(c=a.length-1;0<=c;c--)if(h=a[c][0],v(h,f)){a[c].push(f);e=!0;break}e||a.push([f.reverse()])}a=1===a.length?{type:"Polygon",coordinates:a[0]}:{type:"MultiPolygon",coordinates:a}}if(b.geometry||b.attributes)a.type="Feature",a.geometry=b.geometry?q.arcgisToGeoJSON(b.geometry):
null,a.properties=b.attributes?x(b.attributes):null,b.attributes&&(a.id=b.attributes[d]||b.attributes.OBJECTID||b.attributes.FID);return a},geojsonToArcGIS:function(b,d){d=d||"OBJECTID";var a={wkid:4326},c={};switch(b.type){case "Point":c.x=b.coordinates[0];c.y=b.coordinates[1];c.spatialReference=a;break;case "MultiPoint":c.points=b.coordinates.slice(0);c.spatialReference=a;break;case "LineString":c.paths=[b.coordinates.slice(0)];c.spatialReference=a;break;case "MultiLineString":c.paths=b.coordinates.slice(0);
c.spatialReference=a;break;case "Polygon":c.rings=w(b.coordinates.slice(0));c.spatialReference=a;break;case "MultiPolygon":d=c;b=b.coordinates.slice(0);for(var e=[],h=0;h<b.length;h++)for(var f=w(b[h]),k=f.length-1;0<=k;k--){var m=f[k].slice(0);e.push(m)}d.rings=e;c.spatialReference=a;break;case "Feature":b.geometry&&(c.geometry=q.geojsonToArcGIS(b.geometry,d));c.attributes=b.properties?x(b.properties):{};b.id&&(c.attributes[d]=b.id);break;case "FeatureCollection":c=[];for(a=0;a<b.features.length;a++)c.push(q.geojsonToArcGIS(b.features[a],
d));break;case "GeometryCollection":for(c=[],a=0;a<b.geometries.length;a++)c.push(q.geojsonToArcGIS(b.geometries[a],d))}return c}};return q});