Code Monkey home page Code Monkey logo

svelte-mapbox's Introduction

Beyonk

Svelte MapBox

js-standard-style CircleCI svelte-v2 svelte-v3

Maps and Geocoding (Autocomplete) components in Vanilla JS (or Svelte)

  • SSR Ready
  • Lightweight
  • No clientside dependencies
  • Allow creation of custom Svelte components on the map

WIP

Documentation is a WIP.

Basic Usage (Map)

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

<Map
  accessToken="<your api key>" // add your api key here
  on:recentre={e => console.log(e.detail.center.lat, e.detail.center.lng) } // recentre events
>
  <Earthquakes /> // Any custom component you create or want here - see marker example
  <Marker lat={someLat} lng={someLng} /> // built in Marker component
  <NavigationControl />
  <GeolocateControl options={{ some: 'control-option' }} />
  <ScalingControl />
</Map>

<script>
  import { Map, Geocoder, controls } from '@beyonk/svelte-mapbox'
	import Earthquakes from './Earthquakes.svelte' // custom component
  
  const { GeolocateControl, NavigationControl, ScalingControl } = controls
</script>

Basic Usage (Geocoder)

The Geocoder is an autocompleting place lookup, which returns a lat and lng for a place.

<Geocoder accessToken="<your api key>" on:place-changed={somePlaceChangeEvent} label="Some Label" />

<script>
  import { Geocoder } from '@beyonk/svelte-mapbox'
</script>

Note the label prop is used for aria-* attributes on the search input, this component doesn't have a built-in label.

Context API

This implementation makes use of the Context API, so you can wrap custom components in the Map, and inside those components you can do:

import { contextKey } from './mapbox.js'

const { getMap, getMapbox } = getContext(contextKey)
const map = getMap()
const mapbox = getMapbox()
  • map is a reference to the Map object.
  • mapbox is a reference to the mapbox library.

Demo

To see the earthquakes demo:

npm run dev

svelte-mapbox's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.