-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
264ac0c
commit 783b1d6
Showing
11 changed files
with
227 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface Window { | ||
google: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use client' | ||
|
||
import { MapComponent } from "./googleMap"; | ||
import { MapProvider } from "./mapProvider"; | ||
|
||
|
||
|
||
function extractMapParametersFromUrl(url: string) { | ||
const regex = /@(-?\d+\.\d+),(-?\d+\.\d+),(\d+)a,(\d+\.\d+)y,(\d+\.\d+)h,(\d+\.\d+)t/; | ||
console.log("url", url) | ||
|
||
const matches = url.match(regex); | ||
console.log("matches", matches) | ||
if (matches) { | ||
return { | ||
lat: parseFloat(matches[1]), | ||
lng: parseFloat(matches[2]), | ||
zoom: parseInt(matches[3]), | ||
pitch: parseFloat(matches[4]), | ||
heading: parseFloat(matches[5]), | ||
tilt: parseFloat(matches[6]), | ||
}; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
const DynamicMap = ({ mapUrl }: { mapUrl: string }) => { | ||
|
||
const mapParameters = extractMapParametersFromUrl(mapUrl); | ||
|
||
console.log("mapParameters", mapParameters) | ||
|
||
if (!mapParameters) { | ||
return <p>Invalid URL</p>; | ||
} | ||
|
||
return ( | ||
<MapProvider> | ||
<MapComponent lat={mapParameters.lat} lng={mapParameters.lng} zoom={mapParameters.zoom} tilt={mapParameters.tilt}></MapComponent> | ||
</MapProvider> | ||
); | ||
}; | ||
|
||
export default DynamicMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*Since the map was loaded on client side, | ||
we need to make this component client rendered as well*/ | ||
'use client' | ||
|
||
//Map component Component from library | ||
import { GoogleMap, useJsApiLoader } from "@react-google-maps/api"; | ||
|
||
|
||
const MapComponent = ({ lat, lng, zoom, tilt }: { lat: number, lng: number, zoom: number, tilt: number }) => { | ||
//Map's styling | ||
const defaultMapContainerStyle = { | ||
width: '100%', | ||
height: '100vh', | ||
borderRadius: '32px 0px 0px 32px', | ||
}; | ||
|
||
//K2's coordinates | ||
const defaultMapCenter = { | ||
lat: lat, | ||
lng: lng | ||
} | ||
|
||
//Default zoom level, can be adjusted | ||
const defaultMapZoom = zoom | ||
|
||
//Map options | ||
const defaultMapOptions = { | ||
zoomControl: false, | ||
tilt: tilt, | ||
}; | ||
|
||
|
||
|
||
return ( | ||
<div className="w-full"> | ||
<GoogleMap | ||
mapContainerStyle={defaultMapContainerStyle} | ||
center={defaultMapCenter} | ||
zoom={defaultMapZoom} | ||
options={defaultMapOptions} | ||
|
||
> | ||
</GoogleMap> | ||
</div> | ||
|
||
) | ||
}; | ||
|
||
export { MapComponent }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
const Map = (props: | ||
|
||
import { Work } from "@/payload-types"; | ||
import DynamicMap from "./dinamycMap"; | ||
|
||
const Map = ({ work, height = '800' }: | ||
{ | ||
hasCoordinates: (arg0: any) => any; | ||
work: { | ||
coordenadas: { | ||
longitude: any; | ||
latitude: any; | ||
}; | ||
}; | ||
// hasCoordinates: (arg0: any) => any; | ||
work: Work; | ||
height?: string; | ||
}) => { | ||
const height = props.height ?? '450' | ||
|
||
|
||
return ( | ||
props.hasCoordinates(props.work?.coordenadas) && <div className="w-full"> | ||
<iframe src={`https://www.google.com/maps/embed/v1/streetview?key=AIzaSyBFQ2XvHhidZ5rCrKnJ9GZMzldlkTUsRKQ&location=${props.work?.coordenadas?.longitude!},${props.work?.coordenadas?.latitude!}&heading=161&pitch=10&fov=35&`} width="100%" height={height} allowFullScreen={true} loading="lazy" referrerPolicy="no-referrer-when-downgrade"></iframe> | ||
</div>) | ||
work.mapUrl && | ||
<DynamicMap mapUrl={work.mapUrl} /> | ||
|
||
) | ||
}; | ||
|
||
// props.hasCoordinates(props.work?.coordenadas) && <div className="w-full"> | ||
// <iframe src={`https://www.google.com/maps/embed/v1/streetview?key=AIzaSyBFQ2XvHhidZ5rCrKnJ9GZMzldlkTUsRKQ&location=${props.work?.coordenadas?.longitude!},${props.work?.coordenadas?.latitude!}&heading=161&pitch=10&fov=35&`} width="100%" height={height} allowFullScreen={true} loading="lazy" referrerPolicy="no-referrer-when-downgrade"></iframe> | ||
// </div> | ||
|
||
|
||
|
||
export default Map |
Oops, something went wrong.