Skip to content

Commit

Permalink
more review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Feb 25, 2020
1 parent 7a0ffa8 commit 79b5a3a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import sprites1 from '@elastic/maki/dist/sprite@1.png';
import sprites2 from '@elastic/maki/dist/sprite@2.png';
import { DrawControl } from './draw_control';
import { TooltipControl } from './tooltip_control';
import { clampToLatBounds, clampToLonBounds } from '../../../elasticsearch_geo_utils';

mapboxgl.workerUrl = mbWorkerUrl;
mapboxgl.setRTLTextPlugin(mbRtlPlugin);
Expand Down Expand Up @@ -234,12 +235,12 @@ export class MBMapContainer extends React.Component {
//clamping ot -89/89 latitudes since Mapboxgl does not seem to handle bounds that contain the poles (logs errors to the console when using -90/90)
const lnLatBounds = new mapboxgl.LngLatBounds(
new mapboxgl.LngLat(
clamp(goto.bounds.min_lon, -180, 180),
clamp(goto.bounds.min_lat, -89, 89)
clampToLonBounds(goto.bounds.min_lon),
clampToLatBounds(goto.bounds.min_lat)
),
new mapboxgl.LngLat(
clamp(goto.bounds.max_lon, -180, 180),
clamp(goto.bounds.max_lat, -89, 89)
clampToLonBounds(goto.bounds.max_lon),
clampToLatBounds(goto.bounds.max_lat)
)
);
//maxZoom ensure we're not zooming in too far on single points or small shapes
Expand Down Expand Up @@ -306,9 +307,3 @@ export class MBMapContainer extends React.Component {
);
}
}

function clamp(val, min, max) {
if (val > max) val = max;
else if (val < min) val = min;
return val;
}
18 changes: 18 additions & 0 deletions x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,21 @@ export function convertMapExtentToPolygon({ maxLat, maxLon, minLat, minLon }) {

return formatEnvelopeAsPolygon({ maxLat, maxLon, minLat, minLon });
}

export function clampToLatBounds(lat) {
return clamp(lat, -89, 89);
}

export function clampToLonBounds(lon) {
return clamp(lon, -180, 180);
}

export function clamp(val, min, max) {
if (val > max) {
return max;
} else if (val < min) {
return min;
} else {
return val;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import _ from 'lodash';
import { RENDER_AS } from './render_as';
import { getTileBoundingBox } from './geo_tile_utils';
import { extractPropertiesFromBucket } from '../../util/es_agg_utils';
import { clamp } from '../../../elasticsearch_geo_utils';

const GRID_BUCKET_KEYS_TO_IGNORE = ['key', 'gridCentroid'];

Expand Down Expand Up @@ -77,20 +78,14 @@ function rowToGeometry({ gridKey, gridCentroid, renderAs }) {
};
}

// see https://github.com/elastic/elasticsearch/issues/24694 for why clampGrid is used
// see https://github.com/elastic/elasticsearch/issues/24694 for why clamp is used
const pointCoordinates = [
clampGrid(gridCentroid.location.lon, left, right),
clampGrid(gridCentroid.location.lat, bottom, top),
clamp(gridCentroid.location.lon, left, right),
clamp(gridCentroid.location.lat, bottom, top),
];

return {
type: 'Point',
coordinates: pointCoordinates,
};
}

function clampGrid(val, min, max) {
if (val > max) val = max;
else if (val < min) val = min;
return val;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('../../../kibana_services', () => {});

import { convertCompositeRespToGeoJson, convertRegularRespToGeoJson } from './convert_to_geojson';
import { RENDER_AS } from './render_as';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import _ from 'lodash';
import { DECIMAL_DEGREES_PRECISION } from '../../../../common/constants';
import { clampToLatBounds } from '../../../elasticsearch_geo_utils';

const ZOOM_TILE_KEY_INDEX = 0;
const X_TILE_KEY_INDEX = 1;
Expand Down Expand Up @@ -87,13 +88,7 @@ function sec(value) {
}

function latitudeToTile(lat, tileCount) {
let boundedLat = lat;
if (lat >= 90) {
boundedLat = 89.9;
} else if (lat <= -90) {
boundedLat = -89.9;
}
const radians = (boundedLat * Math.PI) / 180;
const radians = (clampToLatBounds(lat) * Math.PI) / 180;
const y = ((1 - Math.log(Math.tan(radians) + sec(radians)) / Math.PI) / 2) * tileCount;
return Math.floor(y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('../../../kibana_services', () => {});

import { parseTileKey, getTileBoundingBox, expandToTileBoundaries } from './geo_tile_utils';

it('Should parse tile key', () => {
Expand Down

0 comments on commit 79b5a3a

Please sign in to comment.