Skip to content

Commit 3b63d86

Browse files
committed
Simplify component features, update examples.
1 parent 02f9938 commit 3b63d86

File tree

2 files changed

+14
-86
lines changed

2 files changed

+14
-86
lines changed

src/components/Map.astro

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,37 @@
11
---
2-
import type { HTMLAttributeReferrerPolicy } from 'react';
3-
42
interface Props {
53
location?: string;
6-
embedCode?: string;
7-
mapId?: string;
84
lat?: number;
95
lng?: number;
106
zoom?: number;
11-
mapType?: "roadmap" | "satellite" | "hybrid" | "terrain";
127
title?: string;
13-
loading?: "eager" | "lazy";
14-
referrerPolicy?: HTMLAttributeReferrerPolicy;
158
}
169
1710
const {
1811
location,
19-
embedCode,
20-
mapId,
2112
lat,
2213
lng,
2314
zoom = 14,
24-
mapType = "roadmap",
2515
title = "Map",
26-
loading = "lazy",
27-
referrerPolicy = "no-referrer-when-downgrade",
2816
} = Astro.props;
2917
30-
3118
let src = "";
32-
33-
if (embedCode) {
34-
const srcMatch = embedCode.match(/src="([^"]+)"/);
35-
src = srcMatch ? srcMatch[1] : "";
36-
}
37-
else if (lat && lng) {
38-
src = `https://maps.google.com/maps?q=${lat},${lng}&z=${zoom}&t=${
39-
mapType === "satellite" ? "k" :
40-
mapType === "hybrid" ? "h" :
41-
mapType === "terrain" ? "p" : "m"
42-
}&output=embed`;
43-
}
44-
45-
else if (mapId) {
46-
src = `https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3000!2d-73.9857!3d40.7484!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s${mapId}!2s!5e0!3m2!1sen!2sus!4v1684164357244!5m2!1sen!2sus`;
19+
if (lat && lng) {
20+
src = `https://maps.google.com/maps?q=${lat},${lng}&z=${zoom}&t=m&output=embed`;
4721
}
4822
else if (location) {
49-
src = `https://maps.google.com/maps?q=${encodeURIComponent(location)}&t=${
50-
mapType === "satellite" ? "k" :
51-
mapType === "hybrid" ? "h" :
52-
mapType === "terrain" ? "p" : "m"
53-
}&z=${zoom}&output=embed&iwloc=near`;
23+
src = `https://maps.google.com/maps?q=${encodeURIComponent(location)}&t=m&z=${zoom}&output=embed&iwloc=near`;
5424
}
5525
---
56-
57-
<div class="astro-map-container w-full aspect-video max-w-[800px] border-4 border-white rounded-lg shadow-lg">
26+
<div class="map-container w-full aspect-video max-w-[800px] border-4 border-white rounded-lg shadow-lg">
5827
{src && (
5928
<iframe
6029
src={src}
6130
title={title}
6231
class="w-full aspect-video"
6332
allowfullscreen={true}
64-
loading={loading}
65-
referrerpolicy={referrerPolicy}
33+
loading="lazy"
34+
referrerpolicy="no-referrer-when-downgrade"
6635
style="border:0;"
6736
></iframe>
6837
)}

src/content/pages/test.mdx

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -283,79 +283,38 @@ Barking up the right tree
283283
</Accordion>
284284

285285
## Maps
286-
287286
<h2>Example 1: Map with Location</h2>
288287
<Map
289288
location="Empire State Building, New York"
290289
zoom={15}
291290
/>
292291

293-
<h2>Example 2: Map with Location and Custom Map Type</h2>
294-
<Map
295-
location="Grand Canyon, Arizona"
296-
mapType="satellite"
297-
zoom={12}
298-
/>
299-
300-
<h2>Example 3: Map with Coordinates (Latitude & Longitude)</h2>
292+
<h2>Example 2: Map with Coordinates (Latitude & Longitude)</h2>
301293
<Map
302294
lat={48.8584}
303295
lng={2.2945}
304296
zoom={16}
305297
title="Eiffel Tower, Paris"
306298
/>
307299

308-
<h2>Example 4: Map with Coordinates and Terrain Map Type</h2>
309-
<Map
310-
lat={36.1069}
311-
lng={-112.1129}
312-
mapType="terrain"
313-
zoom={13}
314-
title="Grand Canyon"
315-
/>
316-
317-
<h2>Example 5: Map with Hybrid Map Type</h2>
300+
<h2>Example 3: Map with Default Zoom Level</h2>
318301
<Map
319302
location="Sydney Opera House"
320-
mapType="hybrid"
321-
zoom={17}
322303
/>
323304

324-
<h2>Example 6: Map with Map ID</h2>
305+
<h2>Example 4: Map with Custom Title</h2>
325306
<Map
326-
mapId="0x89c259a944867e5b:0xb2c96748fa5e9cf"
327-
title="Central Park, New York"
328-
/>
329-
330-
<h2>Example 7: Map with Embed Code from Google Maps</h2>
331-
<Map
332-
embedCode='<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2624.9916256937586!2d2.2922926156740954!3d48.858370079287475!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47e66e2964e34e2d%3A0x8ddca9ee380ef7e0!2sEiffel%20Tower!5e0!3m2!1sen!2sus!4v1621536319249!5m2!1sen!2sus" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy"></iframe>'
333-
title="Eiffel Tower Embed"
334-
/>
335-
336-
<h2>Example 8: Map with Loading Performance Options</h2>
337-
<Map
338-
location="Golden Gate Bridge, San Francisco"
339-
loading="eager"
340-
referrerPolicy="strict-origin"
307+
lat={36.1069}
308+
lng={-112.1129}
309+
zoom={13}
310+
title="Grand Canyon"
341311
/>
342312

343-
<h2>Example 9: Map with All Default Values</h2>
313+
<h2>Example 5: Map with All Default Values</h2>
344314
<Map
345315
location="Statue of Liberty, New York"
346316
/>
347317

348-
<h2>Example 10: Full Custom Configuration</h2>
349-
<Map
350-
lat={40.7484}
351-
lng={-73.9857}
352-
zoom={16}
353-
mapType="hybrid"
354-
title="Empire State Building"
355-
loading="eager"
356-
referrerPolicy="no-referrer"
357-
/>
358-
359318
<h2>Usage in Layout</h2>
360319
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
361320
<div>

0 commit comments

Comments
 (0)