mgl-feature in mgl-geojson-source is not rendering

Viewed 242

It seems that I am not able to display the points in those components. I am using the following:

<mgl-map> // removed unnecessary attributes, map is displayed correctly
      <mgl-geojson-source id="branch-points">
          <mgl-feature
              *ngFor="let geometry of branchData"
              [geometry]="geometry">
          </mgl-feature>
      </mgl-geojson-source>
</mgl-map>

my geometry object looks like this:

{
    coordinates: [
        branch.geolocation.lat,
        branch.geolocation.long,
    ],
    type: 'Point',
}

What am I doing wrong?

2 Answers

In order for the mgl-feature to work correctly, you need to provide a value for its id attribute. You can, for instance, get the index of each element in the branchData and use that as an id, as in the example below.

<mgl-map>
      <mgl-geojson-source id="branch-points">
          <mgl-feature
              *ngFor="let geometry of branchData; index as i"
              [id]="i"
              [geometry]="geometry">
          </mgl-feature>
      </mgl-geojson-source>
</mgl-map>

Actually my implementation of the geojson is completely correct. You only have to add the corresponding layer or your geojson will not render :)

Related