mapbox / mapbox-gl-draw

Draw tools for mapbox-gl-js
https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/
ISC License
955 stars 593 forks source link

Error: "type" member required on when using draw.add(geojson) #1029

Closed acebelowzero closed 3 years ago

acebelowzero commented 3 years ago

mapbox-gl-js version: "^2.0.0 mapbox-gl-draw version:^1.2.0

Steps to Trigger Behavior

  1. create a feature collection from a get request
    
    const data = {
        type: "FeatureCollection",
        features:
            zones.map((d) => ({
                type: "Feature",
                id: d.zoneID,
                properties: {},
                geometry: {
                    type: "Polygon",
                    coordinates: [[JSON.parse(d.st_asgeojson).coordinates]]
                },
            }))
    }
 2. add draw.add(data)

### Expected Behavior
multiple polygons to be added to the map

### Actual Behavior
Throws an error

Uncaught (in promise) Error: "type" member required at MapboxDraw.__webpack_exports__.default.api.add (api.js?042a:79) at _callee$ (zones.js?f2b3:32) at tryCatch (runtime.js?96cf:63) at Generator.invoke [as _invoke] (runtime.js?96cf:293) at Generator.eval [as next] (runtime.js?96cf:118) at asyncGeneratorStep (asyncToGenerator.js?1da1:3) at _next (asyncToGenerator.js?1da1:25)


This is how my collection looks closed
![my-feature-collection](https://user-images.githubusercontent.com/64754588/102643202-245e9480-411c-11eb-9696-10982633cbc2.PNG)
this is how it looks open
![my-CollectionOpen](https://user-images.githubusercontent.com/64754588/102643212-288ab200-411c-11eb-8237-38760a5e8dd5.PNG)
this is mapbox draw when creating a new collection
![mapbox-draw-new-collection](https://user-images.githubusercontent.com/64754588/102643218-2a547580-411c-11eb-973f-18efd1bf7a0c.PNG)
this is how it looks when I open it
![mapbox-draw-collection-open](https://user-images.githubusercontent.com/64754588/102643228-2d4f6600-411c-11eb-8789-e036c677e195.PNG)

I believe my geojson is correct because it matches the geojson mapbox draw creates when I add new ploygons
acebelowzero commented 3 years ago

was returning a promise