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

map.addLayer() of layer having "ref" property throw a TypeError of <whatever_paint_property> undefined #3674

Closed
ggho opened this issue Nov 22, 2016 · 6 comments

Comments

@ggho
Copy link

ggho commented Nov 22, 2016

mapbox-gl-js version: 0.28.0

Steps to Trigger Behavior

  1. create a map object
  2. add a map layer with map.addLayer() that has "ref" property
  3. it will throws the TypeError

Codes snippet

//create a map object with source named <some_cource> and source layer named 
//<some_source_layer>
//...

map.addLayer({
    "id": "layer1",
    "type": "line",
    "source": <some_source>,
    "source-layer": <some_source_layer>,
    "paint": {
        "line-opacity": 0.7,
        "line-color": "#000000"
    }
});
// where error was thrown
map.addLayer({
    "id": "layer2",
    "ref": "layer1",
    "paint": {
       //this can be any other paint property
        "line-color": "#fab700"
    }
});

Expected Behavior

No errors thrown.

Actual Behavior

style_layer.js:117 Uncaught TypeError: Cannot read property 'line-color' of undefined
    at i.setPaintProperty (http://api.tiles.mapbox.com/mapbox-gl-js/v0.28.0/mapbox-gl.js:124:2558)
    at new i (http://api.tiles.mapbox.com/mapbox-gl-js/v0.28.0/mapbox-gl.js:124:1000)
    at Function.StyleLayer.create (http://api.tiles.mapbox.com/mapbox-gl-js/v0.28.0/mapbox-gl.js:124:6296)
    at t.addLayer (http://api.tiles.mapbox.com/mapbox-gl-js/v0.28.0/mapbox-gl.js:120:6605)
    at e.addLayer (http://api.tiles.mapbox.com/mapbox-gl-js/v0.28.0/mapbox-gl.js:204:7500)
    at HTMLSelectElement.selector.onchange (http://localhost:8000/:164:26)```

@ggho ggho changed the title map.addLayer() of layer having "ref" property throw a TypeError of 'line-color' undefined map.addLayer() of layer having "ref" property throw a TypeError of <whatever_paint_property> undefined Nov 22, 2016
@lucaswoj
Copy link
Contributor

Apologies about this error @ggho. This should have been listed as a breaking change in our release notes. I will update those now.

User-specified refs are no longer supported. If you include all the metadata and layout properties on both layers, the ref will be applied internally.

@lucaswoj
Copy link
Contributor

See #3486

@ggho
Copy link
Author

ggho commented Nov 23, 2016

@lucaswoj Thanks for the prompt reply! It explains a lot.

On the other hand, I also realised the "interactive" property is removed without being mentioned in the release note? That one is obvious to notice as error warnings popped out when I used it, the same error message did not happen for "ref" though.

@lucaswoj
Copy link
Contributor

@ggho interactive was removed back in March #1479

@ggho
Copy link
Author

ggho commented Nov 24, 2016

@lucaswoj Now I know thanks! I just couldn't find it in the release notes, just wonder if you would add it so others would know easier.

@sdawson26
Copy link

sdawson26 commented Apr 4, 2017

This issue has helped me understand why I couldn't get the rich version 9 map to load by means of addLayer() due to the "ref" field.

Are there any future plans to reincorporate this in future versions? We'd like to be able to add streets-v9 without having to put it in the root style and instead add the source after the map initializes.

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

3 participants