-
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
Dedupe attributions that are substrings of others #2453
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,29 @@ | |
|
||
new mapboxgl.Attribution({position: 'top-left'}) | ||
.addTo(map); | ||
|
||
map.on('style.load', function () { | ||
map.addSource('foo', new mapboxgl.GeoJSONSource({ | ||
data: { | ||
type: 'FeatureCollection', features: [] | ||
} | ||
})); | ||
map.style.sources.foo.attribution = '<a href="https://www.mapbox.com/about/maps/" target="_blank">© Mapbox</a> <a href="http://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap</a> <a class="mapbox-improve-map" href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a> © Someone else like DG' | ||
|
||
map.addSource('bar', new mapboxgl.GeoJSONSource({ | ||
data: { | ||
type: 'FeatureCollection', features: [] | ||
} | ||
})); | ||
map.style.sources.bar.attribution = 'Another Source'; | ||
|
||
map.addSource('baz', new mapboxgl.GeoJSONSource({ | ||
data: { | ||
type: 'FeatureCollection', features: [] | ||
} | ||
})); | ||
map.style.sources.baz.attribution = 'Another Source'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is anything blocking us from creating automated unit tests for this code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I meant to mention this in the PR: I looked and didn't find any other unit tests for |
||
}); | ||
</script> | ||
</body> | ||
</html> |
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.
Why do you sort the attributions before filtering them?
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.
@lucaswoj i figured sorting the list first means that, in the filter function for the
i-th
item, you can safely start the loop ati+1
. Without this, you have to check every item, and I think it gets a little weird to correctly filter out exact duplicates.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.
Whether you sort or not, you're comparing every attribution string to every other attribution string. I don't think the sort is necessary.
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.
Agreed, but it's also directional, since we're looking for a substring match and want to keep the longer of the two if there's a match.
I agree the sort isn't necessary, but removing it does make the logic in the filter function a little more particular... I think it would then need to be something like:
@lucaswoj I considered this, and ended up feeling that both approaches were equally bad... lemme know if you find this way clearer and I can change it
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.
That's a good point. We should sort by length not alphabetic ordering, then.