From 9ea11bf2a372d5662dd7734e2448351c703c8cd0 Mon Sep 17 00:00:00 2001 From: john gravois Date: Tue, 31 Jan 2017 11:59:16 -0800 Subject: [PATCH 1/2] bindPopup should simplify output geometry slightly this patch applies a simplification factor of 0.5 to output geometries in bindPopup using the current scale of the map to ensure that no more vertices than necessary are retrieved from the server. for the test case provided by the user, this reduced the payload from 213kb/600ms to 922b/150ms without visible evidence on screen when zoomed out far on a complex feature --- spec/Layers/DynamicMapLayerSpec.js | 4 ++-- src/Layers/DynamicMapLayer.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/Layers/DynamicMapLayerSpec.js b/spec/Layers/DynamicMapLayerSpec.js index 2b50204c3..bac3b4611 100644 --- a/spec/Layers/DynamicMapLayerSpec.js +++ b/spec/Layers/DynamicMapLayerSpec.js @@ -374,7 +374,7 @@ describe('L.esri.DynamicMapLayer', function () { }); it('should bind a popup to the layer', function () { - server.respondWith('GET', new RegExp(/http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockMapService\/MapServer\/identify\?sr=4326&layers=visible&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&geometry=-?\d+\.\d+%2C-?\d+\.\d+&geometryType=esriGeometryPoint&f=json/), JSON.stringify(sampleResponse)); + server.respondWith('GET', new RegExp(/http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockMapService\/MapServer\/identify\?sr=4326&layers=visible&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&geometry=-?\d+\.\d+%2C-?\d+\.\d+&geometryType=esriGeometryPoint&maxAllowableOffset=0.000171661376953125&f=json/), JSON.stringify(sampleResponse)); layer.bindPopup(function (error, featureCollection) { return featureCollection.features.length + ' Feature(s)'; @@ -395,7 +395,7 @@ describe('L.esri.DynamicMapLayer', function () { }); it('should bind a popup to the layer if the layer is already on a map', function () { - server.respondWith('GET', new RegExp(/http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockMapService\/MapServer\/identify\?sr=4326&layers=visible&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&geometry=-?\d+\.\d+%2C-?\d+\.\d+&geometryType=esriGeometryPoint&f=json/), JSON.stringify(sampleResponse)); + server.respondWith('GET', new RegExp(/http:\/\/services.arcgis.com\/mock\/arcgis\/rest\/services\/MockMapService\/MapServer\/identify\?sr=4326&layers=visible&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+%2C-?\d+\.\d+&geometry=-?\d+\.\d+%2C-?\d+\.\d+&geometryType=esriGeometryPoint&maxAllowableOffset=0.000171661376953125&f=json/), JSON.stringify(sampleResponse)); layer.addTo(map); diff --git a/src/Layers/DynamicMapLayer.js b/src/Layers/DynamicMapLayer.js index 8deafff10..a039a4a3e 100644 --- a/src/Layers/DynamicMapLayer.js +++ b/src/Layers/DynamicMapLayer.js @@ -89,6 +89,9 @@ export var DynamicMapLayer = RasterLayer.extend({ var identifyRequest = this.identify().on(this._map).at(e.latlng); + // remove extraneous vertices from response features + identifyRequest.simplify(this._map, 0.5); + if (this.options.layers) { identifyRequest.layers('visible:' + this.options.layers.join(',')); } else { From e6a0aa02b8330f7e1d27e822e47b50d1464b5e5d Mon Sep 17 00:00:00 2001 From: john gravois Date: Tue, 31 Jan 2017 14:11:06 -0800 Subject: [PATCH 2/2] make sure 1 means more simplified --- src/Tasks/IdentifyFeatures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tasks/IdentifyFeatures.js b/src/Tasks/IdentifyFeatures.js index 22bd56440..7e4c59cf2 100644 --- a/src/Tasks/IdentifyFeatures.js +++ b/src/Tasks/IdentifyFeatures.js @@ -40,7 +40,7 @@ export var IdentifyFeatures = Identify.extend({ simplify: function (map, factor) { var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast()); - this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * (1 - factor); + this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * factor; return this; },