-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Revise addSourceType to be independent of Map instance #2982
Conversation
I'm going to revise this a bit so that it can address #3004 |
a5ccc4f
to
9438bc4
Compare
@lucaswoj ^ revised this to be a more comprehensive solution. Ready for your 👀 |
(also edited the top of the ticket) |
Here is a working example of the API that this change affords: https://github.com/developmentseed/mapbox-gl-topojson/blob/gh-pages/site.js |
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
@@ -202,6 +203,11 @@ var Map = module.exports = function(options) { | |||
this.resize(); | |||
|
|||
if (options.classes) this.setClasses(options.classes); | |||
if (options.sourceTypes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name it customSourceTypes
to reflect that we supply those additionally to the core ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, but I also don't have a strong opinion on this.
This generally looks good to me! |
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
Revise addSourceType to be independent of Map instance
@@ -14,6 +14,7 @@ mapboxgl.Popup = require('./ui/popup'); | |||
mapboxgl.Marker = require('./ui/marker'); | |||
|
|||
mapboxgl.Style = require('./style/style'); | |||
mapboxgl.Source = require('./source/source'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we expose mapboxgl.addSourceType
instead of the whole Source
module? There are lots of bits & pieces in Source
that we don't want to be public.
5dae4c7
to
5889145
Compare
5889145
to
b632c7d
Compare
Rebased, and updated to leverage the global worker pool. Two key notes:
|
Revise addSourceType to be independent of Map instance
Since `addSourceType` adds the source type to a static map, it was yielding an error if two map instances tried to add the same source type. This changes `addSourceType(name, SourceType)` to simply do nothing if there is already a source type named `name`.
98b7e28
to
9d5a87e
Compare
Rebased |
I'm coming to see the wisdom behind GL Native's custom layer architecture. Instead of defining custom source types, we should accept custom source objects which conform to a given interface specification. map.addCustomSource('foo', new WhizzBangSource({...})) The benefits of this approach include
One downside is that we'll need to find a way to register worker-side logic without the existence of source "types". Does this seem doable @anandthakker? Would it be more doable if we implemented #3034? Overall, does implementing this architecture sound doable within the scope of this PR? |
@lucaswoj This is interesting! I actually don't think it would be too difficult to deal with registering worker-side code; we'd just need an API like However, one drawback to this no-types approach is that it basically seals the deal against specifying custom sources (and their dependent style layers) declaratively with style json like |
It's a tradeoff for sure. We are giving up some ergonomics in exchange for simplicity, uniformity with GL Native, and the preservation of a tight validator. I prefer to err on the side of simplicity and see how things shake out in practice. Down the road we may revisit the "register source type" design or a design that allows embedding |
Gotcha. I think the change from addSourceType-based to addCustomSource-based API should be reasonably manageable, but definitely makes more sense to do after the |
Revise addSourceType to be independent of Map instance
We are going to go a different direction for this functionality: #3004 |
Closes #3004
The problem:
addSourceType
does not quite make sense as a method on the Map (or Style) instance, because: a) Sources, being types, are really 'global'; b) practically speaking, there are problems having this as an instance method, because that approach fails to coordinate setting up the WorkerSources for other map instances.Changes:
Map#addSourceType
andStyle#addSourceType
with the staticSource.addType
-- exported asmapboxgl.addSourceType
. Leveraging the global worker pool, this method can now directly take care of registering the WorkerSource for the added source type if necessary.Checklist
master