2.0.18 • Published 4 months ago

react-give-me-map v2.0.18

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months 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.

2.0.14

4 months ago

2.0.17

4 months ago

2.0.18

4 months ago

2.0.13

4 months ago

1.0.4197

6 months ago

2.0.11

5 months ago

2.0.12

5 months ago

2.0.10

5 months ago

2.0.3

5 months ago

2.0.2

5 months ago

2.0.5

5 months ago

2.0.4

5 months ago

2.0.7

5 months ago

2.0.6

5 months ago

2.0.9

5 months ago

2.0.1

5 months ago

2.0.0

5 months ago

1.0.4195

6 months ago

1.0.4196

6 months ago

1.0.4193

6 months ago

1.0.4194

6 months ago

1.0.4191

6 months ago

1.0.4192

6 months ago

1.0.4190

6 months ago

1.0.4188

7 months ago

1.0.4189

7 months ago

1.0.4186

7 months ago

1.0.4187

7 months ago

1.0.4185

7 months ago

1.0.4182

7 months ago

1.0.4183

7 months ago

1.0.4180

8 months ago

1.0.4181

8 months ago

1.0.4179

9 months ago

1.0.4177

9 months ago

1.0.4178

9 months ago

1.0.4175

9 months ago

1.0.4176

9 months ago

1.0.4173

9 months ago

1.0.4174

9 months ago

1.0.4172

10 months ago

1.0.4171

10 months ago

1.0.4170

11 months ago

1.0.4169

12 months ago

1.0.4166

12 months ago

1.0.4167

12 months ago

1.0.4165

1 year ago

1.0.4164

1 year ago

1.0.4162

1 year ago

1.0.4163

1 year ago

1.0.4160

1 year ago

1.0.4161

1 year ago

1.0.4157

1 year ago

1.0.4155

1 year ago

1.0.4156

1 year ago

1.0.4154

1 year ago

1.0.4151

1 year ago

1.0.4152

1 year ago

1.0.4149

1 year ago

1.0.4148

1 year ago

1.0.4146

1 year ago

1.0.4147

1 year ago

1.0.4144

1 year ago

1.0.4145

1 year ago

1.0.4142

1 year ago

1.0.4143

1 year ago

1.0.4141

1 year ago

1.0.4140

1 year ago

1.0.4139

1 year ago

1.0.4137

1 year ago

1.0.4138

1 year ago

1.0.4135

1 year ago

1.0.4136

1 year ago

1.0.4133

1 year ago

1.0.4134

1 year ago

1.0.4131

1 year ago

1.0.4132

1 year ago

1.0.4130

1 year ago

1.0.4128

1 year ago

1.0.4129

1 year ago

1.0.4126

1 year ago

1.0.4127

1 year ago

1.0.4124

1 year ago

1.0.4125

1 year ago

1.0.4122

1 year ago

1.0.4123

1 year ago

1.0.4120

1 year ago

1.0.4121

1 year ago

1.0.4119

1 year ago

1.0.4117

1 year ago

1.0.4118

1 year ago

1.0.4115

1 year ago

1.0.4116

1 year ago

1.0.4113

1 year ago

1.0.4114

1 year ago

1.0.4112

1 year ago

1.0.4098

2 years ago

1.0.4099

2 years ago

1.0.4096

2 years ago

1.0.4097

2 years ago

1.0.4094

2 years ago

1.0.4095

2 years ago

1.0.4092

2 years ago

1.0.4093

2 years ago

1.0.4090

2 years ago

1.0.4091

2 years ago

1.0.4089

2 years ago

1.0.4087

2 years ago

1.0.4088

2 years ago

1.0.4085

2 years ago

1.0.4086

2 years ago

1.0.4083

2 years ago

1.0.4084

2 years ago

1.0.4081

2 years ago

1.0.4082

2 years ago

1.0.4080

2 years ago

1.0.4078

2 years ago

1.0.4079

2 years ago

1.0.4076

2 years ago

1.0.4077

2 years ago

1.0.4074

2 years ago

1.0.4075

2 years ago

1.0.4072

2 years ago

1.0.4073

2 years ago

1.0.4070

2 years ago

1.0.4071

2 years ago

1.0.4110

2 years ago

1.0.4108

2 years ago

1.0.4109

2 years ago

1.0.4106

2 years ago

1.0.4107

2 years ago

1.0.4104

2 years ago

1.0.4105

2 years ago

1.0.4102

2 years ago

1.0.4103

2 years ago

1.0.4100

2 years ago

1.0.4101

2 years ago

1.0.4018

2 years ago

1.0.4019

2 years ago

1.0.4016

2 years ago

1.0.4017

2 years ago

1.0.4014

2 years ago

1.0.4015

2 years ago

1.0.4012

2 years ago

1.0.4013

2 years ago

1.0.4010

2 years ago

1.0.4011

2 years ago

1.0.4009

2 years ago

1.0.4007

2 years ago

1.0.4005

2 years ago

1.0.4006

2 years ago

1.0.4069

2 years ago

1.0.4067

2 years ago

1.0.4068

2 years ago

1.0.4065

2 years ago

1.0.4066

2 years ago

1.0.4063

2 years ago

1.0.4064

2 years ago

1.0.4061

2 years ago

1.0.4062

2 years ago

1.0.4060

2 years ago

1.0.4058

2 years ago

1.0.4059

2 years ago

1.0.4056

2 years ago

1.0.4057

2 years ago

1.0.4054

2 years ago

1.0.4055

2 years ago

1.0.4052

2 years ago

1.0.4053

2 years ago

1.0.4050

2 years ago

1.0.4051

2 years ago

1.0.4049

2 years ago

1.0.4047

2 years ago

1.0.4048

2 years ago

1.0.4045

2 years ago

1.0.4046

2 years ago

1.0.4043

2 years ago

1.0.4044

2 years ago

1.0.4041

2 years ago

1.0.4042

2 years ago

1.0.4040

2 years ago

1.0.4038

2 years ago

1.0.4039

2 years ago

1.0.4036

2 years ago

1.0.4037

2 years ago

1.0.4034

2 years ago

1.0.4032

2 years ago

1.0.4033

2 years ago

1.0.4030

2 years ago

1.0.4031

2 years ago

1.0.4029

2 years ago

1.0.4027

2 years ago

1.0.4028

2 years ago

1.0.4025

2 years ago

1.0.4026

2 years ago

1.0.4023

2 years ago

1.0.4024

2 years ago

1.0.4022

2 years ago

1.0.4020

2 years ago

1.0.3765

2 years ago

1.0.3766

2 years ago

1.0.3763

2 years ago

1.0.3764

2 years ago

1.0.3761

2 years ago

1.0.3762

2 years ago

1.0.3760

2 years ago

1.0.3758

2 years ago

1.0.3759

2 years ago

1.0.3756

2 years ago

1.0.3757

2 years ago

1.0.3754

2 years ago

1.0.3755

2 years ago

1.0.3752

2 years ago

1.0.3753

2 years ago

1.0.4003

2 years ago

1.0.3750

2 years ago

1.0.4004

2 years ago

1.0.3751

2 years ago

1.0.4001

2 years ago

1.0.4002

2 years ago

1.0.4000

2 years ago

1.0.3749

2 years ago

1.0.3747

2 years ago

1.0.3748

2 years ago

1.0.3745

2 years ago

1.0.3746

2 years ago

1.0.3743

2 years ago

1.0.3744

2 years ago

1.0.3741

2 years ago

1.0.3742

2 years ago

1.0.3740

2 years ago

1.0.3738

2 years ago

1.0.3739

2 years ago

1.0.3772

2 years ago

1.0.3770

2 years ago

1.0.3771

2 years ago

1.0.3769

2 years ago

1.0.3767

2 years ago

1.0.3768

2 years 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