Skip to content

Commit

Permalink
Merge pull request #48 from Stassi/feature/mobile-tutorial-ts
Browse files Browse the repository at this point in the history
feature/mobile-tutorial-ts
  • Loading branch information
Stassi authored Oct 7, 2024
2 parents 1d22621 + 1f17ef6 commit 8bc2da4
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 88 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stassi/leaf",
"version": "0.0.47",
"version": "0.0.48",
"description": "Leaflet adapter.",
"keywords": [
"cartography",
Expand Down
23 changes: 0 additions & 23 deletions public/leaflet-adapter/circle.js

This file was deleted.

18 changes: 0 additions & 18 deletions public/leaflet-adapter/map/world-locator.js

This file was deleted.

2 changes: 1 addition & 1 deletion public/tutorial/mobile/mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>Leaflet on Mobile</title>
<link href="../../leaflet/leaflet.css" rel="stylesheet"/>
<link href="style/fullscreen.css" rel="stylesheet"/>
<script src="script/mobile.js" type="module"></script>
<script src="dist/mobile.js" type="module"></script>
</head>

<body>
Expand Down
35 changes: 0 additions & 35 deletions public/tutorial/mobile/script/mobile.js

This file was deleted.

13 changes: 13 additions & 0 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ const rollupConfig: RollupOptions[] = [
},
plugins: [typescript(), terser()],
},
{
external: ['@stassi/leaf'],
input: 'src/tutorial/mobile/mobile.ts',
output: {
file: 'public/tutorial/mobile/dist/mobile.js',
format: 'esm',
paths: {
'@stassi/leaf': '../../../leaf/leaf.js',
},
sourcemap: true,
},
plugins: [typescript(), terser()],
},
]

// eslint-disable-next-line import/no-default-export -- default export required by Rollup.js
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './leaf/circle.js'
export * from './leaf/coordinate-reference-system/epsg-3857.js'
export * from './leaf/map/map.js'
export * from './leaf/map/world-locator.js'
export * from './leaf/marker.js'
export * from './leaf/polygon.js'
export * from './leaf/popup.js'
Expand Down
37 changes: 37 additions & 0 deletions src/leaf/map/world-locator.ts
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)
}
34 changes: 34 additions & 0 deletions src/tutorial/mobile/mobile.ts
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,
})
10 changes: 2 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"checkJs": true,
"esModuleInterop": true,
"lib": ["DOM", "ESNext"],
"module": "ESNext",
Expand All @@ -13,11 +11,7 @@
"strict": true,
"target": "ESNext"
},
"exclude": ["node_modules", "public/tutorial/quick-start/dist/**/*.js"],
"exclude": ["node_modules"],
"extends": "@vercel/style-guide/typescript/node20",
"include": [
"public/tutorial/quick-start/**/*.js",
"rollup.config.ts",
"src/**/*.ts"
]
"include": ["rollup.config.ts", "src/**/*.ts"]
}

0 comments on commit 8bc2da4

Please sign in to comment.