-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update mapbounds logic #175
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Map as Maplibre } from 'maplibre-gl'; | ||
import { LngLatBounds, Map as Maplibre } from 'maplibre-gl'; | ||
import { DocumentLayerSpecification, MapLayerSpecification } from './mapLayerType'; | ||
import { DASHBOARDS_MAPS_LAYER_TYPE } from '../../common'; | ||
import { DASHBOARDS_MAPS_LAYER_TYPE, MAX_LONGITUDE, MIN_LONGITUDE } from '../../common'; | ||
import { | ||
buildOpenSearchQuery, | ||
Filter, | ||
|
@@ -22,16 +22,27 @@ interface MaplibreRef { | |
current: Maplibre | null; | ||
} | ||
|
||
// OpenSearch only accepts longitude in range [-180, 180] | ||
// Maplibre could return value out of the range | ||
function adjustLongitudeForSearch(lon: number) { | ||
if (lon < -180) { | ||
return -180; | ||
} | ||
if (lon > 180) { | ||
return 180; | ||
// calculate lng limits based on map bounds | ||
// maps can render more than 1 copies of map at lower zoom level and displays | ||
// one side from 1 copy and other side from other copy at higher zoom level if | ||
// screen crosses internation dateline | ||
function calculateBoundingBoxLngLimit(bounds: LngLatBounds) { | ||
const boundsMinLng = bounds.getNorthWest().lng; | ||
const boundsMaxLng = bounds.getSouthEast().lng; | ||
// if bounds expands more than 360 then, consider complete globe is visible | ||
if (boundsMaxLng - boundsMinLng >= MAX_LONGITUDE - MIN_LONGITUDE) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. SouthEast will always be greater than NorthWest in Maplibre since we are not wrapping. |
||
return { | ||
right: MAX_LONGITUDE, | ||
left: MIN_LONGITUDE, | ||
}; | ||
} | ||
return lon; | ||
// wrap bounds if only portion of globe is visible | ||
// wrap() returns a new LngLat object whose longitude is | ||
// wrapped to the range (-180, 180). | ||
return { | ||
right: bounds.getSouthEast().wrap().lng, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a question here, suppose the current map lng bounding is
The query would be
Is this what OpenSearch expecting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ruanyl Sorry, do you mean will OpenSearch accept similar to following query or not
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VijayanB I mean will OpenSearch return the same results as expected in the bounding box There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ruanyl Yes. |
||
left: bounds.getNorthWest().wrap().lng, | ||
}; | ||
} | ||
|
||
export const prepareDataLayerSource = ( | ||
|
@@ -112,13 +123,14 @@ export const handleDataLayerRender = ( | |
maplibreRef.current | ||
) { | ||
const mapBounds = maplibreRef.current.getBounds(); | ||
const lngLimit = calculateBoundingBoxLngLimit(mapBounds); | ||
const filterBoundingBox = { | ||
bottom_right: { | ||
lon: adjustLongitudeForSearch(mapBounds.getSouthEast().lng), | ||
lon: lngLimit.right, | ||
lat: mapBounds.getSouthEast().lat, | ||
}, | ||
top_left: { | ||
lon: adjustLongitudeForSearch(mapBounds.getNorthWest().lng), | ||
lon: lngLimit.left, | ||
lat: mapBounds.getNorthWest().lat, | ||
}, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement 👍