有时候重写 DynamicMapServiceLayer后参数太多要用post请求:
改arcgis init.js源码:
搜索
"esri/layers/ArcGISDynamicMapServiceLayer" 这个关键key对应的类,因为是key value形式
找到方法getImageUrl
_jsonRequest是esri/request的别名
加{usePost: true}
getImageUrl: function (b, e, g, f) {
var k = this._url.path + "/export", q = this._params, r = q.token = this._getToken(),
p = b.spatialReference.wkid || m.toJson(b.spatialReference.toJson()),
t = this._errorHandler;
delete q._ts;
n.mixin(q, {
bbox: b.xmin + "," + b.ymin + "," + b.xmax + "," + b.ymax,
bboxSR: p,
imageSR: p,
size: e + "," + g
}, this.disableClientCaching ? {_ts: (new Date).getTime()} : {});
q.layerDefs && (b = d._serializeLayerDefinitions(q.layerDefs, 10.5 <= this.version), q = n.mixin({}, q), delete q.layerDefs, q.layerDefs = b);
b = a.addProxy(a.normalize(k) + "?" + l.objectToQuery(n.mixin({}, q, {f: "image"})));
/*
这是原方法,现在直接改为下面的post
b.length > h.defaults.io.postLength || this.useMapImage ? this._jsonRequest = c({
url: k, content: n.mixin(q, {f: "json"}), callbackParamName: "callback",
load: function (b) {
b.imageData ? b = "data:" + (b.contentType || "image") + ";base64," + b.imageData : (b = b.href, r && (b += -1 === b.indexOf("?") ? "?tokenx3d" + r : "x26tokenx3d" + r), b = a.addProxy(b));
f(b)
}, error: t
}) : f(b)
*/
this._jsonRequest = c({
url: k,
content: n.mixin(q, {f: "json"}),
callbackParamName: "callback",
load: function (b) {
b.imageData ? b = "data:" + (b.contentType || "image") + ";base64," + b.imageData : (b = b.href, r && (b += -1 === b.indexOf("?") ? "?tokenx3d" + r : "x26tokenx3d" + r), b = a.addProxy(b));
f(b)
},
error: t
}, {usePost: true});
this._jsonRequest.then(function(b){
b.imageData ? b = "data:" + (b.contentType || "image") + ";base64," + b.imageData : (b = b.href, r && (b += -1 === b.indexOf("?") ? "?tokenx3d" + r : "x26tokenx3d" + r), b = a.addProxy(b));
f(b)
},t);
}