visgl / deck.gl

WebGL2 powered visualization framework
https://deck.gl
MIT License
12.22k stars 2.08k forks source link

Icons do not render on map #4929

Closed jerrywu28 closed 4 years ago

jerrywu28 commented 4 years ago

Description

I'm using react-map-gl with deck.gl, but am unable to get any icons to render on the page in spite of following the guide provided in the docs to a tee.

Repro Steps

I am importing the following dependencies to the component:

import React from 'react'; import DeckGL from '@deck.gl/react'; import { IconLayer, PathLayer } from '@deck.gl/layers';

The icon layer going into my layers' array, which is passed into <DeckGL layers={layers}> is built this way:

new IconLayer({
      id: 'icon-layer',
      data: destinations.map((destination) => {
        const { latitude, longitude } = destination.coordinates;
        return {
          address: destination.location.formatted_address,
          coordinates: [latitude, longitude],
          name: destination.name,
        };
      }),
      pickable: false,
      iconAtlas:
        'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/icon-atlas.png',
      iconMapping: {
        marker: { x: 0, y: 0, width: 128, height: 128, mask: true },
      },
      sizeScale: 20,
      getIcon: () => 'marker',
      getPosition: (d) => d.coordinates,
      getSize: () => 20,
      getColor: () => [125, 125, 125],
    });

Unfortunately, nothing appears on the map. It may be irrelevant, but I am able to get pathLayer working in the layers array without any issue.

Environment (please complete the following information):

Logs

Here's a screenshot of layers being console.logged before rendering. See shape of data in props.data[i].

Screen Shot 2020-09-10 at 8 36 07 AM
Pessimistress commented 4 years ago

DeckGL never received your layer. Please share the complete code of your React component if you would like help with debugging, ideally in a CodeSandbox.

jerrywu28 commented 4 years ago

Thanks for your quick response! I spun up a CodeSandbox for you, thanks for the extra pair of eyes on this:

https://codesandbox.io/s/priceless-kapitsa-pdwy9?file=/src/App.js

Edit: I should mention that it requires a MapBox API key on line 8 in Map.js. I didn't feel comfortable sharing my own in the sandbox.

Pessimistress commented 4 years ago

Coordinates need to be in [longitude, latitude] (GeoJSON convention).

jerrywu28 commented 4 years ago

That fixed it!