-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[android] - derived source attribution #8630
Conversation
b4bbbb3
to
3688cf2
Compare
It seems we need some additional logic here, currently attribution for digital globe when using a satellite map shows up under |
“Improve This Map” should appear before DigitalGlobe. (This screenshot is outdated.) |
|
||
private void parseAttribution(String attributionSource) { | ||
if (!TextUtils.isEmpty(attributionSource)) { | ||
SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attributionSource); |
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.
Could you characterize the HTML parser being used here? fromHtml(String)
doesn’t say anything about which tags it supports, what encoding it uses, whether it attempts to load external images, etc. fromHtml(String, int)
mentions TagSoup, but I don’t know if it’s also the case with this older API.
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.
They use TagSoup underneath. With current design there isn't any possibility of icon placement though the API support it with an ImageGetter https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler.
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.
No external icon support is perfectly fine. I just wanted to double-check because the use of HTML in attribution has been problematic for GL JS and mapbox.js, mostly concerning XSS risk.
private void rebuildAttributionMap() { | ||
attributionMap = new LinkedHashMap<>(); | ||
for (Source source : mapboxMap.getSources()) { | ||
parseAttribution(source.getAttribution()); |
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.
This implementation doesn’t attempt to deduplicate copyright notices that appear redundantly in multiple sources. For example, the Mapbox Streets and Mapbox Satellite sources both credit OpenStreetMap, so “© OpenStreetMap” would probably appear twice in the dialog when viewing the Mapbox Satellite Streets style.
You may want to adapt the logic used on iOS and macOS or alternatively the GL JS implementation. Both implementations come with plenty of unit tests as well.
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.
A map collection cannot contain duplicate keys so this solves the issues of duplicate entries. Is there a use-case that I'm a not supporting with not implementing // remove any entries that are substrings of another entry
.?
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 logic was originally implemented in GL JS in mapbox/mapbox-gl-js#2453. I guess it’s meant to avoid “© OpenStreetMap contributors © OpenStreetMap” or somesuch, not sure.
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.
I think what you’ve got should be fine when it comes to the Mapbox default styles at least. None of the sources ultimately loaded by Mapbox Streets or Mapbox Satellite Streets have any links whose texts differ but overlap.
<array name="mapbox_attribution_links" formatted="false" translatable="false"> | ||
<item>https://www.mapbox.com/about/maps/</item> | ||
<item>http://www.openstreetmap.org/about/</item> | ||
<item>https://www.mapbox.com/map-feedback/#/%1$f/%2$f/%3$d</item> |
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.
The iOS, macOS, and JS implementations automatically append this hash to the feedback URL. That way, the Map Feedback tool starts out at the right location, which makes their feedback much more actionable. The feedback link has a class
attribute of mapbox-improve-map
.
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 got lost, will readd
3688cf2
to
9111e42
Compare
Fixed up @1ec5 comment about improving this map, did a cleanup and is ready for review. |
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.
👍
@@ -43,6 +43,10 @@ namespace android { | |||
return jni::Make<jni::String>(env, source.getID()); | |||
} | |||
|
|||
jni::String Source::getAttribution(jni::JNIEnv& env) { | |||
return source.getAttribution() ? jni::Make<jni::String>(env, source.getAttribution().value()) : jni::Make<jni::String>(env,""); |
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.
Minor thing, but maybe invoke source.getAttribution()
only once. Now it doesn't really do much, but if the implementation gets more complex it's a bit wasteful.
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.
done in 527ffbe#diff-8a5300c6fbc51b88f2e971461adcb513R33. re-review that part of the code?
import java.util.LinkedHashMap; | ||
import java.util.Locale; | ||
|
||
class AttributionDialogManager implements View.OnClickListener, DialogInterface.OnClickListener { |
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.
Nit; some class level javadoc?
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.
9111e42
to
527ffbe
Compare
*/ | ||
class AttributionDialogManager implements View.OnClickListener, DialogInterface.OnClickListener { | ||
|
||
private static final String MAP_FEEDBACK_URL = "https://www.mapbox.com/map-feedback"; |
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.
We shouldn’t hard-code this URL, because sources other than Mapbox Streets are free to provide their own map feedback URLs. Look for <a>
tags with class
set to mapbox-improve-map
.
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.
I ticketed this out as tail work in #8730, since custom feedback links are admittedly quite an edge case.
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.
Thank you for ticketing that out, will fix it separately from this PR.
527ffbe
to
a70febf
Compare
a70febf
to
4e01377
Compare
Closes #2723