text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.6/esri/copyright.txt for details.
  //>>built
  define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/accessorSupport/decorators dojo/_base/lang ../core/Collection ../core/HandleRegistry ../core/promiseUtils ../core/CollectionFlattener ../core/accessorSupport/write ../geometry/Extent ../geometry/SpatialReference ../request ../Graphic ../PopupTemplate ./Layer ./mixins/OperationalLayer ./mixins/PortalLayer ./mixins/RefreshableLayer ./mixins/ScaleRangeLayer ./support/wmsUtils ./support/WMSSublayer ./support/ExportWMSImageParameters".split(" "),
  function(I,J,u,d,e,g,v,h,w,x,y,m,n,l,z,A,B,C,D,E,F,p,q,G){function H(e,b){return e.some(function(a){for(var f in a)if(y.willPropertyWrite(a,f,null,b))return!0;return!1})}function t(e,b,a){var f=[],c=new Map;e.forEach(function(e){var d=new q;d.read(e,b);a&&-1===a.indexOf(d.name)&&(d.visible=!1);c[d.id]=d;null!=e.parentLayerId&&-1!==e.parentLayerId?(e=c[e.parentLayerId],e.sublayers||(e.sublayers=[]),e.sublayers.unshift(d)):f.unshift(d)});return f}return function(r){function b(a,b){var c=r.call(this)||
  this;c._sublayersHandles=new h;c.allSublayers=new x({root:c,rootCollectionNames:["sublayers"],getChildrenFunction:function(a){return a.sublayers}});c.customParameters=null;c.customLayerParameters=null;c.copyright=null;c.description=null;c.fullExtent=null;c.fullExtents=null;c.featureInfoFormat=null;c.featureInfoUrl=null;c.imageFormat=null;c.imageMaxHeight=2048;c.imageMaxWidth=2048;c.imageTransparency=!0;c.legendEnabled=!0;c.mapUrl=null;c.operationalLayerType="WMS";c.spatialReference=null;c.spatialReferences=
  null;c.sublayers=null;c.type="wms";c.version=null;c.watch("sublayers",function(a,b){b&&(b.forEach(function(a){a.layer=null}),c._sublayersHandles.removeAll(),c._sublayersHandles=null);a&&(a.forEach(function(a){a.parent=c;a.layer=c}),c._sublayersHandles||(c._sublayersHandles=new h),c._sublayersHandles.add([a.on("after-add",function(a){a=a.item;a.parent=c;a.layer=c}),a.on("after-remove",function(a){a=a.item;a.parent=null;a.layer=null})]))},!0);return c}u(b,r);b.prototype.normalizeCtorArgs=function(a,
  b){return"string"===typeof a?g.mixin({url:a},b):a};b.prototype.load=function(){var a=this;this.addResolvingPromise(this.loadFromPortal({supportedTypes:["WMS"]}).then(function(){return a._fetchService()}));return this.when()};b.prototype.readFullExtentFromItemOrMap=function(a,b,c){a=b.extent;return(b=b.spatialReferences)&&0<b.length?new m({xmin:a[0][0],ymin:a[0][1],xmax:a[1][0],ymax:a[1][1],spatialReference:b[0]}):new m({xmin:a[0][0],ymin:a[0][1],xmax:a[1][0],ymax:a[1][1]})};b.prototype.writeFullExtent=
  function(a,b,c,e){b.extent=[[a.xmin,a.ymin],[a.xmax,a.ymax]]};b.prototype.readImageFormat=function(a,b){return(a=b.supportedImageFormatTypes)&&-1<a.indexOf("image/png")?"image/png":a&&a[0]};b.prototype.readSpatialReferenceFromItemOrDocument=function(a,b,c){return new n(b.spatialReferences[0])};b.prototype.writeSpatialReferences=function(a,b,c,e){var d=this.spatialReference&&this.spatialReference.wkid;a&&d?(b.spatialReferences=a.filter(function(a){return a!==d}),b.spatialReferences.unshift(d)):b.spatialReferences=
  a};b.prototype.readSublayersFromItemOrMap=function(a,b,c){return t(b.layers,c,b.visibleLayers)};b.prototype.readSublayers=function(a,b,c){return t(b.layers,c)};b.prototype.writeSublayers=function(a,b,c,e){b.layers=[];var d=new Map;a=a.flatten(function(a){return(a=a.sublayers)&&a.toArray()}).toArray();a.forEach(function(a){"number"===typeof a.parent.id&&(d.has(a.parent.id)?d.get(a.parent.id).push(a.id):d.set(a.parent.id,[a.id]))});a.forEach(function(a){var c=g.mixin({sublayer:a},e),f=a.write({parentLayerId:"number"===
  typeof a.parent.id?a.parent.id:-1},c);d.has(a.id)&&(f.sublayerIds=d.get(a.id));!a.sublayers&&a.name&&(a=a.write({},c),delete a.id,b.layers.push(a))});b.visibleLayers=a.filter(function(a){return a.visible&&!a.sublayers}).map(function(a){return a.name})};b.prototype.createExportImageParameters=function(a){this._exportWMSImageParameters=new G({layer:this,extent:a});return this._exportWMSImageParameters.toJSON()};b.prototype.fetchImage=function(a,b,c,d){var e=this.parsedUrl.path;a={responseType:"image",
  allowImageDataAccess:d&&d.allowImageDataAccess||!1,query:this._mixCustomParameters(g.mixin({width:b,height:c},this.createExportImageParameters(a)))};d&&d.timestamp&&(a.query=g.mixin({_ts:d.timestamp},a.query));return l(e,a).then(function(a){return a.data})};b.prototype.fetchFeatureInfo=function(a,b,c,d,e){var f=this,h=p.getPopupLayers(this._exportWMSImageParameters.visibleSublayers);if(!this.featureInfoUrl||!h)return null;b=g.mixin({query_layers:h,request:"GetFeatureInfo",info_format:this.featureInfoFormat,
  feature_count:25,width:b,height:c},"1.3.0"===this.version?{I:d,J:e}:{x:d,y:e});var k=g.mixin(this.createExportImageParameters(a),b),k=this._mixCustomParameters(k);return l(this.featureInfoUrl,{query:k,responseType:"text/html"}).then(function(a){var b=f.featureInfoUrl,b=b+(-1===b.indexOf("?")?"?":""),c;for(c in k)b+="?"===b.substring(b.length-1,b.length)?"":"\x26",b+=c+"\x3d"+k[c];return new z({popupTemplate:new A({title:f.title,content:'\x3ciframe src\x3d"'+b+'" frameborder\x3d"0" marginwidth\x3d"0" marginheight\x3d"0"\x3e'+
  a.data+"\x3cframe\x3e"})})})};b.prototype.findSublayerById=function(a){return this.allSublayers.find(function(b){return b.id===a})};b.prototype._fetchService=function(){var a=this;return w.resolve().then(function(){if(a.resourceInfo)return{ssl:!1,data:a.resourceInfo};a.parsedUrl.query&&a.parsedUrl.query.service&&(a.parsedUrl.query.SERVICE=a.parsedUrl.query.service,delete a.parsedUrl.query);a.parsedUrl.query&&a.parsedUrl.query.request&&(a.parsedUrl.query.REQUEST=a.parsedUrl.query.service,delete a.parsedUrl.query.request);
  return l(a.parsedUrl.path,{query:g.mixin({SERVICE:"WMS",REQUEST:"GetCapabilities"},a.parsedUrl.query,a.customParameters),responseType:"xml"})}).then(function(b){b.ssl&&(a.url=a.url.replace(/^http:/i,"https:"));a.resourceInfo||(b.data=p.parseCapabilities(b.data));b.data&&a.read(b.data,{origin:"service"})})};b.prototype._mixCustomParameters=function(a){if(!this.customLayerParameters&&!this.customParameters)return a;var b=g.mixin({},this.customParameters,this.customLayerParameters),c;for(c in b)a[c.toLowerCase()]=
  b[c];return a};d([e.shared({"2d":"../views/2d/layers/WMSLayerView2D","3d":"../views/3d/layers/WMSLayerView3D"})],b.prototype,"viewModulePaths",void 0);d([e.property({readOnly:!0})],b.prototype,"allSublayers",void 0);d([e.property({json:{write:!0}})],b.prototype,"customParameters",void 0);d([e.property({json:{write:!0}})],b.prototype,"customLayerParameters",void 0);d([e.property({type:String,json:{write:!0}})],b.prototype,"copyright",void 0);d([e.property()],b.prototype,"description",void 0);d([e.property({json:{origins:{service:{read:{source:"extent"}}}}})],
  b.prototype,"fullExtent",void 0);d([e.reader(["web-document","portal-item"],"fullExtent",["extent"])],b.prototype,"readFullExtentFromItemOrMap",null);d([e.writer(["web-document","portal-item"],"fullExtent")],b.prototype,"writeFullExtent",null);d([e.property()],b.prototype,"fullExtents",void 0);d([e.property({type:String,json:{write:{ignoreOrigin:!0}}})],b.prototype,"featureInfoFormat",void 0);d([e.property({type:String,json:{write:{ignoreOrigin:!0}}})],b.prototype,"featureInfoUrl",void 0);d([e.property({type:String,
  json:{origins:{"web-document":{read:{source:"format"},write:{target:"format"}}}}})],b.prototype,"imageFormat",void 0);d([e.reader("imageFormat",["supportedImageFormatTypes"])],b.prototype,"readImageFormat",null);d([e.property({type:Number,json:{read:{source:"maxHeight"},write:{target:"maxHeight"}}})],b.prototype,"imageMaxHeight",void 0);d([e.property({type:Number,json:{read:{source:"maxWidth"},write:{target:"maxWidth"}}})],b.prototype,"imageMaxWidth",void 0);d([e.property()],b.prototype,"imageTransparency",
  void 0);d([e.property({type:Boolean,json:{origins:{service:{read:{enabled:!1}}},read:{source:"showLegend"},write:{target:"showLegend"}}})],b.prototype,"legendEnabled",void 0);d([e.property({type:String,json:{write:{ignoreOrigin:!0}}})],b.prototype,"mapUrl",void 0);d([e.property()],b.prototype,"operationalLayerType",void 0);d([e.property({type:n,json:{origins:{service:{read:{source:"extent.spatialReference"}}},write:!1}})],b.prototype,"spatialReference",void 0);d([e.reader(["web-document","portal-item"],
  "spatialReference",["spatialReferences"])],b.prototype,"readSpatialReferenceFromItemOrDocument",null);d([e.property({type:[Number],json:{read:{source:"spatialReferences"},write:{ignoreOrigin:!0}}})],b.prototype,"spatialReferences",void 0);d([e.writer(["web-document","portal-item"],"spatialReferences")],b.prototype,"writeSpatialReferences",null);d([e.property({type:v.ofType(q),json:{write:{overridePolicy:function(a,b,c){if(H(this.allSublayers,c))return{ignoreOrigin:!0}}}}})],b.prototype,"sublayers",
  void 0);d([e.reader(["web-document","portal-item"],"sublayers",["layers","visibleLayers"])],b.prototype,"readSublayersFromItemOrMap",null);d([e.reader("service","sublayers",["layers"])],b.prototype,"readSublayers",null);d([e.writer("sublayers")],b.prototype,"writeSublayers",null);d([e.property({json:{read:!1},readOnly:!0,value:"wms"})],b.prototype,"type",void 0);d([e.property({type:String,json:{write:{ignoreOrigin:!0}}})],b.prototype,"version",void 0);return b=d([e.subclass("esri.layers.WMSLayer")],
  b)}(e.declared(B,C,D,E,F))});