Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: error on missing zoom or center #308

Merged
merged 15 commits into from
Apr 18, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ export type {
} from './use-map-events';

export type MapCameraProps = {
center: google.maps.LatLngLiteral;
zoom: number;
heading?: number;
tilt?: number;
};
} & (
| {center: google.maps.LatLngLiteral}
| {defaultCenter: google.maps.LatLngLiteral}
) &
({zoom: number} | {defaultZoom: number});

/**
* Props for the Google Maps Map Component
*/
export type MapProps = google.maps.MapOptions &
MapEventProps &
MapCameraProps &
Copy link
Contributor Author

@maciej-ka maciej-ka Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like inclusion of MapCameraProps is missing? Without it zoom and center are not a Map property.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zoom and center are defined in google.maps.MapOptions so they haven't been repeated here.

MapCameraProps isn't included since it is intended to be used together with the MapCameraChangedEvent (it's a type you can use for the details of that event), see here for example:

const [cameraState, setCameraState] =
useState<MapCameraProps>(INITIAL_CAMERA_STATE);
// we only want to receive cameraChanged events from the map the
// user is interacting with:
const [activeMap, setActiveMap] = useState(1);
const handleCameraChange = useCallback((ev: MapCameraChangedEvent) => {
setCameraState(ev.detail);
}, []);

Maybe it should be renamed to MapCameraState to avoid confusion with the props?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I would add that rename.

DeckGlCompatProps & {
/**
* An id for the map, this is required when multiple maps are present
Expand All @@ -67,8 +70,6 @@ export type MapProps = google.maps.MapOptions &
*/
controlled?: boolean;

defaultCenter?: google.maps.LatLngLiteral;
defaultZoom?: number;
defaultHeading?: number;
defaultTilt?: number;
/**
Expand Down