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 basemaps order #7170

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

glughi
Copy link
Contributor

@glughi glughi commented May 28, 2024

What this PR does

Fixes #7169

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

@ljowen ljowen requested a review from tephenavies May 29, 2024 03:38
@tephenavies tephenavies self-assigned this May 29, 2024
) {
const itemModel = this.terria.getModelById(BaseModel, baseMapItem.item);
if (MappableMixin.isMixedInto(itemModel))
this.enabledBaseMaps.forEach((baseMapItem) => {
Copy link
Contributor

@zoran995 zoran995 Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.enabledBaseMaps might be undefined, and when undefined it should show all base maps available.
i.e. simple sorting before return in the old code would do the trick

// Sort based on enabledBaseMaps order
if (this.enabledBaseMaps) {
  enabledBaseMaps.sort((a, b) => {
    const aIndex = this.enabledBaseMaps!.indexOf(a.item.uniqueId!);
    const bIndex = this.enabledBaseMaps!.indexOf(b.item.uniqueId!);
    return aIndex - bIndex;
  });
}

another option that comes to my mind is to go with the utility function and do mapping over proper array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zoran995 what do you think about

    const baseMapList =
      this.enabledBaseMaps ?? this.items.map((item) => item.item);
    baseMapList.forEach((baseMapItem) => {
      const item = this.items.find((item) => item.item === baseMapItem);
      if (item && !ModelReference.isRemoved(baseMapItem)) {
        const itemModel = this.terria.getModelById(BaseModel, baseMapItem);
        if (MappableMixin.isMixedInto(itemModel)) {
          enabledBaseMaps.push({
            image: item.image,
            contrastColor: item.contrastColor,
            item: itemModel
          });
        }
      }
    });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on first look, it should work correctly and the rest is a personal preference on the code structure. It would be great to cover sorting with the unit test to avoid regression bugs in future, there are tests for BaseMapsModel

https://github.com/TerriaJS/terriajs/blob/2490260c78e4b7666496bfc6d0ec677eac63a98c/test/Models/BaseMaps/BaseMapsModelSpec.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Basemaps sorting bug
3 participants