-
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 #48 from Stassi/feature/mobile-tutorial-ts
feature/mobile-tutorial-ts
- Loading branch information
Showing
11 changed files
with
91 additions
and
88 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
This file was deleted.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
type ErrorEventHandlerFn, | ||
type LocateOptions, | ||
type LocationEventHandlerFn, | ||
type Map, | ||
} from 'leaflet' | ||
|
||
import { map } from './map.js' | ||
|
||
export type WorldLocatorMapOptions = { | ||
id: string | HTMLElement | ||
onLocate: LocationEventHandlerFn | ||
onLocateError: ErrorEventHandlerFn | ||
} & Omit<LocateOptions, 'maxZoom' | 'setView'> & | ||
Partial<{ | ||
setViewOnLocate: boolean | ||
zoomMaxOnLocate: number | ||
}> | ||
|
||
export function worldLocator({ | ||
id, | ||
onLocate, | ||
onLocateError, | ||
setViewOnLocate: setView, | ||
zoomMaxOnLocate: maxZoom, | ||
...props | ||
}: WorldLocatorMapOptions): Map { | ||
return map({ id }) | ||
.fitWorld() | ||
.locate({ | ||
maxZoom, | ||
setView, | ||
...props, | ||
}) | ||
.on('locationerror', onLocateError) | ||
.on('locationfound', onLocate) | ||
} |
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,34 @@ | ||
import { type ErrorEvent, type LocationEvent, type Map } from 'leaflet' | ||
|
||
import { circle, marker, tileLayerOsm, worldLocator } from '@stassi/leaf' | ||
|
||
const map: Map = worldLocator({ | ||
id: 'map', | ||
onLocate: ({ | ||
accuracy: radius, | ||
latlng: latitudeLongitude, | ||
}: LocationEvent) => { | ||
circle({ | ||
latitudeLongitude, | ||
map, | ||
radius, | ||
}) | ||
|
||
marker({ | ||
latitudeLongitude, | ||
map, | ||
popupContent: `You are within ${radius.toString()} meters from this point.`, | ||
}).openPopup() | ||
}, | ||
onLocateError: ({ message }: ErrorEvent) => { | ||
// eslint-disable-next-line no-alert -- required by tutorial | ||
alert(message) | ||
}, | ||
setViewOnLocate: true, | ||
zoomMaxOnLocate: 16, | ||
}) | ||
|
||
tileLayerOsm({ | ||
map, | ||
zoomMax: 19, | ||
}) |
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