Skip to content

Commit

Permalink
refactor: better consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
mrMetalWood committed Dec 9, 2024
1 parent 2fa0ab9 commit d1e9afa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/components/static-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export type StaticMapProps = {
export const StaticMap = async (props: StaticMapProps) => {
const {url} = props;

if (!url) {
return null;
}
if (!url) throw new Error('URL is required');

return <img src={url} width="100%" />;
};
11 changes: 6 additions & 5 deletions src/libraries/create-static-maps-url/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const STATIC_MAPS_BASE = 'https://maps.googleapis.com/maps/api/staticmap';
* @param {string} options.apiKey - Your Google Maps API key (required)
* @param {number} options.width - The width of the map image in pixels (required)
* @param {number} options.height - The height of the map image in pixels (required)
* @param {StaticMapsLocation} [options.center] - The center point of the map (lat/lng or address)
* @param {number} [options.zoom] - The zoom level of the map (0-21)
* @param {StaticMapsLocation} [options.center] - The center point of the map (lat/lng or address).
* Required if no markers or paths or "visible locations" are provided.
* @param {number} [options.zoom] - The zoom level of the map. Required if no markers or paths or "visible locations" are provided.
* @param {1|2|4} [options.scale] - The resolution of the map (1, 2, or 4)
* @param {string} [options.format] - The image format (png, png8, png32, gif, jpg, jpg-baseline)
* @param {string} [options.mapType] - The type of map (roadmap, satellite, terrain, hybrid)
Expand Down Expand Up @@ -84,7 +85,7 @@ export function createStaticMapsUrl({
mapType,
language,
region,
map_id,
mapId,
markers = [],
paths = [],
visible = [],
Expand All @@ -100,10 +101,10 @@ export function createStaticMapsUrl({
...(zoom && {zoom}),
...(scale && {scale}),
...(format && {format}),
...(mapType && {mapType}),
...(mapType && {maptype: mapType}),
...(language && {language}),
...(region && {region}),
...(map_id && {map_id})
...(mapId && {map_id: mapId})
};

const url = new URL(STATIC_MAPS_BASE);
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/create-static-maps-url/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type StaticMapsApiOptions = {
mapType?: google.maps.MapTypeId;
language?: string;
region?: string;
map_id?: string;
mapId?: string;
markers?: Array<StaticMapsMarker>;
paths?: Array<StaticMapsPath>;
visible?: Array<StaticMapsLocation>;
Expand Down

0 comments on commit d1e9afa

Please sign in to comment.