Home
Softono
b

beyonk

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
2

Software by beyonk

svelte-mapbox
Open Source

svelte-mapbox

<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) [![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) [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 adds about 0.5mb to the bundle size, and significant time to the build time if bundled. ## Installing ``` npm install --save-dev @beyonk/svelte-mapbox ``` ### Basic Usage (Map) The container component is the map, and there are a variety of components which go on the map. ```svelte <Map accessToken="<your api key>" // add your api key here bind:this={mapComponent} // Get reference to your map component to use methods onrecentre={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} color="rgb(255,255,255)" label="some marker label" popupClassName="class-name" /> // built in Marker component <NavigationControl /> <GeolocateControl options={{ some: 'control-option' }} oneventname={eventHandler} /> <ScaleControl /> </Map> <script> import { Map, Geocoder, Marker, controls } from '@beyonk/svelte-mapbox' import Earthquakes from './Earthquakes.svelte' // custom component 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. ```svelte <Marker color={brandColour} /> ``` You may also create a custom pin with the default slot. ```svelte <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. ```svelte <Marker label={markerText} /> ``` To indicate interactivity, you may target the marker with some custom CSS: ```svelte <style> :global(.mapboxgl-marker){ cursor: pointer; } </style> ``` Optionally, disable the popup with the `popup={false}` property: ```svelte <Marker popup={false} /> ``` You may alternatively pass a custom DOM element to the marker to use as a popup. ```svelte <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: ```svelte <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. ```svelte <Geocoder accessToken="<your api key>" onresult={somePlaceChangeFunction} /> <script> import { Geocoder } from '@beyonk/svelte-mapbox' </script> ``` The geocoder has five events you can subscribe to: `onloading`, `onresult`, `onresults`, `onclear`, and `onerror` which are [documented here](https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#on) The most important event is `onresult` which is fired when a user selects an autocomplete result. There is a sixth event specific to this library, which is `onready`, 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 `

Web Components & Widgets Map Servers & Tiles
365 Github Stars
svelte-google-analytics
Open Source

svelte-google-analytics

<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 Google Analytics** [![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) Supports Google Analytics v4! ## Install the package ```bash pnpm i --save-dev @beyonk/svelte-google-analytics ``` ## **Usage** In `App.svelte` ```svelte import { GoogleAnalytics } from '@beyonk/svelte-google-analytics' <GoogleAnalytics properties={[ 'google property id A', ...'google property id X' ]} /> ``` Component accepts two additional properties: `enabled` and `configurations`. ### The `configurations` property (optional) `configurations` props which accepts an object type with configurations for the properties. The key in this object is the id of the property. Example on disabling automatic pageviews for the `id-1` property: ```svelte <GoogleAnalytics properties={[ 'id-1' ]} configurations={{ 'id-1': { 'send_page_view': false } }} /> ``` ### The `enabled` property (optional) The `enabled` prop set to `true` by default. Logic can be added here to disable/enable analytics. If you disable tracking by default, for instance, due to [GDPR](https://github.com/beyonk-adventures/gdpr-cookie-consent-banner), then you can enable it later by calling `init()` on your component: ```svelte <GoogleAnalytics bind:this={ga} properties={[ 'id-1' ]} enabled={false} /> <script> function enableAnalytics () { ga.init() } </script> ``` ### Page Tracking With Google Analytics v4, most basic events are automatic. See [the docs](https://support.google.com/analytics/answer/9234069) (see [Google Analytics offical docs - Pageviews](https://developers.google.com/analytics/devguides/collection/gtagjs/pages)) for more info <p>&nbsp;</p> ### Event Tracking All [events specified in the documentation](https://support.google.com/analytics/answer/9267735?hl=en&ref_topic=9756175) are implemeneted (generated automatically from scraping the docs pages and building the project!) ```svelte <script> import { ga } from '@beyonk/svelte-google-analytics' function handleClick () { ga.games.earnVirtualCurrency('SvelteBucks', 50) } </script> <main> <button on:click={handleClick}>Get 50 SvelteBucks</button> </main> ``` #### Custom Events Custom events can be tracked with `addEvent`: ```svelte <script> import { ga } from '@beyonk/svelte-google-analytics' function handleClick () { ga.addEvent('event_name', { foo: 'bar', baz: 'qux' }) } </script> ``` #### Multiple Properties To send an event to a different property, specify the property id as the last parameter to the event: `send_to`. ```js ga.games.earnVirtualCurrency('SvelteBucks', 50, 'Property Id B') ``` #### Set User Properties To split user to different segment, such as language preference or geographic location, set the Properties with `setUserProperties` and setup custom dimension on Google Analytics dashboard. For more information see [Google Analytics Documentation](https://developers.google.com/analytics/devguides/collection/ga4/user-properties). ```js ga.setUserProperties({ favorite_composer: 'Mahler', favorite_instrument: 'double bass', season_ticketholder: 'true' }) ``` #### Set User Id To identify user inside GA and link their sessions together, set the Properties with `setUserId`. ```js ga.setUserId('user_id_here') ``` #### Set config To add a Google Analytics ID after initialization call the `setConfig` and pass optional configuration options. ```js ga.setConfig('ga_id', opts) ```

SEO Tools
77 Github Stars