Azure / Azure/react-azure-maps

Map center property does not center the map camera within maxbounds

Open
#236 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
58
Forks
43
PR merge metrics
No merged PRs in 30d

Description

The map options **center property** and the **setCamera function** do not center map camera correctly. The camera gets positioned at the top or bottom of the boundary instead.

In both scenarios below the map camera is not centered.

**MapOptions**
```
const DefaultMap = (props) => {
const { mapRef, isMapReady } = useAzureMaps();
const option: IAzureMapOptions = {
authOptions: {
authType: AuthenticationType.anonymous,
clientId: '...',
getToken: (resolve, reject) => {...},
},
maxBounds: props.bounds,
center: props.center,
};

return (




)
}

export default DefaultMap;
```

**SetCamera**

```
const DefaultMap = (props) => {
const option: IAzureMapOptions = {
authOptions: {
authType: AuthenticationType.anonymous,
clientId: '...',
getToken: (resolve, reject) => {...},
},
};

useEffect(() => {
if(mapRef && isMapReady) {
mapRef.setCamera({
center: [props.lng, props.lat],
maxBounds: props.bounds,
});
}
}, [isMapReady, mapRef]);

return (




)
}

export default DefaultMap;
```

Also tried using `atlas.data.BoundingBox.getCenter(bounds)` which has the same result.

I have found a work around that involves setting the center value again after initial load but this is not ideal.

Would appreciate any help on this. Thanks in advance.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.