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

Fix attribution control bug #85

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
### Bug Fixes
### Others

## 2.0.3
### Bug Fixes
- Fixed issue in attribution control

## 2.0.2
### Bug Fixes
- Fix for the client-side caching breaking GeoJSON sources [#82](https://github.com/maptiler/maptiler-sdk-js/pull/82)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maptiler/sdk",
"version": "2.0.2",
"version": "2.0.3",
"description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud",
"module": "dist/maptiler-sdk.mjs",
"types": "dist/maptiler-sdk.d.ts",
Expand Down
32 changes: 21 additions & 11 deletions src/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
StyleSetterOptions,
ExpressionSpecification,
SymbolLayerSpecification,
AttributionControlOptions,
} from "maplibre-gl";
import { ReferenceMapStyle, MapStyleVariant } from "@maptiler/client";
import { config, MAPTILER_SESSION_ID, SdkConfig } from "./config";
Expand All @@ -35,7 +36,6 @@ import { MaptilerTerrainControl } from "./MaptilerTerrainControl";
import { MaptilerNavigationControl } from "./MaptilerNavigationControl";
import { geolocation } from "@maptiler/client";
import { MaptilerGeolocateControl } from "./MaptilerGeolocateControl";
import { AttributionControl } from "./MLAdapters/AttributionControl";
import { ScaleControl } from "./MLAdapters/ScaleControl";
import { FullscreenControl } from "./MLAdapters/FullscreenControl";

Expand Down Expand Up @@ -205,13 +205,32 @@ export class Map extends maplibregl.Map {
);
}

// default attribution control options
let attributionControlOptions = {
compact: false,
} as AttributionControlOptions;
if (options.customAttribution) {
attributionControlOptions.customAttribution = options.customAttribution;
} else if (
options.attributionControl &&
typeof options.attributionControl === "object"
) {
attributionControlOptions = {
...attributionControlOptions,
...options.attributionControl,
};
}

// calling the map constructor with full length style
super({
...options,
style,
maplibreLogo: false,
transformRequest: combineTransformRequest(options.transformRequest),
...(options.attributionControl ?? { attributionControl: false }),
attributionControl:
options.forceNoAttributionControl === true
? false
: attributionControlOptions,
});

if (config.caching) {
Expand Down Expand Up @@ -377,15 +396,6 @@ export class Map extends maplibregl.Map {
new MaptilerLogoControl({ logoURL }),
options.logoPosition,
);

// if attribution in option is `false` or not provided, but the the logo shows up in the tileJson, then the attribution must show anyways
if (!options.attributionControl) {
this.addControl(
new AttributionControl({
customAttribution: options.customAttribution,
}),
);
}
} else if (options.maptilerLogo) {
this.addControl(new MaptilerLogoControl(), options.logoPosition);
}
Expand Down
Loading