From d8d5b6020cd0c65c17e370b1026e4fe5e62351a6 Mon Sep 17 00:00:00 2001 From: stefano bovio Date: Thu, 14 Dec 2017 17:01:59 +0100 Subject: [PATCH] Added a float parser on leaflet bbox (#2483) --- web/client/components/map/leaflet/Map.jsx | 16 ++++++++-------- .../map/leaflet/__tests__/Map-test.jsx | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/web/client/components/map/leaflet/Map.jsx b/web/client/components/map/leaflet/Map.jsx index 7a50a05fd5..16a753c4c0 100644 --- a/web/client/components/map/leaflet/Map.jsx +++ b/web/client/components/map/leaflet/Map.jsx @@ -326,10 +326,10 @@ class LeafletMap extends React.Component { var center = this.map.getCenter(); this.props.onMapViewChanges({x: center.lng, y: center.lat, crs: "EPSG:4326"}, this.map.getZoom(), { bounds: { - minx: bbox[0], - miny: bbox[1], - maxx: bbox[2], - maxy: bbox[3] + minx: parseFloat(bbox[0]), + miny: parseFloat(bbox[1]), + maxx: parseFloat(bbox[2]), + maxy: parseFloat(bbox[3]) }, crs: 'EPSG:4326', rotation: 0 @@ -375,10 +375,10 @@ class LeafletMap extends React.Component { let bbox = new L.LatLngBounds(southWest, northEast).toBBoxString().split(','); return { bounds: { - minx: bbox[0], - miny: bbox[1], - maxx: bbox[2], - maxy: bbox[3] + minx: parseFloat(bbox[0]), + miny: parseFloat(bbox[1]), + maxx: parseFloat(bbox[2]), + maxy: parseFloat(bbox[3]) }, crs: 'EPSG:4326', rotation: 0 diff --git a/web/client/components/map/leaflet/__tests__/Map-test.jsx b/web/client/components/map/leaflet/__tests__/Map-test.jsx index 73fce47bc5..8d1781267b 100644 --- a/web/client/components/map/leaflet/__tests__/Map-test.jsx +++ b/web/client/components/map/leaflet/__tests__/Map-test.jsx @@ -11,6 +11,7 @@ var LeafletMap = require('../Map.jsx'); var LeafLetLayer = require('../Layer.jsx'); var expect = require('expect'); var mapUtils = require('../../../../utils/MapUtils'); +const {isNumber} = require('lodash'); require('leaflet-draw'); require('../../../../utils/leaflet/Layers'); @@ -223,10 +224,17 @@ describe('LeafletMap', () => { expect(bbox).toExist(); expect(mapBbox).toExist(); expect(bbox.bounds).toExist(); - expect(bbox.bounds.minx).toBe(mapBbox[0]); - expect(bbox.bounds.miny).toBe(mapBbox[1]); - expect(bbox.bounds.maxx).toBe(mapBbox[2]); - expect(bbox.bounds.maxy).toBe(mapBbox[3]); + + expect(isNumber(bbox.bounds.minx)).toBe(true); + expect(isNumber(bbox.bounds.miny)).toBe(true); + expect(isNumber(bbox.bounds.maxx)).toBe(true); + expect(isNumber(bbox.bounds.maxy)).toBe(true); + + expect(Math.round(bbox.bounds.minx)).toBe(Math.round(parseFloat(mapBbox[0]))); + expect(Math.round(bbox.bounds.miny)).toBe(Math.round(parseFloat(mapBbox[1]))); + expect(Math.round(bbox.bounds.maxx)).toBe(Math.round(parseFloat(mapBbox[2]))); + expect(Math.round(bbox.bounds.maxy)).toBe(Math.round(parseFloat(mapBbox[3]))); + expect(bbox.crs).toExist(); // in the case of leaflet the bounding box CRS should always be "EPSG:4326" and the roation 0 expect(bbox.crs).toBe("EPSG:4326");