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, 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); } } });