Skip to content

Commit

Permalink
Fix attribution control bug (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlurie authored Apr 25, 2024
1 parent e565ccb commit d3aed49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
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

0 comments on commit d3aed49

Please sign in to comment.