Mapbox-gl-js: deprecate source.load, style.load, etc to simplify + clarify eventing

Created on 13 Jan 2017  路  4Comments  路  Source: mapbox/mapbox-gl-js

per chat w @lucaswoj yesterday and with added motivation from #3958, we should simply eventing by removing all events that do not fall within the schema of the data events from #3590, and extending the current implementation to cover the use cases of the old events.

refactoring

Most helpful comment

yes and no :) because when I use styledata instead i get allot of error messages in the form of
image

in previous versions using style.load i was guaranteed I could add new sources and build my map back up again from scratch when the event got fired when switching styles. Note, that I could have just been lucky things didn't break :) But as far as I can tell there is no other event that only get called once when switching styles?

map.on('styledata', function () {

  map.addSource('markers', {
    type: 'geojson',
    data: markers,
    cluster: true,
    clusterMaxZoom: 14,
    clusterRadius: 30
  })

  map.addSource('traces', {
    type: 'geojson',
    data: traces
  })

  if (location.search.substring(1) !== '') {
    draw()
  } else {
    map.getSource('traces').setData(traces)
  }
  map.getSource('markers').setData(markers)
  paint()
  threadBuffer.postMessage(null)
  threadSPOT.postMessage(null)

}

All 4 comments

hmm I am unable to figure out how i should do the style.load event now? Tried load also.

example: (removed) press [+] to load new style, event doesn't get fired and when pressed again I get warning?

@gertcuykens style.load was never part of our public API. I believe the styledata event has the behaviour you're looking for.

yes and no :) because when I use styledata instead i get allot of error messages in the form of
image

in previous versions using style.load i was guaranteed I could add new sources and build my map back up again from scratch when the event got fired when switching styles. Note, that I could have just been lucky things didn't break :) But as far as I can tell there is no other event that only get called once when switching styles?

map.on('styledata', function () {

  map.addSource('markers', {
    type: 'geojson',
    data: markers,
    cluster: true,
    clusterMaxZoom: 14,
    clusterRadius: 30
  })

  map.addSource('traces', {
    type: 'geojson',
    data: traces
  })

  if (location.search.substring(1) !== '') {
    draw()
  } else {
    map.getSource('traces').setData(traces)
  }
  map.getSource('markers').setData(markers)
  paint()
  threadBuffer.postMessage(null)
  threadSPOT.postMessage(null)

}

Thanks for the heads-up about that caveat to styledata @gertcuykens. We will fix that in conjunction with deprecating style.load.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevage picture stevage  路  3Comments

mollymerp picture mollymerp  路  3Comments

bgentry picture bgentry  路  3Comments

aendrew picture aendrew  路  3Comments

aderaaij picture aderaaij  路  3Comments