mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.2k stars 2.22k forks source link

deprecate style.load, etc to simplify + clarify eventing #3970

Open mollymerp opened 7 years ago

mollymerp commented 7 years ago

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.

gertcuykens commented 7 years ago

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?

lucaswoj commented 7 years ago

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

gertcuykens commented 7 years ago

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)

}
lucaswoj commented 7 years ago

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

ryanhamley commented 2 years ago

Updating issue name since source.load is no longer an event