Skip to content

Commit

Permalink
Merge pull request Esri#1220 from Esri/1184-dynamiclayer-proxy-image
Browse files Browse the repository at this point in the history
1184 dynamiclayer proxy image
  • Loading branch information
jwasilgeo authored Jul 24, 2020
2 parents 7faa408 + 970578b commit 7392bbc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 16 additions & 1 deletion spec/Layers/DynamicMapLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('L.esri.DynamicMapLayer', function () {

beforeEach(function () {
clock = sinon.useFakeTimers();
server = sinon.fakeServer.create();
server = sinon.fakeServer.create(); // { logger: console.log }
server.respondWith('GET', new RegExp(/http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockMapService\/MapServer\/export\?bbox=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&size=500%2C500&dpi=96&format=png32&transparent=true&bboxSR=3857&imageSR=3857&f=json/), JSON.stringify({
href: Image1
}));
Expand Down Expand Up @@ -410,6 +410,21 @@ describe('L.esri.DynamicMapLayer', 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\/MockMapService\/MapServer\/export\?bbox=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&size=500%2C500&dpi=96&format=png32&transparent=true&bboxSR=3857&imageSR=3857&f=json/), JSON.stringify({
imageData: base64Image,
contentType: 'image/png'
}));
layer = L.esri.dynamicMapLayer({
url: url,
f: 'image',
proxy: './proxy.ashx'
});
var spy = sinon.spy(layer, '_renderImage');
layer.addTo(map);
expect(spy.getCall(0).args[0]).to.match(new RegExp(/\.\/proxy.ashx\?http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockMapService\/MapServer\/export\?bbox=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&size=500%2C500&dpi=96&format=png32&transparent=true&bboxSR=3857&imageSR=3857&proxy=\.%2Fproxy.ashx&f=image/));
});

it('should be able to parse real base64 images from the export service', function (done) {
server.respondWith('GET', new RegExp(/http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockMapService\/MapServer\/export\?bbox=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&size=500%2C500&dpi=96&format=png32&transparent=true&bboxSR=3857&imageSR=3857&f=json/), JSON.stringify({
imageData: base64Image,
Expand Down
10 changes: 5 additions & 5 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.f !== 'json') {
options.f = 'json';
}

Util.setOptions(this, options);
},

Expand Down Expand Up @@ -193,7 +189,11 @@ export var DynamicMapLayer = RasterLayer.extend({
}, this);
} else {
params.f = 'image';
this._renderImage(this.options.url + 'export' + Util.getParamString(params), bounds);
var fullUrl = this.options.url + 'export' + Util.getParamString(params);
if (this.options.proxy) {
fullUrl = this.options.proxy + '?' + fullUrl;
}
this._renderImage(fullUrl, bounds);
}
}
});
Expand Down

0 comments on commit 7392bbc

Please sign in to comment.