Skip to content

Commit

Permalink
updated DynamicMapLayer and ImageMapLayer:
Browse files Browse the repository at this point in the history
- removed options.f conditional override during initialization of DynamicMapLayer (related to #1180);
- standardized usage of params.token and params.proxy in "_buildExportParams" and "_requestExport" of DynamicMapLayer  and ImageMapLayer;
- prepended optional params.proxy in "_requestExport" of DynamicMapLayer  and ImageMapLayer;
  • Loading branch information
jwasilgeo committed Jan 17, 2020
1 parent 8585509 commit 07c2ee5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
28 changes: 19 additions & 9 deletions src/Layers/DynamicMapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export var DynamicMapLayer = RasterLayer.extend({
this.service = mapService(options);
this.service.addEventParent(this);

if ((options.proxy || options.token) && options.f !== 'json') {
options.f = 'json';
}

Util.setOptions(this, options);
},

Expand Down Expand Up @@ -179,21 +175,35 @@ export var DynamicMapLayer = RasterLayer.extend({
this.service.request('export', params, function (error, response) {
if (error) { return; } // we really can't do anything here but authenticate or requesterror will fire

if (this.options.token && response.href) {
response.href += ('?token=' + this.options.token);
if (params.token && response.href) {
// append token
response.href += ('?token=' + params.token);
}
if (this.options.proxy && response.href) {
response.href = this.options.proxy + '?' + response.href;

if (params.proxy && response.href) {
// prepend proxy
response.href = params.proxy + '?' + response.href;
}

if (response.href) {
this._renderImage(response.href, bounds);
} else {
this._renderImage(response.imageData, bounds, response.contentType);
}
}, this);
} else {
// if not 'json', then 'image' is the only other valid value for params.f
// (this.options.f should be equal to 'image' if the default 'json' value was not used)
params.f = 'image';
this._renderImage(this.options.url + 'export' + Util.getParamString(params), bounds);

var url = this.options.url + 'export' + Util.getParamString(params);

if (params.proxy) {
// prepend proxy
url = params.proxy + '?' + url;
}

this._renderImage(url, bounds);
}
}
});
Expand Down
29 changes: 24 additions & 5 deletions src/Layers/ImageMapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ export var ImageMapLayer = RasterLayer.extend({
params.token = this.service.options.token;
}

if (this.options.proxy) {
params.proxy = this.options.proxy;
}

if (this.options.renderingRule) {
params.renderingRule = JSON.stringify(this.options.renderingRule);
}
Expand All @@ -180,17 +184,32 @@ export var ImageMapLayer = RasterLayer.extend({
if (this.options.f === 'json') {
this.service.request('exportImage', params, function (error, response) {
if (error) { return; } // we really can't do anything here but authenticate or requesterror will fire
if (this.options.token) {
response.href += ('?token=' + this.options.token);

if (params.token) {
// append token
response.href += ('?token=' + params.token);
}
if (this.options.proxy) {
response.href = this.options.proxy + '?' + response.href;

if (params.proxy) {
// prepend proxy
response.href = params.proxy + '?' + response.href;
}

this._renderImage(response.href, bounds);
}, this);
} else {
// if not 'json', then 'image' is the only other valid value for params.f
// (this.options.f should be equal to 'image' if the optional 'json' value was not used)
params.f = 'image';
this._renderImage(this.options.url + 'exportImage' + Util.getParamString(params), bounds);

var url = this.options.url + 'exportImage' + Util.getParamString(params);

if (params.proxy) {
// prepend proxy
url = params.proxy + '?' + url;
}

this._renderImage(url, bounds);
}
}
});
Expand Down

0 comments on commit 07c2ee5

Please sign in to comment.