Skip to content
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

Fix issue with image placement when maps show multiple Earths #1033

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/components/wms/AnimatedRasterLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { nextTick, onMounted, onUnmounted, watch } from 'vue'
import { toMercator } from '@turf/projection'
import {
ImageSource,
LngLat,
LngLatBounds,
MapLayerMouseEvent,
MapLayerTouchEvent,
Expand Down Expand Up @@ -113,8 +114,18 @@ function getImageSourceOptions(): any {
return {}
const baseUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
const time = props.layer.time.toISOString()
const bounds = map.getBounds()
const canvas = map.getCanvas()
let bounds = map.getBounds()
let { width, height } = map.getCanvas()

// Check if we have a multiple Earths on the map
// Then reduce the bounds and image width to contain only one Earth
if (bounds.getEast() - bounds.getWest() > 360) {
width = (width * 360) / (bounds.getEast() - bounds.getWest())
bounds = new LngLatBounds(
new LngLat(-180, bounds.getSouth()),
new LngLat(180, bounds.getNorth()),
)
}

const getMapUrl = new URL(`${baseUrl}/wms`)
getMapUrl.searchParams.append('service', 'WMS')
Expand All @@ -123,8 +134,9 @@ function getImageSourceOptions(): any {
getMapUrl.searchParams.append('layers', props.layer.name)
getMapUrl.searchParams.append('crs', 'EPSG:3857')
getMapUrl.searchParams.append('bbox', `${getMercatorBboxFromBounds(bounds)}`)
getMapUrl.searchParams.append('height', `${canvas.height}`)
getMapUrl.searchParams.append('width', `${canvas.width}`)
// Width and height are in pixels, this can cause the image can be distorted a bit relicative to the bbox coordinates
getMapUrl.searchParams.append('height', `${height.toFixed(0)}`)
getMapUrl.searchParams.append('width', `${width.toFixed(0)}`)
getMapUrl.searchParams.append('time', `${time}`)
if (props.layer.style) {
getMapUrl.searchParams.append('styles', props.layer.style)
Expand Down
Loading