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);//釋放
}
}
});
});