2.4.5 • Published 4 days ago

remapgl v2.4.5

Weekly downloads
40
License
MIT
Repository
-
Last release
4 days ago

remapgl

Declarative Mapbox GL bindings <🌎>

Quickly and easily create Mapbox GL maps with React components.

Install

yarn add remapgl

Use

Components accept most of the properties described in the Mapbox GL documentation as props.

Create a map

The root component of a map is RemapGL, all other components must be children of RemapGL.

import { RemapGL } from "remapgl";

export function App() {
  return <RemapGL accessToken="your access token" />;
}

Add Markers to a map

import { Marker, RemapGL } from "remapgl";

export function App() {
  return (
    <RemapGL accessToken="your access token">
      <Marker lnglat={{ lng: -68.2954881, lat: 44.3420759 }} />
    </RemapGL>
  );
}

Map layers

Layer order in the map is controlled by the order of the elements in the array provided to <LayerCollection> via its layers prop.

import { CircleLayer, CirclePaint } from "mapbox-gl";
import { FeatureCollection, Geometry } from "geojson";
import { LayerCollection, RemapGL } from "remapgl";

export function App() {
  return (
    <RemapGL accessToken="your access token">
      <LayerCollection layers={layerData} />
    </RemapGL>
  );
}

const data: FeatureCollection<Geometry, Record<string, any>> = {
  features: [
    {
      geometry: {
        coordinates: [-68.18928528, 44.32134247],
        type: "Point"
      },
      properties: {
        title: "Thunder Hole"
      },
      type: "Feature"
    }
  ],
  type: "FeatureCollection"
};

const paint: CirclePaint = {
  "circle-color": "#222",
  "circle-radius": {
    base: 1.15,
    stops: [
      [10, 5],
      [14, 5]
    ]
  },
  "circle-stroke-color": "#FFF",
  "circle-stroke-opacity": 0.8,
  "circle-stroke-width": {
    base: 1.15,
    stops: [
      [10, 3],
      [14, 3]
    ]
  }
};

const layerData: CircleLayer[] = [
  {
    id: "black",
    paint,
    source: { data, type: "geojson" },
    type: "circle"
  }
];

Other controls

import {
  AttributionControl,
  GeolocateControl,
  NavigationControl,
  RemapGL,
  ScaleControl,
  FullscreenControl
} from "remapgl";

export function App() {
  return (
    <RemapGL accessToken="your access token">
      <AttributionControl />
      <FullscreenControl />
      <GeolocateControl />
      <NavigationControl showCompass showZoom />
      <ScaleControl />
    </RemapGL>
  );
}

Control instance members

remapgl adopts a similar convention regarding Mapbox GL controls as React does for HTML DOM objects. Components that wrap a Mapbox GL control, which exposes instance members, support the MbxObj interface. A callback function provided to such a component's obj prop will be invoked with a single argument that is the current instance of the Mapbox GL control.

The following components support the MbxObj interface:

  • RemapGL: returns mapboxgl.Map.
  • Marker: returns: mapboxgl.Marker.
  • MapPopup: returns mapboxgl.Popup.
  • GeolocateControl: returns mapboxgl.GeoLocateControl.

In the following example the GeolocateControl returns the underlying Mapbox GL control which is used to trigger the request to start using geo-location.

import { GeolocateControl, RemapGL } from "remapgl";

export function App() {
  return (
    <RemapGL accessToken="your access token">
      <GeolocateControl obj={control => control.trigger()} />
    </RemapGL>
  );
}
2.4.5

4 days ago

2.4.3

19 days ago

2.4.4

18 days ago

2.4.2

10 months ago

2.4.1

1 year ago

2.4.0

1 year ago

2.3.2-alpha.19

2 years ago

2.3.2-alpha.18

2 years ago

2.3.2-alpha.17

2 years ago

2.3.2-alpha.16

2 years ago

2.3.2-alpha.15

2 years ago

2.3.2-alpha.14

2 years ago

2.3.2-alpha.13

2 years ago

2.3.2-alpha.12

2 years ago

2.3.2-alpha.11

2 years ago

2.3.2-alpha.10

2 years ago

2.3.2-alpha.1

2 years ago

2.3.2-alpha.0

2 years ago

2.3.2-alpha.7

2 years ago

2.3.2-alpha.6

2 years ago

2.3.2-alpha.9

2 years ago

2.3.2-alpha.8

2 years ago

2.3.2-alpha.3

2 years ago

2.3.2-alpha.2

2 years ago

2.3.2-alpha.5

2 years ago

2.3.2-alpha.4

2 years ago

2.3.2

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.3.1

2 years ago

2.1.0

3 years ago

2.0.0

3 years ago

0.14.0

4 years ago

0.14.1

4 years ago

0.13.2

4 years ago

0.13.1

4 years ago

0.13.0

4 years ago

0.12.2

4 years ago

0.12.0

4 years ago

0.12.1

4 years ago

0.11.11

4 years ago

0.11.10

4 years ago

0.11.9

4 years ago

0.11.8

4 years ago

0.11.7

4 years ago

0.11.6

4 years ago

0.11.5

4 years ago

0.11.4

4 years ago

0.11.3

4 years ago

0.11.2

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.3

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago