mapbox / mapbox/mapbox-gl-draw

Getting error on editing polygon(Invalid LngLat object: (NaN, NaN))

Open
#1,083 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged needs information
Dominant language
JavaScript
Stars
1.1k
Forks
612
Avg merge
8d 9h
Merged PRs (30d)
5

Description

Hi Team,
I added geojson polygon to map and i am trying to edit the polygon at this stage getting below error
Uncaught Error: Invalid LngLat object: (NaN, NaN)

case 2:
        {
            const lnglatall = figure.lnglatall,
                  coords = lnglatall.split('_');
            var ret = [], coord = [];
            coords.forEach(crd => 
            {
                if( crd.length > 0 )
                {
                    coord = crd.split(',');
                    ret.push(  [coord[1], coord[0]] );
                }                
            });            

            ret.push(ret[0]);

            figure_ = 
            {
                "id": figure.AutoIDx,
                "type": "Feature",
                "properties": {},
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [
                         ret  
                    ],                
                }
            }          
            
            lon_to_fly = ret[0][0];
            lat_to_fly = ret[0][1];            

            break;
        }
      }      
     
      console.log(  figure_  )
      this.last_id_toEdit  = this.draw.add(  figure_ );
      this.draw.setFeatureProperty(this.last_id_toEdit, 'portColor', this.color_hex);

The polygon is drawn  on the map but when is editted throws the errot described.

Any help please?

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 by reproducing the polygon edit path around this.draw.add(figure_) and the conversion of figure.lnglatall into ret. Inspect the generated figure_ and coordinate values before editing; done means identifying the source of the NaN values and confirming that editing the polygon no longer throws the Invalid LngLat error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.