1.0.3 • Published 7 months ago

mapbox-map-web-component v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Mapbox Web Component

This is a simple Mapbox Web component that allow you to show map with point on your page. It should support any web page or framework like Angular, Vue, React and others.

Required

  • Mapbox token, check how to get the token

Optional

  • Mapbox style
  • Marker icon - you can provide your icon or use a build-in icon

Usage with node_module

Installation

npm install mapbox-map-web-component

Import

import 'mapbox-map-web-component'

Use

<div style="height: 100vh; width: 100%">
  <map-box-map
    width="100%"
    height="100%"
    access-token="<YOUR-TOKEN>"
    marker-width="60px"
    marker-height="60px"
  ></map-box-map>
</div>

Example in Vue

<map-box-map
  width="100%"
  height="500px"
  access-token="<YOUR-TOKEN>"
  zoom="11"
  marker-width="80px"
  marker-height="80px"
  :lng="location[0]"
  :lat="location[2]"
  marker-url="src/assets/markers/marker.png"
></map-box-map>

Example map

Usage with HTML file

Import

<script type="module" src="https://unpkg.com/mapbox-map-web-component@latest"></script>

Example

<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
  <title>Stencil Component Starter</title>

  <script type="module" src="https://unpkg.com/mapbox-map-web-component@latest"></script>
</head>
<body>
<div style="height: 100vh; width: 100%">
  <map-box-map
    width="100%"
    height="100%"
    access-token="<YOUR-TOKEN-HERE>"
    marker-width="60px"
    marker-height="60px"
  ></map-box-map>
</div>
</body>
</html>

Configuration Options

Below are the configuration properties available for the library/component. You can customize these to suit your application's needs.

PropertyTypeDefault ValueDescription
marker-urlstringundefinedURL for the marker icon to be used on the map. If not provided, a default icon is used. Sometimes restricted (e.g., ViteFS, see reference).
marker-widthstring'50px'Specifies the width of the marker in pixels.
marker-heightstring'50px'Specifies the height of the marker in pixels.
heightstring'100%'Represents the height of the map (supported CSS values).
widthstring'100%'Represents the width of the map (supported CSS values).
access-tokenstringundefinedMapbox access token (mandatory for Mapbox functionality). See Mapbox guide.
map-stylestringundefinedURL of the Mapbox style. See Map Styles.
lngnumber19.457216Longitude coordinate of the map's center.
latnumber51.759445Latitude coordinate of the map's center.
zoomnumber11Map's initial zoom level (min: 0, max: 15).

Example Configuration

Here’s an example of how you can configure the component:

<map-box-map
  width="80%"
  height="600px"
  access-token="your-access-token"
  map-style="mapbox://styles/mapbox/streets-v11"
  lng="10.7522"
  lat="59.9139"
  zoom="12"
  marker-url="https://example.com/custom-icon.png"
  marker-width="40px"
  marker-height="60px"
/>

Notes

  • marker-url: If the URL for the custom icon is restricted (e.g., when using Vite), ensure the path is allowed, as explained in the Vite documentation.
  • access-token: This is mandatory for the Mapbox functionality. Ensure you obtain your token from Mapbox).

Created with Stencil Built With Stencil

Stencil is a compiler for building fast web apps using Web Components.

Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than runtime tool. Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.

Stencil components are just Web Components, so they work in any major framework or with no framework at all.

Getting Started

To start building an own version of this web component, clone this repo to a new directory:

git clone https://github.com/DawidRyczko/map-box-web-component.git
cd map-box-web-component

and run:

npm install
npm start

To build the component for production, run:

npm run build

To run the unit tests for the components, run:

npm test

Need help? Check out our docs here.

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago