mapbox / mapbox/mapbox-gl-draw

Argument of type 'MapboxDraw' is not assignable to parameter of type 'IControl'

Open
#1,257 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
1.1k
Forks
612
Avg merge
8d 9h
Merged PRs (30d)
5

Description

**@mapbox/mapbox-gl-draw:** ^1.4.3,
**@mapbox/mapbox-gl-draw-static-mode:** ^1.0.1,
**mapbox-gl:** ^3.2.0,

### Steps to Trigger Behavior

#### Code

```tsx

modes.static = StaticMode

const draw = new MapboxDraw({
displayControlsDefault: false,
touchEnabled: true,
modes,
styles: [
// ACTIVE (being drawn)
// line stroke
{
id: "gl-draw-line",
type: "line",
filter: ["all", ["==", "$type", "LineString"], ["!=", "mode", "static"]],
layout: {
"line-cap": "round",
"line-join": "round",
},
paint: {
"line-color": "#84cc16",
"line-width": 2, // Line width
"line-opacity": 1, // Fully opaque lines
},
},
// polygon fill
{
id: "gl-draw-polygon-fill",
type: "fill",
filter: ["all", ["==", "$type", "Polygon"], ["!=", "mode", "static"]],
paint: {
"fill-color": "#84cc16",
"fill-outline-color": "#84cc16",
"fill-opacity": 0.1, // Semi-opaque fill
},
},
// polygon outline stroke
// This doesn't style the first edge of the polygon, which uses the line stroke styling instead
{
id: "gl-draw-polygon-stroke-active",
type: "line",
filter: ["all", ["==", "$type", "Polygon"], ["!=", "mode", "static"]],
layout: {
"line-cap": "round",
"line-join": "round",
},
paint: {
"line-color": "#84cc16", // Red color for polygon outline
"line-width": 2, // Line width
"line-opacity": 1, // Fully opaque outline
},
},
// vertex point halos
{
id: "gl-draw-polygon-and-line-vertex-halo-active",
type: "circle",
filter: ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]],
paint: {
"circle-radius": 10,
"circle-color": "#FFF", // White color for vertex halo
},
},
// vertex points
{
id: "gl-draw-polygon-and-line-vertex-active",
type: "circle",
filter: ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]],
paint: {
"circle-radius": 8,
"circle-color": "#84cc16", // Red color for vertex points
},
},
// Inactive polygon fill
{
id: "gl-draw-polygon-fill-static",
type: "fill",
filter: ["all", ["==", "$type", "Polygon"], ["==", "mode", "static"]],
paint: {
"fill-color": "#3b82f6", // Blue color for inactive polygon fill
"fill-outline-color": "#3b82f6", // Blue outline
"fill-opacity": 0.1, // Semi-opaque fill
},
},
// Inactive polygon outline stroke
{
id: "gl-draw-polygon-stroke-static",
type: "line",
filter: ["all", ["==", "$type", "Polygon"], ["==", "mode", "static"]],
layout: {
"line-cap": "round",
"line-join": "round",
},
paint: {
"line-color": "#3b82f6", // Blue color for inactive polygon outline
"line-width": 2, // Line width
"line-opacity": 1, // Fully opaque outline
},
},
// Inactive vertex points
{
id: "gl-draw-polygon-and-line-vertex-static",
type: "circle",
filter: ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["==", "mode", "static"]],
paint: {
"circle-radius": 3,
"circle-color": "#3BB2D0", // Blue color for inactive vertex points
},
},
],

// Set mapbox-gl-draw to draw by default.
// The user does not have to click the polygon control button first.
// defaultMode: drawMode,
})

mapRef.current.addControl(draw, "top-right")
```

### Expected Behavior

Types compatible

### Actual Behavior

![image](https://github.com/user-attachments/assets/79245d42-75ab-40f4-8e59-c87017406a7b)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the TypeScript error on mapRef.current.addControl(draw, "top-right") and compare MapboxDraw's control declaration with mapbox-gl's IControl definition. Reproduce it with the listed package versions; done means the draw instance is accepted by addControl without a type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.