Skip to content

Commit

Permalink
✨ remove params make map style
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannLai committed Jan 30, 2024
1 parent 229030d commit 060dc01
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions tools/showPoisOnMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,22 @@ function createShowPoisOnMap({
longitude: z.number(),
})),
zoom: z.number().optional(),
mapStyle: z.string().optional(),
})

const name = 'showPoisOnMap';
const description = `
Displays specific Points of Interest (POIs) on a map using the Mapbox Static API. Returns a URL to the map image.
pois: An array of POIs to be displayed on the map.
zoom: The zoom level for the map depends from the place size. For larger places use min value and for smaller use max. For countries use zoom '1.0'-'3.0'; for national parks, states use '4.0'-'6.0'; landmarks, places or cities use '7.0'-'9.0'. For streets use '15'. If multiple places are provided, this will automatically set to 'auto'.
mapStyle: The style of the map. Can be 'streets-v12', 'satellite-streets-v12', or 'outdoors-v12'. Default please set 'outdoors-v12'.
`

const execute = async ({ pois, zoom, mapStyle }: z.infer<typeof paramsSchema>) => {
const execute = async ({ pois, zoom }: z.infer<typeof paramsSchema>) => {
const accessToken = mapboxAccessToken;

if (!accessToken) {
throw new Error('Please set the Mapbox Access Token in the plugin settings.');
}

if (!mapStyle) {
mapStyle = 'outdoors-v12';
}

let markers;
let padding = "";
let formatZoom = zoom?.toString() || (pois.length == 1 ? '9' : 'auto'); // Use provided zoom level or default
Expand All @@ -51,7 +45,7 @@ function createShowPoisOnMap({
formatZoom = `${formatZoom},0`;
}
let coordinates = pois.length == 1 ? `${pois[0].longitude},${pois[0].latitude},${formatZoom}` : 'auto';
let url = `https://api.mapbox.com/styles/v1/mapbox/${mapStyle || 'streets-v12'}/static/${markers}/${coordinates}/600x400@2x?access_token=${accessToken}${padding}`;
let url = `https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/static/${markers}/${coordinates}/600x400@2x?access_token=${accessToken}${padding}`;

return { imageURL: url };
};
Expand Down

0 comments on commit 060dc01

Please sign in to comment.