From 827a328cbddf5ef1c7cff553f91e067b5633ab45 Mon Sep 17 00:00:00 2001 From: Gavin Rehkemper Date: Thu, 23 Jul 2020 15:17:38 -0500 Subject: [PATCH 1/2] test for dynamiclayer proxy f:image --- spec/Layers/DynamicMapLayerSpec.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/Layers/DynamicMapLayerSpec.js b/spec/Layers/DynamicMapLayerSpec.js index 53f6d6d08..bc4570d32 100644 --- a/spec/Layers/DynamicMapLayerSpec.js +++ b/spec/Layers/DynamicMapLayerSpec.js @@ -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 })); @@ -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, From 970578bb303b75acdd43c7d259aed67f8cd454d2 Mon Sep 17 00:00:00 2001 From: Gavin Rehkemper Date: Fri, 24 Jul 2020 14:36:13 -0500 Subject: [PATCH 2/2] support proxy in dynamicmaplayer --- src/Layers/DynamicMapLayer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Layers/DynamicMapLayer.js b/src/Layers/DynamicMapLayer.js index 9ccb4f715..128af59c6 100644 --- a/src/Layers/DynamicMapLayer.js +++ b/src/Layers/DynamicMapLayer.js @@ -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); }, @@ -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); } } });