1.0.4171 • Published 14 days ago

react-give-me-map v1.0.4171

Weekly downloads
-
License
ISC
Repository
github
Last release
14 days ago

🚧 The package is currently under development.

You can use this package and experiment with it but major changes may be introduced in future versions.

React - Give Me Map

Give-Me-Map is a library that allows you to add content on a map easily. Using Mapbox as an underlying map provider. The main features:

  • ✨ Simple to use
  • 🎨 Support many marker types
  • 💡 Create your content in JSON or draw your map on Mapheim and export it
  • 📦 Still Provides access to all underlying Mapbox API

Installation

Assuming you have react and react-dom packages already installed, you need to only install the following packages:

npm i react-give-me-map mapbox-gl react-map-gl

Example

Below you can see a demo created through Mapheim - a map about a running race event in Norway. You can also see a live demo on https://mapheim.com/fjellseterlopet.

Example of a map with custom content

Usage

Adding a map

A minimal map to be loaded into your application may look like the code below. This will include the map with a default location and style and without any markers (content).

import * as React from 'react'
import ReactDOM from 'react-dom'
import { GiveMeMap } from 'react-give-me-map';

function App() {
    const [viewport, setViewport] = React.useState({
        latitude: 55.15,
        longitude: 15.02,
        zoom: 4.4
    });

  return (
    <GiveMeMap
      map={{
          mapboxAccessToken: '<MAPBOX_TOKEN_HERE>',
          longitude: viewport.longitude,
          latitude: viewport.latitude,
          zoom: viewport.zoom,
          onMove: (v) => {
            setViewport({
              latitude: v.viewState.latitude,
              longitude: v.viewState.longitude,
              zoom: v.viewState.zoom
            })
          },
          style: {
            width: 1000,
            height: 400
          },
      }}
      config={{
        availableStyles: ['mapbox://styles/koudelka/cl6gs87ey002l15o9gnp7opx7']
      }}
    />)
}

ReactDOM.render(<App />, document.querySelector('#root'))

Adding markers

Manually

To add markers to your map, add a markers parameter and fill it with the right data. An example marker can be seen below:

  const imageMarker: IImageWorldMarker = {
    id: '1',
    lat: 55,
    lng: 16,
    elementType: 'image',
    elementData: {
      src: 'https://relive-story-static-content-email.s3.eu-central-1.amazonaws.com/logo.png',
    }
  }

  <GiveMeMap
    // ...otherAttributes
    markers={[imageMarker]}
  />

Using Mapheim

A nice alternative, and more user friendly is to use Mapheim editor on https://www.mapheim.com/world where you can instantly create a new map and either use your map hosted directly on Mapheim platform, or you can export the marker in a JSON format. And include it as a JSON/variable in your code. See below how to find the export functionality in two steps:

Mapheim export functionality

Detail Marker's documentation

Below you can see listed all the market types.

Marker typeDescription
TextRepresents a text
ImageRenders an image
DrawRenders a pencil/pen drawing
PinRenders a simple fixed-size marker that is represented by Image, Pin or Emoji
PolygonRepresents a drawing of the polygon with multiple points
DirectionRepresents a path computed between selected points on the map
YoutubeRenders a Youtube video that can be played
LinkRenders a link to the external web including it's favicon

Common marker attributes |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |id|string|required|-|Unique identifier of the marker| |lat|number|required|-|Latitude position of the marker on the map| |lng|number|required|-|Longitude position of the marker on the map| |elementType|enum|required|-|Defines the type of market. One of text, image, draw, pin, polygon, direction, youtube, link| |elementData|object|required|-|Defines the data of the marker, accepts different values dependent on the elementType, see the sections below for more information what is the structure| |scalable|boolean|optional|true|Indicates if the marker will scale when the map is zoomed in/out| |scale|number|optional|1|Defines the number that scales the marker > 1 to increase the size of the marker, < 1 to decrease the size of the marker| |order|number|optional|false|defines if the marker is in front/behind other markers. Higher the value, the more in front the marker is|

Text marker |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |text|string|required|-|Text content of the marker| |width|number|required|-|Defines the width of the marker. The text breaks after the given width| |fill|number|required|-|Defines if the marker is filled with background, otherwise background is transparent| |color|string|required|-|Background color of the marker in hexadecimal format| |textColor|string|optional|white|Text color| |borderRadiusPx|number|optional|0|Defines the border-radius style of the element in pixels| |borderSize|number|optional|0|Defines the border-size style of the element in pixels| |borderColor|string|optional|black|Defines the border-color style of the element| |dropShadowCombined|string|optional|empty|Defines the box-shadow style of the element| |textShadow|string|optional|1px 1px 2px rgba(0, 0, 0, 0.5) when fill=false, otherwise gamma is 0.25|Defines the box-shadow style of the element|

Image marker

AttributeTypeRequiredDefaultDescription
srcstringrequired-URL of the image to render
borderRadiusPxnumberoptional0Defines the border-radius style of the element in pixels
borderSizenumberoptional0Defines the border-size style of the element in pixels
borderColorstringoptionalblackDefines the border-color style of the element
dropShadowCombinedstringoptionalemptyDefines the box-shadow style of the element

Link marker |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |link|string|required|-|URL of the external website to redirect to when the marker is clicked| |text|string|required|-|Text content of the marker| |width|number|required|-|Defines the width of the marker. The text breaks after the given width| |color|string|required|-|Background color of the marker in hexadecimal format. Text color is determined automatically| |borderRadiusPx|number|optional|0|Defines the border-radius style of the element in pixels| |borderSize|number|optional|0|Defines the border-size style of the element in pixels| |borderColor|string|optional|black|Defines the border-color style of the element| |dropShadowCombined|string|optional|empty|Defines the box-shadow style of the element|

Draw marker |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |type|enum|required|-|One of pen, brush value. The value pen will render a sharp link, while brush will render a line that is not sharp and is more suitable for highlighting| |path|string|required|-|The definition of the line as a svg path. You can learn more about here.| |width|number|required|-||width|number|required|-|Defines the width of the marker| |height|number|required|-|Defines the height of the marker| |opacity|number|required|-|Defines the opacity style of the element. Accepts values between 0 and 1| |strokeWidth|number|required|-|Defines the width of the drawn line| |color|string|required|-|Defines the color of the drawn line| |fill|boolean|required|-|Defines is the drawn shape should be filled in with the same color as the line|

Pin marker |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |label|string|optional|-|Defines text that is displayed next to the pin| |img|string|optional|-||Defines content of the pin. Accepts a URL of the image that will render as a pin. When set, the emoji and dotColor should not be set| |emoji|string|optional|-|Defines content of the pin. Accepts a single character to be rendered as the pin. When set, the img and dotColor should not be set| |dotColor|string|optional|-|Defines content of the pin. Accepts the color that the pin will be filled with. When set, the img and emoji should not be set|

Polygon marker |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |path|string|required|- |coordinates|array of objects|required|-|Array of objects in the shape { lat: number; lng: number }. It defines all the vertices (points) of the polygon| |width|number|required|-|Width of the line the polygon is drawn with| |height|number|required|-|???| |color|string|required|-|Color of the polygon| |fill|boolean|optional|false||Defines is the drawn shape should be filled in with the same color as the polygon|

Direction marker |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |start|object|required|-|An object that defines the start of the route defined as { lat: number; lng: number }| |end|object|required|-|An object that defines the end of the route defined as { lat: number; lng: number }| |coordinates|array of objects|required|-|Array of objects in the shape { lat: number; lng: number } that are rendered in between start and end points| |transport|enum|required|-|One of 'driving-traffic, driving, walking, cycling, plane to define the type of transportation that the route is computed for. |lineColor|string|required|-|Color of the line that is rendered| |lineOpacity|number|required|-|Defines the opacity style of the line| |dropShadowColor|string|optional|empty|Defines the box-shadow style of the element|

Youtube marker |Attribute|Type|Required|Default|Description| |----|----|----|----|----| |video|string|required|-|Youtube video identifier or a full video URL| |borderRadiusPx|number|optional|0|Defines the border-radius style of the element in pixels| |borderSize|number|optional|0|Defines the border-size style of the element in pixels| |borderColor|string|optional|black|Defines the border-color style of the element| |dropShadowCombined|string|optional|empty|Defines the box-shadow style of the element|

Feedback

If you're having trouble implementing Give Me Map, check out GitHub issues or create a new GitHub issue.

1.0.4171

14 days ago

1.0.4170

2 months ago

1.0.4169

2 months ago

1.0.4166

2 months ago

1.0.4167

2 months ago

1.0.4165

3 months ago

1.0.4164

3 months ago

1.0.4162

3 months ago

1.0.4163

3 months ago

1.0.4160

3 months ago

1.0.4161

3 months ago

1.0.4157

3 months ago

1.0.4155

3 months ago

1.0.4156

3 months ago

1.0.4154

3 months ago

1.0.4151

3 months ago

1.0.4152

3 months ago

1.0.4149

3 months ago

1.0.4148

3 months ago

1.0.4146

4 months ago

1.0.4147

4 months ago

1.0.4144

4 months ago

1.0.4145

4 months ago

1.0.4142

4 months ago

1.0.4143

4 months ago

1.0.4141

4 months ago

1.0.4140

4 months ago

1.0.4139

5 months ago

1.0.4137

6 months ago

1.0.4138

5 months ago

1.0.4135

6 months ago

1.0.4136

6 months ago

1.0.4133

6 months ago

1.0.4134

6 months ago

1.0.4131

7 months ago

1.0.4132

7 months ago

1.0.4130

7 months ago

1.0.4128

7 months ago

1.0.4129

7 months ago

1.0.4126

7 months ago

1.0.4127

7 months ago

1.0.4124

7 months ago

1.0.4125

7 months ago

1.0.4122

7 months ago

1.0.4123

7 months ago

1.0.4120

7 months ago

1.0.4121

7 months ago

1.0.4119

7 months ago

1.0.4117

7 months ago

1.0.4118

7 months ago

1.0.4115

7 months ago

1.0.4116

7 months ago

1.0.4113

7 months ago

1.0.4114

7 months ago

1.0.4112

7 months ago

1.0.4098

10 months ago

1.0.4099

10 months ago

1.0.4096

10 months ago

1.0.4097

10 months ago

1.0.4094

10 months ago

1.0.4095

10 months ago

1.0.4092

10 months ago

1.0.4093

10 months ago

1.0.4090

10 months ago

1.0.4091

10 months ago

1.0.4089

10 months ago

1.0.4087

10 months ago

1.0.4088

10 months ago

1.0.4085

10 months ago

1.0.4086

10 months ago

1.0.4083

10 months ago

1.0.4084

10 months ago

1.0.4081

11 months ago

1.0.4082

11 months ago

1.0.4080

11 months ago

1.0.4078

11 months ago

1.0.4079

11 months ago

1.0.4076

11 months ago

1.0.4077

11 months ago

1.0.4074

11 months ago

1.0.4075

11 months ago

1.0.4072

11 months ago

1.0.4073

11 months ago

1.0.4070

12 months ago

1.0.4071

11 months ago

1.0.4110

9 months ago

1.0.4108

9 months ago

1.0.4109

9 months ago

1.0.4106

9 months ago

1.0.4107

9 months ago

1.0.4104

9 months ago

1.0.4105

9 months ago

1.0.4102

10 months ago

1.0.4103

9 months ago

1.0.4100

10 months ago

1.0.4101

10 months ago

1.0.4018

1 year ago

1.0.4019

1 year ago

1.0.4016

1 year ago

1.0.4017

1 year ago

1.0.4014

1 year ago

1.0.4015

1 year ago

1.0.4012

1 year ago

1.0.4013

1 year ago

1.0.4010

1 year ago

1.0.4011

1 year ago

1.0.4009

1 year ago

1.0.4007

1 year ago

1.0.4005

1 year ago

1.0.4006

1 year ago

1.0.4069

12 months ago

1.0.4067

12 months ago

1.0.4068

12 months ago

1.0.4065

1 year ago

1.0.4066

12 months ago

1.0.4063

1 year ago

1.0.4064

1 year ago

1.0.4061

1 year ago

1.0.4062

1 year ago

1.0.4060

1 year ago

1.0.4058

1 year ago

1.0.4059

1 year ago

1.0.4056

1 year ago

1.0.4057

1 year ago

1.0.4054

1 year ago

1.0.4055

1 year ago

1.0.4052

1 year ago

1.0.4053

1 year ago

1.0.4050

1 year ago

1.0.4051

1 year ago

1.0.4049

1 year ago

1.0.4047

1 year ago

1.0.4048

1 year ago

1.0.4045

1 year ago

1.0.4046

1 year ago

1.0.4043

1 year ago

1.0.4044

1 year ago

1.0.4041

1 year ago

1.0.4042

1 year ago

1.0.4040

1 year ago

1.0.4038

1 year ago

1.0.4039

1 year ago

1.0.4036

1 year ago

1.0.4037

1 year ago

1.0.4034

1 year ago

1.0.4032

1 year ago

1.0.4033

1 year ago

1.0.4030

1 year ago

1.0.4031

1 year ago

1.0.4029

1 year ago

1.0.4027

1 year ago

1.0.4028

1 year ago

1.0.4025

1 year ago

1.0.4026

1 year ago

1.0.4023

1 year ago

1.0.4024

1 year ago

1.0.4022

1 year ago

1.0.4020

1 year ago

1.0.3765

1 year ago

1.0.3766

1 year ago

1.0.3763

1 year ago

1.0.3764

1 year ago

1.0.3761

1 year ago

1.0.3762

1 year ago

1.0.3760

1 year ago

1.0.3758

1 year ago

1.0.3759

1 year ago

1.0.3756

1 year ago

1.0.3757

1 year ago

1.0.3754

1 year ago

1.0.3755

1 year ago

1.0.3752

1 year ago

1.0.3753

1 year ago

1.0.4003

1 year ago

1.0.3750

1 year ago

1.0.4004

1 year ago

1.0.3751

1 year ago

1.0.4001

1 year ago

1.0.4002

1 year ago

1.0.4000

1 year ago

1.0.3749

1 year ago

1.0.3747

1 year ago

1.0.3748

1 year ago

1.0.3745

1 year ago

1.0.3746

1 year ago

1.0.3743

1 year ago

1.0.3744

1 year ago

1.0.3741

1 year ago

1.0.3742

1 year ago

1.0.3740

1 year ago

1.0.3738

2 years ago

1.0.3739

2 years ago

1.0.3772

1 year ago

1.0.3770

1 year ago

1.0.3771

1 year ago

1.0.3769

1 year ago

1.0.3767

1 year ago

1.0.3768

1 year ago

1.0.3737

2 years ago

1.0.3736

2 years ago

1.0.3735

2 years ago

1.0.3734

2 years ago

1.0.3733

2 years ago

1.0.3732

2 years ago

1.0.3731

2 years ago

1.0.3730

2 years ago

1.0.3729

2 years ago

1.0.3728

2 years ago

1.0.3727

2 years ago

1.0.3726

2 years ago

1.0.3725

2 years ago

1.0.3724

2 years ago

1.0.3723

2 years ago

1.0.3722

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago