-
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.
solved the duplicated image name issue
- Loading branch information
Showing
3 changed files
with
52 additions
and
35 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 |
---|---|---|
@@ -1,17 +1,43 @@ | ||
import mapboxgl, { MapMouseEvent } from "mapbox-gl"; | ||
|
||
export const markerCreator = (e: MapMouseEvent, m: mapboxgl.Map, directionImg:HTMLElement, markerImg:HTMLElement) => { | ||
import directionSVG from "../public/icons/direction.svg"; | ||
import markerSVG from "../public/icons/marker.svg"; | ||
|
||
const direction = new mapboxgl.Marker(directionImg, { | ||
offset: [-.5, -25] | ||
}).setLngLat([e.lngLat.lng, e.lngLat.lat]).addTo(m) | ||
export const markerCreator = (e: MapMouseEvent, m: mapboxgl.Map) => { | ||
let directionImg = new Image(50, 50); | ||
let markerImg = new Image(25, 25); | ||
|
||
directionImg.onload = () => | ||
m?.addImage("directionImg", directionImg, { | ||
sdf: true, | ||
}); | ||
markerImg.onload = () => | ||
m?.addImage("markerImg", markerImg, { | ||
sdf: true, | ||
}); | ||
|
||
const marker = new mapboxgl.Marker(markerImg, { | ||
offset: [0, 0] | ||
}).setLngLat([e.lngLat.lng, e.lngLat.lat]).addTo(m) | ||
// Set the src attribute after attaching onload event handler | ||
directionImg.src = directionSVG.src; | ||
markerImg.src = markerSVG.src; | ||
|
||
return { direction, marker } | ||
if (m.hasImage("directionImg")) { | ||
m.removeImage("directionImg"); | ||
} | ||
if (m.hasImage("markerImg")) { | ||
m.removeImage("markerImg"); | ||
} | ||
|
||
} | ||
const direction = new mapboxgl.Marker(directionImg, { | ||
offset: [-0.5, -25], | ||
}) | ||
.setLngLat([e.lngLat.lng, e.lngLat.lat]) | ||
.addTo(m); | ||
|
||
const marker = new mapboxgl.Marker(markerImg, { | ||
offset: [0, 0], | ||
}) | ||
.setLngLat([e.lngLat.lng, e.lngLat.lat]) | ||
.addTo(m); | ||
|
||
return { direction, marker }; | ||
}; |