Skip to content

Commit

Permalink
Added a float parser on leaflet bbox (#2483)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored and mbarto committed Dec 14, 2017
1 parent f6e4163 commit d8d5b60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 8 additions & 8 deletions web/client/components/map/leaflet/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions web/client/components/map/leaflet/__tests__/Map-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit d8d5b60

Please sign in to comment.