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

Attribution default open for osm #795

Merged
merged 50 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0b81a41
Update CHANGELOG.md
acalcutt Dec 6, 2021
2192c1d
Revert "Update CHANGELOG.md"
acalcutt Dec 6, 2021
2031d8e
attribution fixes (from astridx)
acalcutt Dec 6, 2021
032b16e
Update .gitignore
acalcutt Dec 7, 2021
711436a
fix missing new line lint complained about
acalcutt Dec 7, 2021
41be4b5
Merge branch 'maplibre:main' into main
acalcutt Dec 8, 2021
629e818
Merge branch 'maplibre:main' into main
acalcutt Dec 9, 2021
c68a94c
Merge branch 'maplibre:main' into main
acalcutt Dec 11, 2021
53d97eb
Revert "attribution fixes (from astridx)"
acalcutt Dec 11, 2021
46bed6a
Merge branch 'maplibre:main' into main
acalcutt Dec 17, 2021
24af518
Merge branch 'maplibre:main' into main
acalcutt Dec 21, 2021
8f9d5e7
Merge branch 'maplibre:main' into main
acalcutt Dec 23, 2021
1fa7cdc
Merge branch 'maplibre:main' into main
acalcutt Jan 6, 2022
73a16d8
Merge branch 'maplibre:main' into main
acalcutt Jan 13, 2022
c1967e5
Merge branch 'maplibre:main' into main
acalcutt Jan 15, 2022
ef5263b
Merge branch 'maplibre:main' into main
acalcutt Jan 16, 2022
4816eca
Default compact to be open by default
acalcutt Jan 17, 2022
5e7faeb
remove test string I forgot to remove
acalcutt Jan 17, 2022
48f7452
fix compact button showing when there are no attributions
acalcutt Jan 17, 2022
34204f0
update whitespace trim to es6 syntax
acalcutt Jan 17, 2022
a5dfd8d
fixes after testing various states of compact
acalcutt Jan 17, 2022
7d510f9
revert back so it is open when starting in fullscreen
acalcutt Jan 17, 2022
4aeab51
Merge branch 'maplibre:main' into main
acalcutt Jan 19, 2022
f2715c7
revert .gitignore
acalcutt Jan 19, 2022
a33ada3
fix lint errors
acalcutt Jan 20, 2022
195d336
fix tests
acalcutt Jan 20, 2022
d164ea4
Merge branch 'maplibre:main' into main
acalcutt Jan 20, 2022
dcb7716
Merge branch 'maplibre:main' into main
acalcutt Jan 22, 2022
f95b423
Merge branch 'maplibre:main' into main
acalcutt Jan 26, 2022
e900811
Merge branch 'maplibre:main' into main
acalcutt Jan 27, 2022
c290445
Merge branch 'maplibre:main' into main
acalcutt Jan 28, 2022
ec241a6
Merge branch 'maplibre:main' into main
acalcutt Feb 4, 2022
57d2726
Merge branch 'main' into attribution_default_open_for_osm
acalcutt Feb 5, 2022
149e5d2
lint
acalcutt Feb 5, 2022
d74ee59
Merge branch 'maplibre:main' into main
acalcutt Feb 5, 2022
6f1c4de
Update package-lock.json
acalcutt Feb 5, 2022
75e4379
Merge branch 'main' into attribution_default_open_for_osm
acalcutt Feb 5, 2022
580f2d9
Update package-lock.json
acalcutt Feb 5, 2022
6988164
Merge branch 'maplibre:main' into main
acalcutt Feb 5, 2022
77f1c33
Merge branch 'main' into attribution_default_open_for_osm
acalcutt Feb 6, 2022
c16cfe3
Update CHANGELOG.md
acalcutt Feb 6, 2022
90f048f
Merge remote-tracking branch 'maplibre/main' into attribution_default…
acalcutt Feb 6, 2022
82ea91a
Merge remote-tracking branch 'maplibre/main' into attribution_default…
acalcutt Feb 6, 2022
a04eb80
Merge branch 'maplibre:main' into main
acalcutt Feb 6, 2022
0d30003
Merge branch 'main' into attribution_default_open_for_osm
acalcutt Feb 6, 2022
49afc66
Merge remote-tracking branch 'maplibre/main' into attribution_default…
acalcutt Feb 8, 2022
1f1bb67
delete problematic files
acalcutt Feb 8, 2022
86d90b2
put back deleted files
acalcutt Feb 8, 2022
f09f1b7
test/integration/assets/sprites/icon-text-fit-1x@2x.json
acalcutt Feb 8, 2022
757f0d4
restore files
acalcutt Feb 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

### Features and improvements

- Default compact attribution to be open by default to comply with OpenSteetMap Attribution Guidelines (#795)
- Export `Source` classes (`GeoJSONSource` etc.) declarations. ([#801](https://github.com/maplibre/maplibre-gl-js/issues/801))
- Make `AJAXError` public so error HTTP responses can be handled differently from other errors.
- *...Add new stuff here...*

### 🐞 Bug fixes

- Fix compact attribution button showing when attribution is blank (#795)
- Fix error mismatched image size for CJK characters (#718)
- Fire `dataabort` and `sourcedataabort` events when a tile request is aborted (#794)
- *...Add new stuff here...*
Expand Down
53 changes: 44 additions & 9 deletions src/ui/control/attribution_control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('AttributionControl', () => {
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});

let attributionControl = new AttributionControl({
compact: true
compact: true,
customAttribution: 'MapLibre'
});
map.addControl(attributionControl);

Expand All @@ -73,7 +74,32 @@ describe('AttributionControl', () => {
).toHaveLength(1);
});

test('appears in compact mode if container is less then 640 pixel wide', () => {
test('appears in compact mode if container is less then 640 pixel wide and attributions are not empty', () => {
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
const attributionControl = new AttributionControl({
customAttribution: 'MapLibre'
});
map.addControl(attributionControl);

const container = map.getContainer();

expect(
container.querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')
).toHaveLength(1);

Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 600, configurable: true});
map.resize();

expect(
container.querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')
).toHaveLength(1);

expect(
container.querySelectorAll('.maplibregl-attrib-empty')
).toHaveLength(0);
});

test('does not appear in compact mode if container is less then 640 pixel wide and attributions are empty', () => {
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
map.addControl(new AttributionControl());

Expand All @@ -88,26 +114,31 @@ describe('AttributionControl', () => {

expect(
container.querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')
).toHaveLength(0);

expect(
container.querySelectorAll('.maplibregl-attrib-empty')
).toHaveLength(1);
});

test('compact mode control toggles attribution', () => {
map.addControl(new AttributionControl({
compact: true
compact: true,
customAttribution: 'MapLibre'
}));

const container = map.getContainer();
const toggle = container.querySelector('.maplibregl-ctrl-attrib-button');

expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(0);
expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(1);

simulate.click(toggle);

expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(1);
expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(0);

simulate.click(toggle);

expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(0);
expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(1);
});

test('dedupes attributions that are substrings of others', done => {
Expand Down Expand Up @@ -325,23 +356,27 @@ describe('AttributionControl test regarding the HTML elements details and summar
expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');
});

test('The attribute open="" SHOULD change on resize from size > 640 to <= 640 and and vice versa.', () => {
test('The attribute open="" SHOULD exist after resize from size > 640 to <= 640 and and vice versa.', () => {
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 640, configurable: true});
const attributionControl = new AttributionControl({
customAttribution: 'MapLibre'
});
map.addControl(attributionControl);

expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBeNull();
expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')).toHaveLength(1);
expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');

Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 641, configurable: true});
map.resize();

expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')).toHaveLength(1);
expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');

Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 640, configurable: true});
map.resize();

expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBeNull();
expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')).toHaveLength(1);
expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');
});

test('The attribute open="" should NOT change on resize from > 640 to another > 640.', () => {
Expand Down
47 changes: 33 additions & 14 deletions src/ui/control/attribution_control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type AttributionOptions = {
class AttributionControl implements IControl {
options: AttributionOptions;
_map: Map;
_compact: boolean;
_container: HTMLElement;
_innerContainer: HTMLElement;
_compactButton: HTMLElement;
Expand All @@ -39,7 +40,8 @@ class AttributionControl implements IControl {
bindAll([
'_toggleAttribution',
'_updateData',
'_updateCompact'
'_updateCompact',
'_updateCompactMinimize'
], this);
}

Expand All @@ -49,18 +51,20 @@ class AttributionControl implements IControl {

onAdd(map: Map) {
this._map = map;
this._compact = this.options && this.options.compact;
this._container = DOM.create('details', 'maplibregl-ctrl maplibregl-ctrl-attrib mapboxgl-ctrl mapboxgl-ctrl-attrib');
this._compactButton = DOM.create('summary', 'maplibregl-ctrl-attrib-button mapboxgl-ctrl-attrib-button', this._container);
this._compactButton.addEventListener('click', this._toggleAttribution);
this._setElementTitle(this._compactButton, 'ToggleAttribution');
this._innerContainer = DOM.create('div', 'maplibregl-ctrl-attrib-inner mapboxgl-ctrl-attrib-inner', this._container);

this._updateCompact();
this._updateAttributions();
this._updateCompact();

this._map.on('styledata', this._updateData);
this._map.on('sourcedata', this._updateData);
this._map.on('resize', this._updateCompact);
this._map.on('drag', this._updateCompactMinimize);

return this._container;
}
Expand All @@ -71,8 +75,10 @@ class AttributionControl implements IControl {
this._map.off('styledata', this._updateData);
this._map.off('sourcedata', this._updateData);
this._map.off('resize', this._updateCompact);
this._map.off('drag', this._updateCompactMinimize);

this._map = undefined;
this._compact = undefined;
this._attribHTML = undefined;
}

Expand All @@ -83,10 +89,14 @@ class AttributionControl implements IControl {
}

_toggleAttribution() {
if (this._container.classList.contains('maplibregl-compact-show') || this._container.classList.contains('mapboxgl-compact-show')) {
this._container.classList.remove('maplibregl-compact-show', 'mapboxgl-compact-show');
} else {
this._container.classList.add('maplibregl-compact-show', 'mapboxgl-compact-show');
if (this._container.classList.contains('maplibregl-compact')) {
if (this._container.classList.contains('maplibregl-compact-show')) {
this._container.setAttribute('open', '');
this._container.classList.remove('maplibregl-compact-show', 'mapboxgl-compact-show');
} else {
this._container.classList.add('maplibregl-compact-show', 'mapboxgl-compact-show');
this._container.removeAttribute('open');
}
}
}

Expand Down Expand Up @@ -129,6 +139,9 @@ class AttributionControl implements IControl {
}
}

// remove any entries that are whitespace
attributions = attributions.filter(e => String(e).trim());

// remove any entries that are substrings of another entry.
// first sort by length so that substrings come first
attributions.sort((a, b) => a.length - b.length);
Expand All @@ -151,20 +164,18 @@ class AttributionControl implements IControl {
} else {
this._container.classList.add('maplibregl-attrib-empty', 'mapboxgl-attrib-empty');
}
this._updateCompact();
// remove old DOM node from _editLink
this._editLink = null;
}

_updateCompact() {
const compact = this.options && this.options.compact;
if (this._map.getCanvasContainer().offsetWidth <= 640 || compact) {
if (compact === false) {
if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
if (this._compact === false) {
this._container.setAttribute('open', '');
} else {
if (!this._container.classList.contains('maplibregl-compact')) {
this._container.removeAttribute('open');
this._container.classList.add('maplibregl-compact', 'mapboxgl-compact');
}
} else if (!this._container.classList.contains('maplibregl-compact') && !this._container.classList.contains('maplibregl-attrib-empty')) {
this._container.setAttribute('open', '');
this._container.classList.add('maplibregl-compact', 'mapboxgl-compact', 'maplibregl-compact-show', 'mapboxgl-compact-show');
}
} else {
this._container.setAttribute('open', '');
Expand All @@ -174,6 +185,14 @@ class AttributionControl implements IControl {
}
}

_updateCompactMinimize() {
if (this._container.classList.contains('maplibregl-compact')) {
if (this._container.classList.contains('maplibregl-compact-show')) {
this._container.classList.remove('maplibregl-compact-show', 'mapboxgl-compact-show');
}
}
}

}

export default AttributionControl;