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

add support for GeoJSON attribution #6364

Merged
merged 1 commit into from
Jun 5, 2018
Merged

Conversation

andrewharvey
Copy link
Collaborator

@andrewharvey andrewharvey commented Mar 19, 2018

Launch Checklist

  • briefly describe the changes in this PR

adds support for custom attribution strings in GeoJSON sources. This implements the latter part of the discussion of #1485, but could be used as a workaround for the original issue by using a dummy GeoJSON source.

I think to close #1485 we would still need to allow custom attribution strings passed directly to the AttributionControl not attached to any source.

The Vector and Raster sources set their attribution properties via the shared TileJSON code, but since GeoJSON is loaded directly without a TileJSON, they need to be handled separately in the GeoJSON Source code.

  • write tests for all new functionality
  • document any changes to public APIs
  • N/A post benchmark scores
  • manually test the debug page

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation looks good to me. Thanks for adding tests 😸

@jfirebaugh seems like you were on board with adding this functionality in #1485 – does this work for you?

@@ -310,6 +310,10 @@
"default": 18,
"doc": "Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels)."
},
"attribution": {
"type": "string",
"doc": "Contains an attribution to be displayed when the map is shown to a user."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to explain here that this is added specifically to the AttributionControl

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style-spec is platform independent so I'd say best not to refer to the platform specific AttributionControl. What do you think?

That said, it should be consistent with the other sources that accept an attribution option like vector, raster and raster-dem sources. eg. https://www.mapbox.com/mapbox-gl-js/style-spec/#sources-vector-attribution so any change in this wording should apply to all the others too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point. 👍 to keep as is

@@ -110,6 +111,7 @@ class GeoJSONSource extends Evented implements Source {

if (options.maxzoom !== undefined) this.maxzoom = options.maxzoom;
if (options.type) this.type = options.type;
if (options.attribution) this.attribution = options.attribution;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we validate that options.attribution is a non-empty string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribution option is optional so is that needed? If the attribution option isn't provided, or if it's an empty string it won't set any attribution on the source and the AttributionControl won't add any attribution for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I was unclear– I was thinking of validating that it is a string (as opposed to another type) and that its "non-empty." I was thinking about just white space, not a true nonempty which would be truthy). the first part is already happening in the style validation code which I forgot, and I'm not sure its worth worrying about the white space case after all because we don't do that for any other style spec values. sorry for confusion!

Copy link
Collaborator Author

@andrewharvey andrewharvey Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right the style validation already spews out an error for a non-string value (handy if someone uses something like true by mistake. (Thanks for pointing that out by the way, I didn't actually realise it did that already)

As for white space, I'd say we allow it, if someone wants an attribution of "" or " " we should just comply.

@andrewharvey
Copy link
Collaborator Author

@mollymerp not sure if this slipped through the cracks, or it needed further changes? Thanks!

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⌛️ thanks for the ping! sorry for the delay. I think we can move forward with this feature.

@mollymerp mollymerp added cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) feature 🍏 labels Jun 4, 2018
@andrewharvey andrewharvey merged commit 560ca15 into master Jun 5, 2018
@andrewharvey andrewharvey deleted the geojson-attribution branch June 5, 2018 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) feature 🍏
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom attribution strings
2 participants