Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import L from 'leaflet'
import { type GeoBounds } from '@Pimcore/components/geo-map/types/geo-types'
import { convertLatLngBoundsToGeoBounds } from '@Pimcore/components/geo-map/utils/lat-lng-convert'

export const addGeoBoundsToolbar = (leafletMap: L.Map, featureGroup: L.FeatureGroup, geoBounds?: GeoBounds, onChange?: (geoBounds: GeoBounds | undefined) => void, disabled?: boolean): void => {
leafletMap.addLayer(featureGroup)
Expand Down Expand Up @@ -55,18 +56,7 @@ export const addGeoBoundsToolbar = (leafletMap: L.Map, featureGroup: L.FeatureGr
featureGroup.addLayer(layer)
if (featureGroup.getLayers().length === 1) {
if (onChange !== undefined) {
const ne = layer.getBounds().getNorthEast()
const sw = layer.getBounds().getSouthWest()
onChange({
northEast: {
latitude: ne.lat,
longitude: ne.lng
},
southWest: {
latitude: sw.lat,
longitude: sw.lng
}
})
onChange(convertLatLngBoundsToGeoBounds(layer.getBounds()))
}
}
})
Expand All @@ -80,22 +70,10 @@ export const addGeoBoundsToolbar = (leafletMap: L.Map, featureGroup: L.FeatureGr
leafletMap.on(L.Draw.Event.EDITSTOP, function (e) {
for (const layerId in e.target._layers) {
if (Object.prototype.hasOwnProperty.call(e.target._layers, layerId) === true) {
const layer = e.target._layers[layerId]
const layer = e.target._layers[layerId] as L.Rectangle
if (Object.prototype.hasOwnProperty.call(layer, 'edited') === true) {
if (onChange !== undefined) {
const ne = layer._bounds._northEast
const sw = layer._bounds._southWest

onChange({
northEast: {
latitude: ne.lat,
longitude: ne.lng
},
southWest: {
latitude: sw.lat,
longitude: sw.lng
}
})
onChange(convertLatLngBoundsToGeoBounds(layer.getBounds()))
}
}
}
Expand Down
24 changes: 21 additions & 3 deletions assets/js/src/core/components/geo-map/utils/lat-lng-convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@
* @license Pimcore Open Core License (POCL)
*/

import type { GeoPoint, GeoPoints } from '@Pimcore/components/geo-map/types/geo-types'
import type { GeoBounds, GeoPoint, GeoPoints } from '@Pimcore/components/geo-map/types/geo-types'
import L from 'leaflet'

export const convertLatLngToGeoPoint = (latLng: L.LatLng): GeoPoint => {
// Normalize longitude to -180 to 180 range
let normalizedLongitude = latLng.lng
while (normalizedLongitude > 180) {
normalizedLongitude -= 360
}
while (normalizedLongitude < -180) {
normalizedLongitude += 360
}

// Normalize latitude to -90 to 90 range (clamp)
const normalizedLatitude = Math.max(-90, Math.min(90, latLng.lat))

return {
latitude: latLng.lat,
longitude: latLng.lng
latitude: normalizedLatitude,
longitude: normalizedLongitude
}
}
export const convertGeoPointToLatLng = (geoPoint: GeoPoint): L.LatLng => {
Expand All @@ -26,3 +38,9 @@ export const convertPolyLineToLatLngs = (polyLine: GeoPoints): L.LatLng[] => {
export const convertLatLngsToGeoPoints = (latlngs: L.LatLng[]): GeoPoint[] => {
return latlngs.map(convertLatLngToGeoPoint)
}
export const convertLatLngBoundsToGeoBounds = (bounds: L.LatLngBounds): GeoBounds => {
return {
northEast: convertLatLngToGeoPoint(bounds.getNorthEast()),
southWest: convertLatLngToGeoPoint(bounds.getSouthWest())
}
}
23 changes: 0 additions & 23 deletions public/build/0cddb035-0d14-423e-a211-2b461fe0bf6e/entrypoints.json

This file was deleted.

776 changes: 0 additions & 776 deletions public/build/0cddb035-0d14-423e-a211-2b461fe0bf6e/manifest.json

This file was deleted.

23 changes: 23 additions & 0 deletions public/build/cfa8aca3-9b18-4285-af8d-fef65da5eac9/entrypoints.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading