mapbox-gl-draw-select-mode

1.0.3 • Public • Published

NPM Release

mapbox-gl-draw-select-mode

A custom mode for MapboxGL-Draw to select features that highlights features on hover.

Install

npm install mapbox-gl-draw-split-polygon-mode

or use CDN:

<script src="https://unpkg.com/mapbox-gl-draw-select-mode"></script>

Usage

import mapboxGl from "mapbox-gl";
import MapboxDraw from "@mapbox/mapbox-gl-draw";
import defaultDrawStyle from "@mapbox/mapbox-gl-draw/src/lib/theme.js";

import SelectFeatureMode, {
  drawStyles as selectFeatureDrawStyles,
} from "mapbox-gl-draw-select-mode";

const map = new mapboxgl.Map({
  container: "map",
  center: [-91.874, 42.76],
  zoom: 12,
});

draw = new MapboxDraw({
  userProperties: true,
  displayControlsDefault: false,
  modes: {
    ...SelectFeatureMode(MapboxDraw.modes),
  },
  styles: [...selectFeatureDrawStyles(defaultDrawStyle)],
  userProperties: true,
  // Config select-mode
  selectHighlightColor: "red",
});

map.addControl(draw);

draw?.changeMode("select_feature", {
  /// you can override the highlight color for this operation:
  selectHighlightColor: "blue",
  onSelect(selectedFeatureID) {
    alert(`Selected Feature ID: ${selectedFeatureID}`);
  },
});

Package Sidebar

Install

npm i mapbox-gl-draw-select-mode

Weekly Downloads

128

Version

1.0.3

License

MIT

Unpacked Size

282 kB

Total Files

9

Last publish

Collaborators

  • mh_sattarian