Skip to content

Commit

Permalink
Merge pull request #49 from Stassi/feature/merge-world-locator-into-map
Browse files Browse the repository at this point in the history
feature/merge-world-locator-into-map
  • Loading branch information
Stassi authored Oct 7, 2024
2 parents 8bc2da4 + 99b8c12 commit 525e9c5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 58 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.48",
"version": "0.0.49",
"description": "Leaflet adapter.",
"keywords": [
"cartography",
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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
46 changes: 35 additions & 11 deletions src/leaf/map/map.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {
map as leafletMap,
type CRS,
type ErrorEventHandlerFn,
type FitBoundsOptions,
type Layer,
type LeafletMouseEventHandlerFn,
type LocateOptions,
type LocationEventHandlerFn,
type Map,
type MapOptions as LeafletMapOptions,
} from 'leaflet'
Expand All @@ -15,7 +19,12 @@ export type MapOptions = LeafletMapOptions & {
activeLayers: Layer[]
crs: CRS
dragging: boolean
fitWorld: boolean
fitWorldOptions: FitBoundsOptions
locateOptions: LocateOptions
onClick: LeafletMouseEventHandlerFn
onLocate: LocationEventHandlerFn
onLocateError: ErrorEventHandlerFn
zoomDelta: number
zoomMax: number
zoomMin: number
Expand All @@ -26,24 +35,39 @@ export function map({
activeLayers: layers,
crs = epsg3857,
dragging = true,
fitWorld,
fitWorldOptions = fitWorld ? {} : undefined,
id: element,
locateOptions,
onClick,
onLocate,
onLocateError,
zoomDelta = 1,
zoomMax: maxZoom,
zoomMin: minZoom,
zoomSnap = 1,
...props
}: MapOptions): Map {
const created = leafletMap(element, {
crs,
dragging,
layers,
maxZoom,
minZoom,
zoomDelta,
zoomSnap,
...props,
})
const created: Map = leafletMap(element, {
crs,
dragging,
layers,
maxZoom,
minZoom,
zoomDelta,
zoomSnap,
...props,
}),
clickHandled: Map = onClick ? created.on('click', onClick) : created,
locationErrorHandled: Map = onLocateError
? clickHandled.on('locationerror', onLocateError)
: clickHandled,
locationFoundHandled: Map = onLocate
? locationErrorHandled.on('locationfound', onLocate)
: locationErrorHandled,
located: Map = locateOptions
? locationFoundHandled.locate(locateOptions)
: locationFoundHandled

return onClick ? created.on('click', onClick) : created
return fitWorldOptions ? located.fitWorld(fitWorldOptions) : located
}
37 changes: 0 additions & 37 deletions src/leaf/map/world-locator.ts

This file was deleted.

15 changes: 9 additions & 6 deletions src/tutorial/mobile/mobile.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { type ErrorEvent, type LocationEvent, type Map } from 'leaflet'

import { circle, marker, tileLayerOsm, worldLocator } from '@stassi/leaf'
import { circle, map as leafletMap, marker, tileLayerOsm } from '@stassi/leaf'

const map: Map = worldLocator({
const map: Map = leafletMap({
fitWorld: true,
id: 'map',
locateOptions: {
maxZoom: 16,
setView: true,
},
onLocate: ({
accuracy: radius,
latlng: latitudeLongitude,
}: LocationEvent) => {
}: LocationEvent): void => {
circle({
latitudeLongitude,
map,
Expand All @@ -20,12 +25,10 @@ const map: Map = worldLocator({
popupContent: `You are within ${radius.toString()} meters from this point.`,
}).openPopup()
},
onLocateError: ({ message }: ErrorEvent) => {
onLocateError: ({ message }: ErrorEvent): void => {
// eslint-disable-next-line no-alert -- required by tutorial
alert(message)
},
setViewOnLocate: true,
zoomMaxOnLocate: 16,
})

tileLayerOsm({
Expand Down

0 comments on commit 525e9c5

Please sign in to comment.