Skip to content

Commit 3fdea0d

Browse files
authored
Default attribution (#3618)
* Set attribution to be on by default * Update logo * Fix lint * Add changelog * Fixed tests * Update change log, update map API * Update README.md * Fix build and definitions * Add more time to test * Updated a note about attribution * reduce changes in tests * Revert icon change * revert size change, add logo example * revert unneeded changes
1 parent 8ce93cb commit 3fdea0d

File tree

10 files changed

+145
-233
lines changed

10 files changed

+145
-233
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### ✨ Features and improvements
44

5+
- ⚠️ Change attribution to be on by default, change `MapOptions.attributionControl` to be the type that the control handles, removed `MapOptions.customAttribution` ([#3618](https://github.com/maplibre/maplibre-gl-js/issues/3618))
6+
Note: showing the logo of MapLibre is not required for using MapLibre.
57
- ⚠️ Changed cooperative gesture config and removed the strings from it in favor of the locale variable ([#3621](https://github.com/maplibre/maplibre-gl-js/issues/3621))
68
- ⚠️ Changed the terrain enable disable locale key to match the other keys' styles, updated the typings to allow using locale with more ease ([#3621](https://github.com/maplibre/maplibre-gl-js/issues/3621))
79
- Add "opacity" option and "setOpacity" method to Marker ([#3620](https://github.com/maplibre/maplibre-gl-js/pull/3620))
@@ -13,6 +15,7 @@
1315
## 4.0.0-pre.5
1416

1517
### ✨ Features and improvements
18+
1619
- ⚠️ Remove all global getters and setters from `maplibregl`, this means the the following methods have changed:
1720
`maplibregl.version` => `getVersion()`
1821
`maplibregl.workerCount` => `getWorkerCount()`, `setWorkerCount(...)`
@@ -21,6 +24,7 @@
2124
This is to avoid the need to use a global object and allow named exports/imports ([#3601](https://github.com/maplibre/maplibre-gl-js/issues/3601))
2225

2326
### 🐞 Bug fixes
27+
2428
- Fix wheel zoom to be into the same direction above or under the horizon ([#3398](https://github.com/maplibre/maplibre-gl-js/issues/3398))
2529
- Fix _cameraForBoxAndBearing not fitting bounds properly when using asymettrical camera viewport and bearing.
2630

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
![MapLibre Logo](https://maplibre.org/img/maplibre-logo-big.svg)
1+
<p align="center">
2+
<img src="https://maplibre.org/img/maplibre-logo-big.svg" alt="MapLibre Logo">
3+
</p>
24

35
# MapLibre GL JS
46

src/css/svg/maplibregl-ctrl-logo.svg

Lines changed: 10 additions & 85 deletions
Loading

src/ui/control/attribution_control.test.ts

Lines changed: 106 additions & 129 deletions
Large diffs are not rendered by default.

src/ui/control/attribution_control.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {StyleSpecification} from '@maplibre/maplibre-gl-style-spec';
77
/**
88
* The {@link AttributionControl} options object
99
*/
10-
type AttributionControlOptions = {
10+
export type AttributionControlOptions = {
1111
/**
1212
* If `true`, the attribution control will always collapse when moving the map. If `false`,
1313
* force the expanded attribution control. The default is a responsive attribution that collapses when the user moves the map on maps less than 640 pixels wide.
@@ -20,6 +20,11 @@ type AttributionControlOptions = {
2020
customAttribution?: string | Array<string>;
2121
};
2222

23+
export const defaultAtributionControlOptions: AttributionControlOptions = {
24+
compact: true,
25+
customAttribution: '<a href="https://maplibre.org/" target="_blank">MapLibre</a>'
26+
};
27+
2328
/**
2429
* An `AttributionControl` control presents the map's attribution information. By default, the attribution control is expanded (regardless of map width).
2530
* @group Markers and Controls
@@ -34,7 +39,7 @@ type AttributionControlOptions = {
3439
export class AttributionControl implements IControl {
3540
options: AttributionControlOptions;
3641
_map: Map;
37-
_compact: boolean;
42+
_compact: boolean | undefined;
3843
_container: HTMLElement;
3944
_innerContainer: HTMLElement;
4045
_compactButton: HTMLElement;
@@ -46,7 +51,7 @@ export class AttributionControl implements IControl {
4651
/**
4752
* @param options - the attribution options
4853
*/
49-
constructor(options: AttributionControlOptions = {}) {
54+
constructor(options: AttributionControlOptions = defaultAtributionControlOptions) {
5055
this.options = options;
5156
}
5257

@@ -57,7 +62,7 @@ export class AttributionControl implements IControl {
5762
/** {@inheritDoc IControl.onAdd} */
5863
onAdd(map: Map) {
5964
this._map = map;
60-
this._compact = this.options && this.options.compact;
65+
this._compact = this.options.compact;
6166
this._container = DOM.create('details', 'maplibregl-ctrl maplibregl-ctrl-attrib');
6267
this._compactButton = DOM.create('summary', 'maplibregl-ctrl-attrib-button', this._container);
6368
this._compactButton.addEventListener('click', this._toggleAttribution);

src/ui/default_locale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const defaultLocale = {
55
'FullscreenControl.Exit': 'Exit fullscreen',
66
'GeolocateControl.FindMyLocation': 'Find my location',
77
'GeolocateControl.LocationNotAvailable': 'Location not available',
8-
'LogoControl.Title': 'Mapbox logo',
8+
'LogoControl.Title': 'MapLibre logo',
99
'NavigationControl.ResetBearing': 'Reset bearing to north',
1010
'NavigationControl.ZoomIn': 'Zoom in',
1111
'NavigationControl.ZoomOut': 'Zoom out',

src/ui/map.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {Camera, CameraOptions, CameraUpdateTransformFunction, FitBoundsOptions}
1515
import {LngLat} from '../geo/lng_lat';
1616
import {LngLatBounds} from '../geo/lng_lat_bounds';
1717
import Point from '@mapbox/point-geometry';
18-
import {AttributionControl} from './control/attribution_control';
18+
import {AttributionControl, AttributionControlOptions, defaultAtributionControlOptions} from './control/attribution_control';
1919
import {LogoControl} from './control/logo_control';
2020
import {RGBAImage} from '../util/image';
2121
import {Event, ErrorEvent, Listener} from '../util/evented';
@@ -91,14 +91,12 @@ export type MapOptions = {
9191
*/
9292
bearingSnap?: number;
9393
/**
94-
* If `true`, an {@link AttributionControl} will be added to the map.
95-
* @defaultValue true
96-
*/
97-
attributionControl?: boolean;
98-
/**
99-
* Attribution text to show in an {@link AttributionControl}. Only applicable if `options.attributionControl` is `true`.
94+
* If set, an {@link AttributionControl} will be added to the map with the provided options.
95+
* To disable the attribution control, pass `false`.
96+
* Note: showing the logo of MapLibre is not required for using MapLibre.
97+
* @defaultValue compact: true, customAttribution: "MapLibre ...".
10098
*/
101-
customAttribution?: string | Array<string>;
99+
attributionControl?: false | AttributionControlOptions;
102100
/**
103101
* If `true`, the MapLibre logo will be shown.
104102
* @defaultValue false
@@ -371,7 +369,7 @@ const defaultOptions = {
371369
pitchWithRotate: true,
372370

373371
hash: false,
374-
attributionControl: true,
372+
attributionControl: defaultAtributionControlOptions,
375373
maplibreLogo: false,
376374

377375
failIfMajorPerformanceCaveat: false,
@@ -658,7 +656,7 @@ export class Map extends Camera {
658656
if (options.style) this.setStyle(options.style, {localIdeographFontFamily: options.localIdeographFontFamily});
659657

660658
if (options.attributionControl)
661-
this.addControl(new AttributionControl({customAttribution: options.customAttribution}));
659+
this.addControl(new AttributionControl(typeof options.attributionControl === 'boolean' ? undefined : options.attributionControl));
662660

663661
if (options.maplibreLogo)
664662
this.addControl(new LogoControl(), options.logoPosition);

test/build/min.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('test min build', () => {
3636
const decreaseQuota = 4096;
3737

3838
// feel free to update this value after you've checked that it has changed on purpose :-)
39-
const expectedBytes = 772550;
39+
const expectedBytes = 773333;
4040

4141
expect(actualBytes - expectedBytes).toBeLessThan(increaseQuota);
4242
expect(expectedBytes - actualBytes).toBeLessThan(decreaseQuota);

test/examples/simple-map.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
container: 'map', // container id
2020
style: 'https://demotiles.maplibre.org/style.json', // style URL
2121
center: [0, 0], // starting position [lng, lat]
22-
zoom: 1 // starting zoom
22+
zoom: 1, // starting zoom
23+
maplibreLogo: true
2324
});
2425
</script>
2526
</body>

test/integration/render/tests/text-variable-anchor/pitched-with-map/style.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"metadata": {
44
"test": {
55
"height": 256,
6-
"operations": [["idle"], ["wait", 100]]
6+
"operations": [["idle"], ["wait", 500]]
77
}
88
},
99
"center": [

0 commit comments

Comments
 (0)