define([
"dojo/_base/declare",
"dojo/_base/lang",
"esri/layers/DynamicMapServiceLayer",
"esri/geometry/Extent"
], function(
declare,
lang,
DynamicMapServiceLayer,
Extent
) {
return declare("DynamicMapSuperPost", DynamicMapServiceLayer, { // create DynamicMapLayer by extending esri.layers.TiledMapServiceLayer
constructor:function(){
this.spatialReference = new esri.SpatialReference({wkid:4490});
this.initialExtent = this.fullExtent = new Extent({"xmin":109.3868865977334,"ymin":29.938091498799054,"xmax":117.6127404019528,"ymax":37.81307950094276,"spatialReference": this.spatialReference});
this.loaded = true;
this.onLoad(this);
},
getImageUrl: function(extent, width, height, callback) {
var params = {
//request: "GetMap",
//transparent: true,
format: "png",//"image/png",
//bgcolor: "ffffff",
//version: "1.1.1",
layers: 'id1,id2,id3,id4',
//styles: "default,default",
//exceptions: "application/vnd.ogc.se_xml",
//changing values
bbox: extent.xmin + "," + extent.ymin + "," + extent.xmax + "," + extent.ymax,
//bbox:'113.68330445912024,34.75990865047065,113.71526537935056,34.77527045072429',
MAPID: 110,
//GRAY:0,
//LAYERHIDEOID:'`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^',
//LAYERHIDEOID:'`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^',
//srs: "EPSG:" + extent.spatialReference.wkid,
width: width,
height: height
};
var curParams = dojo.objectToQuery(params);
var _self = this;
var curentImgId = this._img_loading.id;
//这个地方是使用了servlet返回动态层的png图片,原因是有些动态层是定制的,要符合他们要求
var url = '../proxy';
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.open('POST', url, true);//POST请求,请求地址,是否异步
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
xhr.onload = function (ev) {
if (this.status == 200) {
var data = this.response;
var blob = new Blob();
blob = data;
var blobImage = window.URL.createObjectURL(blob);
if (_self._img_loading && _self._img_loading.id == curentImgId) {
callback(blobImage);
} else {//缩放或移动中img被arcgis删除了,丢失dom节点
window.URL.revokeObjectURL(blobImage);//释放
}
}
}
xhr.send(curParams);
},
_imgSrcFunc: function (a) {
this._img_loading.src = a
this._img_loading.onload = function () {
window.URL.revokeObjectURL(this.src);//释放
}
}
});
});