Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add custom layer #849

Closed
jvntf opened this issue Jul 17, 2019 · 4 comments
Closed

Cannot add custom layer #849

jvntf opened this issue Jul 17, 2019 · 4 comments

Comments

@jvntf
Copy link

jvntf commented Jul 17, 2019

Version: 5.0.0
Problem: I am unable to add a custom layer to a map (using StaticMap) inside of a DeckGL framework. I get an error that a source must be specified and that type: custom is not supported

class threeJSModel{
        constructor(){
          this.id='custom_layer';
          this.type='custom';
          this.renderingMode = '3d'
        }
        onAdd(map, gl) {
            //create 3JS scene here
        }

        render(gl, matrix) {
            //render the scene
        }
    }

and then I add it to the map as follows:

const mapStyle = defaultMapStyle
      .set('layers', defaultMapStyle.get('layers').push(fromJS(new threeJSModel())))
this.setState({mapStyle})
<StaticMap
             ref = {this._mapRef}
             reuseMaps
             mapStyle={this.state.mapStyle}
             preventStyleDiffing={true}
             mapboxApiAccessToken={MAPBOX_TOKEN}
           />
        }
@mayteio
Copy link

mayteio commented Jul 17, 2019

Hey, it appears this is the same issue I was having yesterday! #848

Glad it's not just me.

@jvntf
Copy link
Author

jvntf commented Jul 17, 2019

hey @mayteio I have had some success with getMap().addLayer() to add my custom layer. It seems like react-map-gl doesn't directly support custom layers but you can access the mapbox-gl api this way and add your layer. It's not clean but seems ok for now

@mayteio
Copy link

mayteio commented Jul 17, 2019

Thanks @jvntf, I too have had the method mentioned working. I'd like to combine mapStyle (so I can make updates via redux) and the custom layers. I'm imagining if I use map.addLayer() then update the mapStyle object, the layer will disappear. Could be wrong though - will have a fiddle.

@ptbrowne
Copy link

ptbrowne commented May 2, 2022

Related to #1851

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants