Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Svelte 4 in peerDependencies #91

Open
wants to merge 158 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
0c0da00
Update src/Map.svelte
antony Apr 16, 2020
756f8e4
Merge pull request #6 from the-yadu/feature/fly-to
antony Apr 16, 2020
935ce18
Bump to version 3.1.0 [skip ci]
Apr 16, 2020
63ba7bc
allow binding of input value
Apr 23, 2020
aa7a376
Bump to version 3.1.1 [skip ci]
Apr 23, 2020
9329bae
default options for geocoder
Apr 24, 2020
f92c6e6
prepare for mapbox upgrade
Apr 24, 2020
1f6532c
remove mapbox lib from dependencies
antony May 5, 2020
343c966
4.0.0
antony May 5, 2020
6c093d2
Bump acorn from 6.1.1 to 6.4.1
dependabot[bot] May 5, 2020
b57e366
Export Marker component
kidandcat May 5, 2020
3f21803
Merge pull request #8 from kidandcat/patch-1
antony May 5, 2020
d644042
4.0.1
antony May 5, 2020
653855f
fix issue with marker's reference to mapbox
antony May 5, 2020
55bb213
4.0.2
antony May 5, 2020
7b5823c
Merge pull request #4 from beyonk-adventures/dependabot/npm_and_yarn/…
antony May 22, 2020
54cce10
improve marker
antony May 22, 2020
ccef8d3
Merge branch 'master' of github.com:beyonk-adventures/svelte-mapbox
antony May 22, 2020
ea639a1
4.1.0
antony May 22, 2020
0303a15
more docs
antony May 22, 2020
615d60e
customise marker colour
antony May 22, 2020
07f67e8
4.1.1
antony May 22, 2020
20d73b0
Make readme very clear
antony May 31, 2020
10a917a
use queue for map commands
antony Jun 12, 2020
8078ef9
4.2.0
antony Jun 12, 2020
472439f
Merge branch 'master' of github.com:beyonk-adventures/svelte-mapbox
antony Jun 12, 2020
bf0a7d0
oops
antony Jun 12, 2020
9c082ed
add github actions
antony Jun 12, 2020
94a2f70
4.2.0
antony Jun 12, 2020
8a0ecc5
expose fitBounds to resize map from bbox
nfk Jun 30, 2020
6b0ccc0
remove marker from the map on component destroy
nfk Jun 30, 2020
dac0d39
expose mapbox marker object
nfk Jun 30, 2020
459eb99
expose mapbox library
nfk Jun 30, 2020
8ce889c
Merge pull request #14 from nfk/improvements
antony Jun 30, 2020
631b988
lint
antony Jun 30, 2020
76c0329
4.3.0
antony Jun 30, 2020
e1b1dde
remove option to pass only lng to marker
antony Jul 24, 2020
be4ee3f
remove 'lon' option from marker
antony Jul 24, 2020
a7d3a90
5.0.0
antony Jul 24, 2020
c42c2f4
Bump lodash from 4.17.15 to 4.17.19
dependabot[bot] Jul 24, 2020
30d4ed0
Merge pull request #15 from beyonk-adventures/dependabot/npm_and_yarn…
antony Aug 13, 2020
a6eeb34
add events to geolocate
antony Aug 13, 2020
721246d
5.1.0
antony Aug 13, 2020
518090e
use new syntax
antony Aug 13, 2020
4b3086b
lint
antony Aug 13, 2020
7c45ff9
5.2.0
antony Aug 13, 2020
437e06f
remove CircleCI badge
antony Aug 13, 2020
2c0bf74
pass data during events
antony Aug 13, 2020
32f3470
5.2.1
antony Aug 13, 2020
1efee84
fix events on geolocation control
antony Aug 13, 2020
a0071ad
5.2.2
antony Aug 13, 2020
2250ac0
Update README.md
markfirmware Aug 25, 2020
852facb
Merge pull request #16 from markfirmware/patch-1
antony Aug 25, 2020
b913e97
include render troubleshooting in readme example
jbixon13 Sep 12, 2020
72e011e
fix css class to global scope
jbixon13 Sep 12, 2020
3f9c25a
add options to base map example
jbixon13 Sep 12, 2020
3f99881
fix css comment indent
jbixon13 Sep 12, 2020
338ec1e
Merge pull request #17 from jbixon13/master
antony Sep 12, 2020
f3ede40
Upgrade dependencies
singingwolfboy Sep 28, 2020
841cf00
Merge pull request #18 from singingwolfboy/upgrade-deps
antony Dec 8, 2020
d8f77b9
allow realtime marker position updates and optional popup
antony Dec 8, 2020
48e5bf4
lint
antony Dec 8, 2020
5632499
5.3.0
antony Dec 8, 2020
f7bcb26
update readme
antony Dec 8, 2020
cdad03e
add reactive properties
antony Dec 9, 2020
2b7f4b5
6.0.0
antony Dec 9, 2020
3dc4741
onClick event emit in map component
the-yadu Dec 29, 2020
b930078
allow overriding cssurl
antony Jan 5, 2021
4336ba7
6.0.1
antony Jan 5, 2021
17bb227
allow overriding not replacing css
antony Jan 5, 2021
682ac04
6.0.2
antony Jan 5, 2021
b656ef3
lint
antony Jan 5, 2021
a9ffb76
6.0.3
antony Jan 5, 2021
c01b38d
Update src/Map.svelte
antony Jan 6, 2021
425fec0
Merge pull request #25 from the-yadu/patch-3
antony Jan 6, 2021
aa671e1
fix broken loader
antony Jan 11, 2021
0971e6a
6.0.4
antony Jan 11, 2021
7790c82
fix demo page
antony Jan 12, 2021
c2fbf22
fix lint issue
antony Jan 12, 2021
973af01
6.0.5
antony Jan 12, 2021
4e5feb5
fix reactive zoom and center, marker, add marker offset, adjust popup…
antony Jan 12, 2021
0bae8c2
7.0.0
antony Jan 12, 2021
82ef2b8
little demo fix
antony Jan 12, 2021
2bf294c
Fixed issue 28
AndreasHald Feb 11, 2021
7ba3072
Merge pull request #29 from AndreasHald/issue-28
antony Feb 11, 2021
140a03a
7.1.0
antony Feb 26, 2021
9049aff
expose more useful methods
antony Mar 4, 2021
72939da
7.2.0
antony Mar 4, 2021
7b828a2
Custom Markers as slot (#34)
Amerlander Mar 23, 2021
3e1f141
7.3.0
antony Mar 23, 2021
c6d26d8
lint
antony Mar 24, 2021
0205dcf
7.3.1
antony Mar 24, 2021
094eb12
Add named Slot for Popup html (#38)
Amerlander Mar 24, 2021
4964631
7.4.0
antony Mar 24, 2021
d74815e
Feature/map react to zoom change via binding (#36)
LucianVoju Mar 24, 2021
f95e0c7
bind reactively to zoom
antony Mar 24, 2021
ccac4d5
7.5.0
antony Mar 24, 2021
0070a6c
don't break if the site is too quick (damn you svelte)
antony Mar 25, 2021
b9efb8c
7.5.1
antony Mar 25, 2021
8f07754
Added optional paremters to Map methods to be passed down to/enable o…
sdl60660 Mar 25, 2021
168c21a
lint
antony Mar 25, 2021
9623e13
7.6.0
antony Mar 25, 2021
ec67bc7
Add support for extra options (#41)
CraigChamberlain Jul 8, 2021
250eeee
Add details fo new Marker (#42)
CraigChamberlain Jul 8, 2021
56b6c9c
7.7.0
antony Jul 8, 2021
6017eac
fix lint
antony Jul 8, 2021
64b7bae
7.7.1
antony Jul 8, 2021
4687b2f
Bump color-string from 1.5.4 to 1.5.5 (#53)
dependabot[bot] Jul 8, 2021
3cd6c92
Bump glob-parent from 5.1.1 to 5.1.2 (#52)
dependabot[bot] Jul 8, 2021
930752b
Bump browserslist from 4.15.0 to 4.16.6 (#51)
dependabot[bot] Jul 8, 2021
9961f8d
Bump hosted-git-info from 2.8.8 to 2.8.9 (#49)
dependabot[bot] Jul 8, 2021
14afeb7
Bump lodash from 4.17.20 to 4.17.21 (#48)
dependabot[bot] Jul 8, 2021
59d75f2
Feature/sveltekit (#55)
antony Jul 21, 2021
e0d5679
re-add lint
antony Jul 21, 2021
f34181d
upgrade node
antony Jul 21, 2021
7911a4f
8.0.0
antony Jul 21, 2021
c35ec67
add svelte2tsx
antony Jul 21, 2021
22be8fa
8.0.1
antony Jul 21, 2021
ea6a20a
just keep adding deps I guess
antony Jul 21, 2021
d5ef95f
upgrade node version on ci
antony Jul 21, 2021
0d40cec
8.0.2
antony Jul 21, 2021
ca68885
get rid of sveltekit specific aliases
antony Jul 21, 2021
c030518
8.0.3
antony Jul 21, 2021
fa3e073
add drag event
antony Jul 22, 2021
c36e1f6
8.1.0
antony Jul 22, 2021
43009e3
fix eslint
antony Jul 22, 2021
5dfa7b3
8.1.1
antony Jul 22, 2021
4d2a6f4
regress geocoder due to bug in mapbox-gl-geocoder
antony Jul 23, 2021
be62c02
8.1.2
antony Jul 23, 2021
c1a45b4
dispatch ready events
antony Jul 23, 2021
bbe63a5
8.1.3
antony Jul 23, 2021
9e1f259
8.1.4
antony Jul 23, 2021
b2de3ee
Update Logo
ahpercival Dec 14, 2021
22e6119
Create LICENSE (#69)
brittharr Nov 15, 2022
088e008
Update Map.svelte (#74)
eur2 Nov 15, 2022
f647f7e
8.2.0
antony Nov 15, 2022
92c7274
upgrade map (but not geocoder because it has regressed)
antony Jan 24, 2023
9972e2f
9.0.0
antony Jan 24, 2023
2f6953a
add svelte-package command
antony Jan 24, 2023
d355373
9.0.1
antony Jan 24, 2023
6b57ea4
add lint to ci
antony Jan 24, 2023
3115aa8
lint fix
antony Jan 24, 2023
6ac3fd5
9.0.2
antony Jan 24, 2023
32bb8d8
upgrade node, pnpm
antony Jan 24, 2023
72816f3
9.0.3
antony Jan 24, 2023
99e2621
cycle api key
antony Jan 24, 2023
706860c
9.0.4
antony Jan 24, 2023
b20c809
remove old api token
antony Jan 24, 2023
69dc8bd
fix main export
antony Jan 24, 2023
f6a92c6
9.0.5
antony Jan 24, 2023
b88bd65
Remove empty div when using default mapbox markers (#63)
cucharadepalo Jun 3, 2023
3189531
add types to package.json (#86)
jamesatjaminit Jun 3, 2023
aecb36c
update lockfile
Jun 3, 2023
a40378c
9.1.0
Jun 3, 2023
2bd9767
upgrade to 4.0
StephenGunn Jul 14, 2023
7d32aaf
peer support for svelte 3 and 4
StephenGunn Jul 14, 2023
6c82451
svelte4
StephenGunn Dec 15, 2023
b07ed79
env
StephenGunn Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions .circleci/config.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package
.svelte-kit
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@beyonk/eslint-config/svelte",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020
}
}
47 changes: 47 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: publish

on:
push:
branches:
- '*'
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master

- uses: volta-cli/action@v1

- uses: pnpm/[email protected]
with:
version: latest
run_install: true

- run: pnpm lint

publish-npm:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master

- uses: volta-cli/action@v1

- uses: pnpm/[email protected]
with:
version: latest
run_install: true

- run: pnpm build
- run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
pnpm package
pnpm publish ./package
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
node_modules
dist
/.svelte-kit
/package
.env.local
.env
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Svelte-Mapbox Changelog

# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [8.0.0]

### Recentre event

Events made more predictable - the recentre event from a map used to actually be `dragend`. It is now triggered by `moveend` - which means it will be fired for anything which moves the map. `dragend` now fires the `dragend` event.

To retain prior behaviour - change uses of `recentre` on `Map` to be `dragend`.

### SvelteKit Support

All external dependencies have been removed (except Mapbox of course!)
`fastq` is removed in favour of svelte stores, and because it didn't support ESM.
`@beyonk/svelte-loader` is removed in favour of using actions to load dependencies.
This module should work fine with `SvelteKit` now.

### IE11 Support

This module no longer attempts to support IE11, and neither should you.

### Actions driven

Both components now use Svelte `actions` instead of `onMount`, resulting in faster loading.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2021 [these people](https://github.com/beyonk-adventures/svelte-mapbox/graphs/contributors)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
148 changes: 134 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
<p align="center">
<img width="186" height="90" src="https://user-images.githubusercontent.com/218949/44782765-377e7c80-ab80-11e8-9dd8-fce0e37c235b.png" alt="Beyonk" />
</p>
<a href="https://beyonk.com">
<br />
<br />
<img src="https://user-images.githubusercontent.com/218949/144224348-1b3a20d5-d68e-4a7a-b6ac-6946f19f4a86.png" width="198" />
<br />
<br />
</a>

## Svelte MapBox

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) [![CircleCI](https://circleci.com/gh/beyonk-adventures/svelte-mapbox.svg?style=shield)](https://circleci.com/gh/beyonk-adventures/svelte-mapbox) [![svelte-v2](https://img.shields.io/badge/svelte-v2-orange.svg)](https://v2.svelte.dev) [![svelte-v3](https://img.shields.io/badge/svelte-v3-blueviolet.svg)](https://svelte.dev)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) [![svelte-v3](https://img.shields.io/badge/svelte-v3-blueviolet.svg)](https://svelte.dev) ![publish](https://github.com/beyonk-adventures/svelte-mapbox/workflows/publish/badge.svg)

Maps and Geocoding (Autocomplete) components in Vanilla JS (or Svelte)
Maps and Geocoding (Autocomplete) [MapBox](https://www.mapbox.com/) components in Vanilla JS (or Svelte)

* SvelteKit Ready
* SSR Ready
* Lightweight
* No clientside dependencies (Map)
* Allow creation of custom Svelte components on the map

* Note that the GeoCoder has a clientside dependency, since it appears to be extremely difficult to bundle.
* Note that the GeoCoder has a clientside dependency, since it adds about 0.5mb to the bundle size, and significant time to the build time if bundled.

## WIP
## Installing

Documentation is a WIP.
```
npm install --save-dev @beyonk/svelte-mapbox
```

## Basic Usage (Map)
### Basic Usage (Map)

The container component is the map, and there are a variety of components which go on the map.

Expand All @@ -28,25 +35,132 @@ The container component is the map, and there are a variety of components which
accessToken="<your api key>" // add your api key here
bind:this={mapComponent} // Get reference to your map component to use methods
on:recentre={e => console.log(e.detail.center.lat, e.detail.center.lng) } // recentre events
options={{ scrollZoom: false }} // // add arbitrary options to the map from the mapbox api
>
<Earthquakes /> // Any custom component you create or want here - see marker example
<Marker lat={someLat} lng={someLng} /> // built in Marker component
<Marker lat={someLat} lng={someLng} color="rgb(255,255,255)" label="some marker label" popupClassName="class-name" /> // built in Marker component
<NavigationControl />
<GeolocateControl options={{ some: 'control-option' }} />
<ScalingControl />
<GeolocateControl options={{ some: 'control-option' }} on:eventname={eventHandler} />
<ScaleControl />
</Map>

<script>
import { Map, Geocoder, controls } from '@beyonk/svelte-mapbox'
import { Map, Geocoder, Marker, controls } from '@beyonk/svelte-mapbox'
import Earthquakes from './Earthquakes.svelte' // custom component

const { GeolocateControl, NavigationControl, ScalingControl } = controls
const { GeolocateControl, NavigationControl, ScaleControl } = controls

// Usage of methods like setCenter and flyto
mapComponent.setCenter([lng,lat],zoom) // zoom is optional
mapComponent.flyTo({center:[lng,lat]}) // documentation (https://docs.mapbox.com/mapbox-gl-js/example/flyto)

// Define this to handle `eventname` events - see [GeoLocate Events](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol-events)
function eventHandler (e) {
const data = e.detail
// do something with `data`, it's the result returned from the mapbox event
}
</script>

<style>
:global(.mapboxgl-map) {
height: 200px;
// sometimes mapbox objects don't render as expected; troubleshoot by changing the height/width to px
}
</style>
```

### Markers

By default, markers are typical map pins to which you can pass a color property.

```jsx
<Marker color={brandColour} />
```

You may also create a custom pin with the default slot.

```jsx
<Marker
lat={waypoint.geo.lat}
lng={waypoint.geo.lng}
>
<a href={waypoint.slug}>
<div class='myMarker {($mapData.activeMarker == waypoint.id) ? 'active' : ''}'
style="
color:{mainPoint.color};
background-image: url('{(waypoint.images != undefined) ? waypoint.images[0].thumb.url : ''}');
">
</div>
</a>
</Marker>
```

### Marker Popups
By default a popup is revealed when you click a pin. It is populated with text provided in the label property.

```jsx
<Marker label={markerText} />
```

To indicate interactivity, you may target the marker with some custom CSS:

```jsx
<style>
:global(.mapboxgl-marker){
cursor: pointer;
}
</style>
```

Optionally, disable the popup with the `popup={false}` property:

```jsx
<Marker popup={false} />
```

You may alternatively pass a custom DOM element to the marker to use as a popup.

```jsx
<Marker lat={pin.coordinates.latitude} lng={pin.coordinates.longitude}>
<div class="content" slot="popup">
<h3>{pin.name}</h3>
<Markdown source={pin.description} />
</div>
<img src="{pin.images.length > 0 ? pin.images[0].url : ""}" alt="{pin.name}"/>
</div>
</Marker>
```

### Reactive Properties

The map has reactive properties for `center` and `zoom`. This means that if you set these properties, or modify them whilst the map is displayed, the map will react accordingly.

This also means that if you bind these properties to a variable, that variable will automatically be updated with the current `center` and `zoom` of the map if the user moves or zooms the map.

This is often easier than waiting for events such as `recentre` or `zoom` to be fired, to update markers and similar:

```jsx
<Map accessToken="<your api key>" bind:center bind:zoom>
<Marker bind:lat bind:lng />
</Map>

<script>
let center
let zoom

$: lng = center[0]
$: lat = center[1]
</script>
```

### Methods

The map has a variety of methods which delegate to a queue. The reason for this is that MapBox is quite a heavy library, and rendering a map is a pretty heavy operation. It's hard to guarantee
when everything is ready in your browser, and when you can start doing things with it.

In case you want raw map access to interact directly with the map, you can call `getMap` on the map and interact with it that way. However we don't recommend it, as you have no guarantees that the
map is ready in your browser when you call it this way.

## Basic Usage (Geocoder)

The Geocoder is an autocompleting place lookup, which returns a lat and lng for a place.
Expand All @@ -65,10 +179,16 @@ The most important event is `on:result` which is fired when a user selects an au

There is a sixth event specific to this library, which is `on:ready`, which is fired when the component is ready for use. You can likely ignore it.

## Custom CSS

You can add additional css to override mapbox provided CSS by passing the `customStylesheetUrl` property to either the `Map` or `Geocoder` components.

## Demo

To see the earthquakes demo:

Make sure you copy the `.env` file to `.env.local` and then populate it with your mapbox key.

`
npm run dev
`
Expand Down
Loading