clean log
This commit is contained in:
parent
e9d28197df
commit
365d55d310
2 changed files with 0 additions and 133 deletions
|
|
@ -65,27 +65,10 @@ const zoomMap = ref<number>(18)
|
||||||
const textTooltip = ref<string>(
|
const textTooltip = ref<string>(
|
||||||
'พื้นที่ใกล้เคียงคือ สถานที่สำคัญรอบตัวคุณ (ไม่ใช่ตำแหน่งปัจจุบัน)'
|
'พื้นที่ใกล้เคียงคือ สถานที่สำคัญรอบตัวคุณ (ไม่ใช่ตำแหน่งปัจจุบัน)'
|
||||||
)
|
)
|
||||||
const MAP_DEBUG = true
|
|
||||||
let attachRetryTimer: number | undefined
|
let attachRetryTimer: number | undefined
|
||||||
let mapInitVersion = 0
|
let mapInitVersion = 0
|
||||||
let isRecoveryReinitializing = false
|
let isRecoveryReinitializing = false
|
||||||
|
|
||||||
function logMapDebug(event: string, payload?: Record<string, unknown>) {
|
|
||||||
if (!MAP_DEBUG) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const mode = $q.screen.gt.xs ? 'desktop' : 'mobile'
|
|
||||||
console.log('[AscGISMap]', event, {
|
|
||||||
mode,
|
|
||||||
isMapInitialized: isMapInitialized.value,
|
|
||||||
isInitializing: isInitializing.value,
|
|
||||||
hasMapView: !!mapView.value,
|
|
||||||
mapDestroyed: !!mapView.value?.destroyed,
|
|
||||||
...payload,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getActiveMapContainer() {
|
function getActiveMapContainer() {
|
||||||
return $q.screen.gt.xs
|
return $q.screen.gt.xs
|
||||||
? desktopMapContainerRef.value
|
? desktopMapContainerRef.value
|
||||||
|
|
@ -96,29 +79,14 @@ async function waitForActiveMapContainer(maxAttempts = 25, delayMs = 120) {
|
||||||
for (let i = 0; i < maxAttempts; i += 1) {
|
for (let i = 0; i < maxAttempts; i += 1) {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
const container = getActiveMapContainer()
|
const container = getActiveMapContainer()
|
||||||
if (i === 0 || i === maxAttempts - 1) {
|
|
||||||
logMapDebug('waitForContainer:attempt', {
|
|
||||||
attempt: i + 1,
|
|
||||||
maxAttempts,
|
|
||||||
width: container?.clientWidth || 0,
|
|
||||||
height: container?.clientHeight || 0,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (container && container.clientWidth > 0 && container.clientHeight > 0) {
|
if (container && container.clientWidth > 0 && container.clientHeight > 0) {
|
||||||
logMapDebug('waitForContainer:ready', {
|
|
||||||
attempt: i + 1,
|
|
||||||
width: container.clientWidth,
|
|
||||||
height: container.clientHeight,
|
|
||||||
})
|
|
||||||
return container
|
return container
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, delayMs))
|
await new Promise((resolve) => setTimeout(resolve, delayMs))
|
||||||
}
|
}
|
||||||
|
|
||||||
logMapDebug('waitForContainer:failed')
|
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,12 +99,10 @@ function clearAttachRetryTimer() {
|
||||||
|
|
||||||
async function recoverMapByReinitialize() {
|
async function recoverMapByReinitialize() {
|
||||||
if (isRecoveryReinitializing) {
|
if (isRecoveryReinitializing) {
|
||||||
logMapDebug('recover:skipAlreadyRunning')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isRecoveryReinitializing = true
|
isRecoveryReinitializing = true
|
||||||
logMapDebug('recover:start', { mapInitVersion })
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapInitVersion += 1
|
mapInitVersion += 1
|
||||||
|
|
@ -151,16 +117,13 @@ async function recoverMapByReinitialize() {
|
||||||
isMapInitialized.value = false
|
isMapInitialized.value = false
|
||||||
await nextTick()
|
await nextTick()
|
||||||
await initializeMap()
|
await initializeMap()
|
||||||
logMapDebug('recover:initializeMapCompleted', { mapInitVersion })
|
|
||||||
} finally {
|
} finally {
|
||||||
isRecoveryReinitializing = false
|
isRecoveryReinitializing = false
|
||||||
logMapDebug('recover:end', { mapInitVersion })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reattachAndResizeMap(retry = 0) {
|
function reattachAndResizeMap(retry = 0) {
|
||||||
if (!mapView.value || mapView.value.destroyed) {
|
if (!mapView.value || mapView.value.destroyed) {
|
||||||
logMapDebug('reattach:skipNoMapView', { retry })
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,18 +134,12 @@ function reattachAndResizeMap(retry = 0) {
|
||||||
activeContainer.clientWidth === 0 ||
|
activeContainer.clientWidth === 0 ||
|
||||||
activeContainer.clientHeight === 0
|
activeContainer.clientHeight === 0
|
||||||
) {
|
) {
|
||||||
logMapDebug('reattach:containerNotReady', {
|
|
||||||
retry,
|
|
||||||
width: activeContainer?.clientWidth || 0,
|
|
||||||
height: activeContainer?.clientHeight || 0,
|
|
||||||
})
|
|
||||||
if (retry < 15) {
|
if (retry < 15) {
|
||||||
clearAttachRetryTimer()
|
clearAttachRetryTimer()
|
||||||
attachRetryTimer = window.setTimeout(() => {
|
attachRetryTimer = window.setTimeout(() => {
|
||||||
reattachAndResizeMap(retry + 1)
|
reattachAndResizeMap(retry + 1)
|
||||||
}, 140)
|
}, 140)
|
||||||
} else if (!isRecoveryReinitializing) {
|
} else if (!isRecoveryReinitializing) {
|
||||||
logMapDebug('reattach:triggerRecovery')
|
|
||||||
void recoverMapByReinitialize()
|
void recoverMapByReinitialize()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -192,26 +149,14 @@ function reattachAndResizeMap(retry = 0) {
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (!mapView.value || mapView.value.destroyed) {
|
if (!mapView.value || mapView.value.destroyed) {
|
||||||
logMapDebug('reattach:skipDestroyedAfterTick', { retry })
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapView.value.container !== activeContainer) {
|
if (mapView.value.container !== activeContainer) {
|
||||||
logMapDebug('reattach:rebindContainer', {
|
|
||||||
width: activeContainer.clientWidth,
|
|
||||||
height: activeContainer.clientHeight,
|
|
||||||
})
|
|
||||||
mapView.value.container = null
|
mapView.value.container = null
|
||||||
mapView.value.container = activeContainer
|
mapView.value.container = activeContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
logMapDebug('reattach:resize', {
|
|
||||||
retry,
|
|
||||||
width: activeContainer.clientWidth,
|
|
||||||
height: activeContainer.clientHeight,
|
|
||||||
center: mapView.value.center,
|
|
||||||
zoom: mapView.value.zoom,
|
|
||||||
})
|
|
||||||
mapView.value.resize()
|
mapView.value.resize()
|
||||||
mapView.value.requestRender?.()
|
mapView.value.requestRender?.()
|
||||||
mapView.value
|
mapView.value
|
||||||
|
|
@ -230,12 +175,10 @@ function reattachAndResizeMap(retry = 0) {
|
||||||
|
|
||||||
async function initializeMap() {
|
async function initializeMap() {
|
||||||
if (isInitializing.value || (mapView.value && !mapView.value.destroyed)) {
|
if (isInitializing.value || (mapView.value && !mapView.value.destroyed)) {
|
||||||
logMapDebug('initialize:skipAlreadyRunningOrReady')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const initVersion = ++mapInitVersion
|
const initVersion = ++mapInitVersion
|
||||||
logMapDebug('initialize:start', { initVersion })
|
|
||||||
|
|
||||||
isInitializing.value = true
|
isInitializing.value = true
|
||||||
|
|
||||||
|
|
@ -250,7 +193,6 @@ async function initializeMap() {
|
||||||
'esri/Graphic',
|
'esri/Graphic',
|
||||||
'esri/layers/TileLayer',
|
'esri/layers/TileLayer',
|
||||||
])
|
])
|
||||||
logMapDebug('initialize:modulesLoaded', { initVersion })
|
|
||||||
// Set apiKey
|
// Set apiKey
|
||||||
// esriConfig.apiKey =
|
// esriConfig.apiKey =
|
||||||
// 'AAPK4f700a4324d04e9f8a1a134e0771ac45FXWawdCl-OotFfr52gz9XKxTDJTpDzw_YYcwbmKDDyAJswf14FoPyw0qBkN64DvP'
|
// 'AAPK4f700a4324d04e9f8a1a134e0771ac45FXWawdCl-OotFfr52gz9XKxTDJTpDzw_YYcwbmKDDyAJswf14FoPyw0qBkN64DvP'
|
||||||
|
|
@ -267,10 +209,6 @@ async function initializeMap() {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (initVersion !== mapInitVersion) {
|
if (initVersion !== mapInitVersion) {
|
||||||
logMapDebug('initialize:cancelledAfterMapCreated', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,37 +222,18 @@ async function initializeMap() {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (initVersion !== mapInitVersion) {
|
if (initVersion !== mapInitVersion) {
|
||||||
logMapDebug('initialize:cancelledAfterGeolocation', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { latitude, longitude } = position.coords
|
const { latitude, longitude } = position.coords
|
||||||
logMapDebug('initialize:geolocationSuccess', {
|
|
||||||
initVersion,
|
|
||||||
latitude,
|
|
||||||
longitude,
|
|
||||||
})
|
|
||||||
|
|
||||||
const mapContainer = await waitForActiveMapContainer()
|
const mapContainer = await waitForActiveMapContainer()
|
||||||
|
|
||||||
if (!mapContainer || initVersion !== mapInitVersion) {
|
if (!mapContainer || initVersion !== mapInitVersion) {
|
||||||
logMapDebug('initialize:containerUnavailableOrCancelled', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
})
|
|
||||||
isMapInitialized.value = false
|
isMapInitialized.value = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logMapDebug('initialize:containerReady', {
|
|
||||||
initVersion,
|
|
||||||
width: mapContainer.clientWidth,
|
|
||||||
height: mapContainer.clientHeight,
|
|
||||||
})
|
|
||||||
|
|
||||||
mapView.value = new MapView({
|
mapView.value = new MapView({
|
||||||
container: mapContainer,
|
container: mapContainer,
|
||||||
map: map,
|
map: map,
|
||||||
|
|
@ -336,13 +255,8 @@ async function initializeMap() {
|
||||||
})
|
})
|
||||||
|
|
||||||
await mapView.value.when()
|
await mapView.value.when()
|
||||||
logMapDebug('initialize:mapViewReady', { initVersion })
|
|
||||||
|
|
||||||
if (initVersion !== mapInitVersion) {
|
if (initVersion !== mapInitVersion) {
|
||||||
logMapDebug('initialize:cancelledAfterMapViewReady', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
})
|
|
||||||
if (mapView.value && !mapView.value.destroyed) {
|
if (mapView.value && !mapView.value.destroyed) {
|
||||||
mapView.value.destroy()
|
mapView.value.destroy()
|
||||||
}
|
}
|
||||||
|
|
@ -438,10 +352,6 @@ async function initializeMap() {
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (initVersion !== mapInitVersion || !mapView.value) {
|
if (initVersion !== mapInitVersion || !mapView.value) {
|
||||||
logMapDebug('initialize:poiIgnoredByVersionOrMap', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -473,25 +383,13 @@ async function initializeMap() {
|
||||||
})
|
})
|
||||||
|
|
||||||
updateLocation(latitude, longitude, poiPlaceName.value)
|
updateLocation(latitude, longitude, poiPlaceName.value)
|
||||||
logMapDebug('initialize:poiSuccess', {
|
|
||||||
initVersion,
|
|
||||||
poiPlaceName: poiPlaceName.value,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
if (initVersion !== mapInitVersion) {
|
if (initVersion !== mapInitVersion) {
|
||||||
logMapDebug('initialize:poiErrorIgnoredByVersion', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
poiPlaceName.value = poiPlaceName.value || 'ไม่พบข้อมูล'
|
poiPlaceName.value = poiPlaceName.value || 'ไม่พบข้อมูล'
|
||||||
updateLocation(latitude, longitude, poiPlaceName.value)
|
updateLocation(latitude, longitude, poiPlaceName.value)
|
||||||
logMapDebug('initialize:poiErrorFallback', {
|
|
||||||
initVersion,
|
|
||||||
poiPlaceName: poiPlaceName.value,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (initVersion === mapInitVersion) {
|
if (initVersion === mapInitVersion) {
|
||||||
|
|
@ -501,21 +399,11 @@ async function initializeMap() {
|
||||||
if (initVersion === mapInitVersion) {
|
if (initVersion === mapInitVersion) {
|
||||||
isMapInitialized.value = false
|
isMapInitialized.value = false
|
||||||
}
|
}
|
||||||
logMapDebug('initialize:error', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
error: error instanceof Error ? error.message : String(error),
|
|
||||||
})
|
|
||||||
console.error('Error loading the map', error)
|
console.error('Error loading the map', error)
|
||||||
} finally {
|
} finally {
|
||||||
if (initVersion === mapInitVersion) {
|
if (initVersion === mapInitVersion) {
|
||||||
isInitializing.value = false
|
isInitializing.value = false
|
||||||
}
|
}
|
||||||
logMapDebug('initialize:end', {
|
|
||||||
initVersion,
|
|
||||||
mapInitVersion,
|
|
||||||
isMapInitialized: isMapInitialized.value,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -609,7 +497,6 @@ const handleWindowResize = () => {
|
||||||
* Only call resize() if the map is fully initialized
|
* Only call resize() if the map is fully initialized
|
||||||
*/
|
*/
|
||||||
function handleMapResize() {
|
function handleMapResize() {
|
||||||
logMapDebug('handleMapResize:called')
|
|
||||||
if (mapView.value && !mapView.value.destroyed && isMapInitialized.value) {
|
if (mapView.value && !mapView.value.destroyed && isMapInitialized.value) {
|
||||||
// Use nextTick to ensure the DOM has finished updating before resizing
|
// Use nextTick to ensure the DOM has finished updating before resizing
|
||||||
reattachAndResizeMap()
|
reattachAndResizeMap()
|
||||||
|
|
@ -626,14 +513,9 @@ watch(
|
||||||
async (newValue) => {
|
async (newValue) => {
|
||||||
// Skip if no actual change (same layout)
|
// Skip if no actual change (same layout)
|
||||||
if (newValue === currentScreenSize.value) {
|
if (newValue === currentScreenSize.value) {
|
||||||
logMapDebug('screenWatch:skipNoChange', { newValue })
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logMapDebug('screenWatch:changed', {
|
|
||||||
oldValue: currentScreenSize.value,
|
|
||||||
newValue,
|
|
||||||
})
|
|
||||||
currentScreenSize.value = newValue
|
currentScreenSize.value = newValue
|
||||||
if (!newValue) {
|
if (!newValue) {
|
||||||
mobileMapExpanded.value = true
|
mobileMapExpanded.value = true
|
||||||
|
|
@ -645,7 +527,6 @@ watch(
|
||||||
// Always destroy and re-initialize when screen size changes
|
// Always destroy and re-initialize when screen size changes
|
||||||
// This ensures the map is attached to the correct container
|
// This ensures the map is attached to the correct container
|
||||||
if (mapView.value && !mapView.value.destroyed) {
|
if (mapView.value && !mapView.value.destroyed) {
|
||||||
logMapDebug('screenWatch:destroyMapView')
|
|
||||||
mapView.value.destroy()
|
mapView.value.destroy()
|
||||||
mapView.value = null
|
mapView.value = null
|
||||||
}
|
}
|
||||||
|
|
@ -662,15 +543,10 @@ watch(
|
||||||
await initializeMap()
|
await initializeMap()
|
||||||
|
|
||||||
if (!mapView.value || mapView.value.destroyed) {
|
if (!mapView.value || mapView.value.destroyed) {
|
||||||
logMapDebug('screenWatch:missingMapAfterInitialize, triggerRecovery')
|
|
||||||
await recoverMapByReinitialize()
|
await recoverMapByReinitialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
reattachAndResizeMap()
|
reattachAndResizeMap()
|
||||||
logMapDebug('screenWatch:reinitialized', {
|
|
||||||
hasMapViewAfterReinit: !!mapView.value,
|
|
||||||
mapDestroyedAfterReinit: !!mapView.value?.destroyed,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -687,28 +563,19 @@ watch(
|
||||||
|
|
||||||
// Set up resize event listener on mount
|
// Set up resize event listener on mount
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
logMapDebug('lifecycle:mounted')
|
|
||||||
window.addEventListener('resize', handleWindowResize)
|
window.addEventListener('resize', handleWindowResize)
|
||||||
|
|
||||||
// Component can be remounted after orientation/layout switches.
|
// Component can be remounted after orientation/layout switches.
|
||||||
// Recreate map automatically when consent is already granted.
|
// Recreate map automatically when consent is already granted.
|
||||||
if (privacyStore.isAccepted && (!mapView.value || mapView.value.destroyed)) {
|
if (privacyStore.isAccepted && (!mapView.value || mapView.value.destroyed)) {
|
||||||
logMapDebug('lifecycle:mounted:triggerInitialize')
|
|
||||||
await waitForActiveMapContainer(30, 100)
|
await waitForActiveMapContainer(30, 100)
|
||||||
await initializeMap()
|
await initializeMap()
|
||||||
reattachAndResizeMap()
|
reattachAndResizeMap()
|
||||||
} else {
|
|
||||||
logMapDebug('lifecycle:mounted:skipInitialize', {
|
|
||||||
privacyAccepted: privacyStore.isAccepted,
|
|
||||||
hasMapView: !!mapView.value,
|
|
||||||
mapDestroyed: !!mapView.value?.destroyed,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Cleanup map resources when component unmounts
|
// Cleanup map resources when component unmounts
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
logMapDebug('lifecycle:beforeUnmount')
|
|
||||||
clearAttachRetryTimer()
|
clearAttachRetryTimer()
|
||||||
|
|
||||||
if (mapView.value) {
|
if (mapView.value) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue