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

#10711: Control loading FontAwesome for vector style #10715

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

mahmoudadel54
Copy link
Contributor

Description

This PR handles control the loading of FontAwesome for vector data style.
A boolean cfg called 'loadFontAwesomeForIcons' for Map plugin can be added to control the loading fontAwesome for vector style this will be used for OpenLayers, Leaflet and Cesium. loadFontAwesomeForIcons is with true by default.
This PR enhances the loadFontAwesome function to load only if the vector data has icons.

This is a sample of config Map plugin:

 {
            "name": "Map",
            "cfg": {
              "mapOptions": {
                "openlayers": {
                  "interactions": {
                    "pinchRotate": false,
                    "altShiftDragRotate": false
                  },
                  "attribution": {
                    "container": "#footer-attribution-container"
                  }
                },
                "leaflet": {
                  "attribution": {
                    "container": "#footer-attribution-container"
                  }
                }
              },
              "toolsOptions": {
                "scalebar": {
                  "container" : "#footer-scalebar-container"
                }
              },
              "loadFontAwesomeForIcons": false
            }
          }

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x", remove the others)

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

Issue

#10711

What is the current behavior?
#10711

What is the new behavior?
If the Map plugin cfg contains loadFontAwesomeForIcons flag with false ---> so it will stop loading fontAwesome for vector data style and if with true -- > fontAwesome will be loaded in adding vector layer to map

Breaking change

Does this PR introduce a breaking change? (check one with "x", remove the other)

  • Yes, and I documented them in migration notes
  • No

Other useful information

Description:
- add boolean cfg called 'loadFontAwesomeForIcons' for Map plugin to control the loading fontAwesome for vector style
- add jsdocs in plugin/Map
- handle the control of loading fontAwesome for openlayers, leaflet and cesium
@mahmoudadel54 mahmoudadel54 requested a review from MV88 December 4, 2024 15:14
@mahmoudadel54 mahmoudadel54 self-assigned this Dec 4, 2024
@mahmoudadel54 mahmoudadel54 added enhancement BackportNeeded Commits provided for an issue need to be backported to the milestone's stable branch labels Dec 4, 2024
@mahmoudadel54 mahmoudadel54 added this to the 2025.01.00 milestone Dec 4, 2024
@mahmoudadel54 mahmoudadel54 linked an issue Dec 4, 2024 that may be closed by this pull request
…nd loadFontAwesomeForIcons = true --> it will load fontAwesome and if there is no icons ---> it won't load
Copy link
Contributor

@MV88 MV88 left a comment

Choose a reason for hiding this comment

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

please check what i suggest here, also within the project as well

web/client/utils/styleparser/StyleParserUtils.js Outdated Show resolved Hide resolved
@mahmoudadel54 mahmoudadel54 requested a review from MV88 December 9, 2024 14:02
@MV88 MV88 merged commit 4d5ca88 into geosolutions-it:master Dec 9, 2024
6 checks passed
const loadFontAwesomeForIcons = getConfigProp("loadFontAwesomeForIcons");
// if undefined or true it will load it to preserve previous behaviour
const loadingPromise = (isNil(loadFontAwesomeForIcons) || loadFontAwesomeForIcons) && icons?.length ? loadFontAwesome() : Promise.resolve();
return loadingPromise
Copy link
Contributor

@allyoucanmap allyoucanmap Dec 9, 2024

Choose a reason for hiding this comment

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

@MV88 @mahmoudadel54 in another branch I was exporting to loadingFontAwesome to a specific utils (this branch is not merged yet on master)

https://github.com/allyoucanmap/MapStore2/blob/96dea788d349a09fc7512466beae3cd0aebe1fec/web/client/utils/FontUtils.js

wouldn't it be better to expose a register function instead to have a loadFontAwesomeForIcons config?

let fontAwesomeLoaded = false;

export const isFontAwesomeReady = () => fontAwesomeLoaded;

let defaultLoadFontAwesome = () => {
    if (fontAwesomeLoaded) {
        return Promise.resolve();
    }
    // async load of font awesome
    return import('font-awesome/css/font-awesome.min.css')
        .then(() => {
            // ensure the font is loaded
            return document.fonts.load('1rem FontAwesome')
                .then(() => {
                    fontAwesomeLoaded = true;
                    return fontAwesomeLoaded;
                });
        });
};

export const registerLoadFontAwesome = (promiseFunc) => {
  defaultLoadFontAwesome = promiseFunc;
}

export const loadFontAwesome = () => {
    return defaultLoadFontAwesome();
};

then in a specific project you could use registerLoadFontAwesome in the app entry to override the default function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@allyoucanmap
I think the use case we opened this issue is in importing vector layer. In import new vector layer -- > drawIcons method is called and it calls loadFontAwesome within it by default. We don't make exporting this specific method and use it particularly in import.
So I think your approach doesn't prevent calling this method because in import vector layer, calling this method is not optional.

@MV88
Copy link
Contributor

MV88 commented Dec 18, 2024

@ElenaGallo can you test this on DEV asap?

mahmoudadel54 added a commit to mahmoudadel54/MapStore2 that referenced this pull request Dec 18, 2024
…eosolutions-it#10715)

* geosolutions-it#10711: Control loading FontAwsome for vector style
Description:
- add boolean cfg called 'loadFontAwesomeForIcons' for Map plugin to control the loading fontAwesome for vector style
- add jsdocs in plugin/Map
- handle the control of loading fontAwesome for openlayers, leaflet and cesium

* geosolutions-it#10711: enhance drawIcons if there are icons in data and loadFontAwesomeForIcons = true --> it will load fontAwesome and if there is no icons ---> it won't load

* geosolutions-it#10711: using cfg loadFontAwesomeForIcons in root in localConfig instead of map plugin and revert other changes

* geosolutions-it#10711: remove unused console.log in StylePArserUtils
@ElenaGallo
Copy link
Contributor

Test passed, @mahmoudadel54 please backport. Thanks

MV88 pushed a commit that referenced this pull request Dec 19, 2024
* #10711: Control loading FontAwsome for vector style
Description:
- add boolean cfg called 'loadFontAwesomeForIcons' for Map plugin to control the loading fontAwesome for vector style
- add jsdocs in plugin/Map
- handle the control of loading fontAwesome for openlayers, leaflet and cesium

* #10711: enhance drawIcons if there are icons in data and loadFontAwesomeForIcons = true --> it will load fontAwesome and if there is no icons ---> it won't load

* #10711: using cfg loadFontAwesomeForIcons in root in localConfig instead of map plugin and revert other changes

* #10711: remove unused console.log in StylePArserUtils
@ElenaGallo ElenaGallo removed the BackportNeeded Commits provided for an issue need to be backported to the milestone's stable branch label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Control loading FontAwesome for vector style
4 participants