-
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
Showing
4 changed files
with
535 additions
and
67 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
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,35 @@ | ||
import React, { useState, useContext } from "react"; | ||
import mapboxgl, { MapMouseEvent } from "mapbox-gl"; | ||
import { MarkerContext, MarkerContextType } from '@/contexts/MarkerContext' | ||
|
||
import directionSVG from "../public/icons/direction.svg" | ||
import markerSVG from "../public/icons/marker.svg" | ||
|
||
const useCreateMarker = (e: MapMouseEvent, m: mapboxgl.Map) => { | ||
const { setDirection, setMarker } = useContext(MarkerContext) as MarkerContextType | ||
|
||
|
||
let directionImg = new Image(50, 50) | ||
directionImg.onload = () => m.addImage('direciton', directionImg, { | ||
sdf: true | ||
}) | ||
directionImg.src = directionSVG.src | ||
|
||
const direction = new mapboxgl.Marker(directionImg, { | ||
offset: [-.5, -25] | ||
}).setLngLat([e.lngLat.lng, e.lngLat.lat]).addTo(m) | ||
setDirection(direction) | ||
|
||
let markerImg = new Image(25, 25) | ||
markerImg.onload = () => m.addImage('marker', markerImg, { | ||
sdf: true | ||
}) | ||
markerImg.src = markerSVG.src | ||
|
||
const marker = new mapboxgl.Marker(markerImg, { | ||
offset: [0, 0] | ||
}).setLngLat([e.lngLat.lng, e.lngLat.lat]).addTo(m) | ||
setMarker(marker) | ||
} | ||
|
||
export default useCreateMarker |
Oops, something went wrong.