I was able to fix this with a workaround. I think the issue was that the labels were being added irrespective to selected floor using the experimental add all.
However, it seems like a significant step backwards to have to do something like the below to get this working correctly.
const useFloorLabels = () => {
const { mapView, mapData } = useMap();
const showLabelsForCurrentFloor = useCallback(async () => {
const currentFloor = mapView.currentFloor;
mapView.Labels?.removeAll?.();
const allEnterpriseLocations = mapData.getByType?.('enterprise-location') || [];
for (const enterpriseLocation of allEnterpriseLocations) {
const floorSpace = enterpriseLocation.spaces
.map(space => typeof space === 'string'
? mapData.getById?.('space', space)
: space)
.find(space => {
const spaceFloor = space?.map || space?.floor;
return spaceFloor?.id === currentFloor.id;
});
if (floorSpace && enterpriseLocation.name) {
mapView.Labels?.add?.(floorSpace, enterpriseLocation.name, {
interactive: true
});
}
}
}, [mapView, mapData]);
return { showLabelsForCurrentFloor };
};
whereas in v5 it was simply
await mapView.current?.FloatingLabels.labelAllLocations();
Similarly, when trying to handle map clicks and extract location data from the click we previously could simply do:
locationName = polygons[0].locations[0].name;
mappedinLocationId = polygons[0].locations[0].id;
to access location info since the click event contained those polygons/locations.
Now, we need to loop through all enterprise locations and see if the space id included in the new click event payload is within the spaces array of a certain enterprise location. It’s very verbose and doesn’t seem to work well at all using this approach as some clicks fail to link up to the correct location.
useMapViewEvent(‘click’, async (payload) => {
const position = {latitude: payload.coordinate.latitude,
longitude: payload.coordinate.longitude
};
let location = null;
if (payload.spaces?.length > 0) {
const clickedSpace = payload.spaces[0];
const allEnterpriseLocations = mapData.getByType(‘enterprise-location’);
// Loop through ALL locations to find which contains this space
for (const enterpriseLocation of allEnterpriseLocations) {
const hasSpace = enterpriseLocation.spaces.some(space =>
(typeof space === 'string' ? space : space.id) === clickedSpace.id
);
if (hasSpace) {
location = enterpriseLocation;
break;
}
}
Are there plans to streamline these APIs or return to patterns from v5?
Thanks