// Listen for location updates/additions if (data.data_type === 'location_update' && data.payload && data.payload.location) { const locationId = data.payload.location_id; const loc = data.payload.location; // Update locations dictionary with new data locations[locationId] = loc; // Remove old shape if exists if (locationShapes[locationId]) { map.removeLayer(locationShapes[locationId]); delete locationShapes[locationId]; } // Create new shape try { const shape = createLocationShape(locationId, loc); locationShapes[locationId] = shape; } catch (error) { console.error('[MAP] Error updating location shape:', error); } } // Listen for location removals if (data.data_type === 'location_remove' && data.payload && data.payload.location_id) { const locationId = data.payload.location_id; if (locationShapes[locationId]) { map.removeLayer(locationShapes[locationId]); delete locationShapes[locationId]; } }