Skip to content

Commit

Permalink
Merge pull request Esri#1221 from Esri/1184-imagelayer-proxy-image
Browse files Browse the repository at this point in the history
support proxy in imagemaplayer
  • Loading branch information
jwasilgeo authored Jul 24, 2020
2 parents 7392bbc + ca7092c commit d710985
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/Layers/ImageMapLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,26 @@ describe('L.esri.ImageMapLayer', function () {
expect(spy.getCall(0).args[0]).to.equal('./proxy.ashx?' + imageUrl);
});

it('should be able to request image using a proxy', function () {
server.respondWith('GET', new RegExp(/\/proxy.ashx\?http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockImageService\/ImageServer\/exportImage\?bbox=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&size=500%2C500&format=jpgpng&transparent=true&bboxSR=3857&imageSR=3857&f=image/), JSON.stringify({
imageData: Image1,
contentType: 'image/png'
}));

layer = L.esri.imageMapLayer({
url: url,
f: 'image',
proxy: './proxy.ashx'
});
server.respond();

var spy = sinon.spy(layer, '_renderImage');

layer.addTo(map);
server.respond();
expect(spy.getCall(0).args[0]).to.match(new RegExp(/\.\/proxy.ashx\?http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockImageService\/ImageServer\/exportImage\?bbox=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&size=500%2C500&format=jpgpng&transparent=true&bboxSR=3857&imageSR=3857&f=image/));
});

it('should pass a token if one is set', function (done) {
server.respondWith('GET', new RegExp(/http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockImageService\/ImageServer\/exportImage\?bbox=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&size=500%2C500&format=jpgpng&transparent=true&bboxSR=3857&imageSR=3857&token=foo&f=json/), JSON.stringify({
href: WithToken
Expand Down
6 changes: 5 additions & 1 deletion src/Layers/ImageMapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ export var ImageMapLayer = RasterLayer.extend({
}, this);
} else {
params.f = 'image';
this._renderImage(this.options.url + 'exportImage' + Util.getParamString(params), bounds);
var fullUrl = this.options.url + 'exportImage' + Util.getParamString(params);
if (this.options.proxy) {
fullUrl = this.options.proxy + '?' + fullUrl;
}
this._renderImage(fullUrl, bounds);
}
}
});
Expand Down

0 comments on commit d710985

Please sign in to comment.