-
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.
Merge pull request #45 from MIERUNE/cursor
Custom cursor
- Loading branch information
Showing
5 changed files
with
112 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script lang="ts"> | ||
import { MapLibre, GeoJSONSource } from 'svelte-maplibre-gl'; | ||
import CircleLayer from '$lib/maplibre/layers/CircleLayer.svelte'; | ||
let cursor: string | undefined = $state(); | ||
const center = [0, 0]; | ||
const CURSORS = [ | ||
'cell', | ||
'col-resize', | ||
'context-menu', | ||
'copy', | ||
'crosshair', | ||
'default', | ||
'grab', | ||
'help', | ||
'move', | ||
'not-allowed', | ||
'pointer', | ||
'progress', | ||
'row-resize', | ||
'text', | ||
'vertical-text', | ||
'wait', | ||
'zoom-in', | ||
'zoom-out' | ||
]; | ||
const data: GeoJSON.FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: CURSORS.map((cursor, i) => ({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [ | ||
center[0] + Math.cos((i / CURSORS.length) * Math.PI * 2) * 15, | ||
center[1] + Math.sin((i / CURSORS.length) * Math.PI * 2) * 15 | ||
] | ||
}, | ||
properties: { | ||
cursor | ||
} | ||
})) | ||
}; | ||
</script> | ||
|
||
<MapLibre | ||
class="h-[55vh] min-h-[300px]" | ||
style="https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json" | ||
zoom={2} | ||
{cursor} | ||
center={{ lng: 0, lat: 0 }} | ||
> | ||
<GeoJSONSource {data}> | ||
<CircleLayer | ||
onmousemove={(e) => { | ||
cursor = e.features![0].properties.cursor; | ||
}} | ||
onmouseleave={() => { | ||
cursor = undefined; | ||
}} | ||
paint={{ | ||
'circle-radius': 12, | ||
'circle-color': '#007cbf', | ||
'circle-stroke-color': '#fff', | ||
'circle-stroke-width': 3 | ||
}} | ||
/> | ||
</GeoJSONSource> | ||
</MapLibre> |
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,15 @@ | ||
--- | ||
title: Change Cursor | ||
description: Change the cursor style on hover | ||
--- | ||
|
||
<script lang="ts"> | ||
import Demo from "./Cursor.svelte"; | ||
import demoRaw from "./Cursor.svelte?raw"; | ||
import CodeBlock from "../../CodeBlock.svelte"; | ||
let { shiki } = $props(); | ||
</script> | ||
|
||
<Demo /> | ||
|
||
<CodeBlock content={demoRaw} {shiki} /> |
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