Skip to content

Commit

Permalink
geosolutions-it#10711: Control loading FontAwsome for vector style
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mahmoudadel54 committed Dec 4, 2024
1 parent 831eab5 commit fb02dab
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion web/client/components/map/cesium/plugins/VectorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const createLayer = (options, map) => {
id: options?.id,
map: map,
opacity: options.opacity,
queryable: options.queryable === undefined || options.queryable
queryable: options.queryable === undefined || options.queryable,
loadFontAwesomeForIcons: options?.loadFontAwesomeForIcons
});

layerToGeoStylerStyle(options)
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/map/leaflet/plugins/VectorLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const createLayer = (options) => {

getStyle(applyDefaultStyleToVectorLayer(options), 'leaflet')
.then((styleUtils) => {
styleUtils({ opacity: options.opacity, layer, features: options.features })
styleUtils({ opacity: options.opacity, layer, features: options.features, loadFontAwesomeForIcons: options.loadFontAwesomeForIcons })
.then(({
style: styleFunc,
pointToLayer = () => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Layers.registerType('vector', {
.then((style) => {
if (style) {
if (style.__geoStylerStyle) {
style({ map, features: options.features })
style({ map, features: options.features, loadFontAwesomeForIcons: options.loadFontAwesomeForIcons })
.then((olStyle) => {
layer.setStyle(olStyle);
});
Expand Down
9 changes: 6 additions & 3 deletions web/client/plugins/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ import {getHighlightLayerOptions} from "../utils/HighlightUtils";
* @prop {boolean} mapOptions.cesium.depthTestAgainstTerrain if true all primitive 3d features will be tested against the terrain while if false they will be drawn on top of the terrain even if hidden by it (default true)
* @prop {number} mapOptions.cesium.maximumZoomDistance max zoom limit (in meter unit) to restrict the zoom out operation based on it
* @prop {number} mapOptions.cesium.minimumZoomDistance min zoom limit (in meter unit) to restrict the zoom in operation based on it
* @prop {boolean} loadFontAwesomeForIcons flag for control loading fontAwesome for vector layer style
* @static
* @example
* // Adding a layer to be used as a source for the elevation (shown in the MousePosition plugin configured with showElevation = true)
Expand Down Expand Up @@ -211,7 +212,8 @@ class MapPlugin extends React.Component {
items: PropTypes.array,
onLoadingMapPlugins: PropTypes.func,
onMapTypeLoaded: PropTypes.func,
pluginsCreator: PropTypes.func
pluginsCreator: PropTypes.func,
loadFontAwesomeForIcons: PropTypes.bool
};

static defaultProps = {
Expand Down Expand Up @@ -249,7 +251,8 @@ class MapPlugin extends React.Component {
items: [],
onLoadingMapPlugins: () => {},
onMapTypeLoaded: () => {},
pluginsCreator
pluginsCreator,
loadFontAwesomeForIcons: true
};

state = {};
Expand Down Expand Up @@ -330,7 +333,7 @@ class MapPlugin extends React.Component {
srs={projection}
position={index}
key={layer.id || layer.name}
options={layer}
options={{...layer, loadFontAwesomeForIcons: this.props.loadFontAwesomeForIcons}}
securityToken={this.props.securityToken}
env={env}
>
Expand Down
4 changes: 3 additions & 1 deletion web/client/utils/cesium/GeoJSONStyledFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class GeoJSONStyledFeatures {
this._dataSource.entities.collectionChanged.addEventListener(() => {
setTimeout(() => this._map.scene.requestRender(), 300);
});
this.loadFontAwesomeForIcons = options.loadFontAwesomeForIcons;
// internal key to associate features with original features
this._uuidKey = '__ms_uuid_key__' + uuid();
// needs to be run after this._uuidKey
Expand Down Expand Up @@ -369,7 +370,8 @@ class GeoJSONStyledFeatures {
getPreviousStyledFeature: (styledFeature) => {
const editingStyleFeature = this._styledFeatures.find(({ id }) => id === styledFeature.id);
return editingStyleFeature;
}
},
loadFontAwesomeForIcons: this.loadFontAwesomeForIcons
})
.then((styledFeatures) => {
this._updateEntities(styledFeatures, forceUpdate);
Expand Down
5 changes: 3 additions & 2 deletions web/client/utils/styleparser/CesiumStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,9 +1036,10 @@ function getStyleFuncFromRules({
features,
getPreviousStyledFeature = () => {},
map,
sampleTerrain = Cesium.sampleTerrain
sampleTerrain = Cesium.sampleTerrain,
loadFontAwesomeForIcons
}) => {
return drawIcons({ rules }, { features })
return drawIcons({ rules, loadFontAwesomeForIcons }, { features })
.then((images) => {
const styledFeatures = getStyledFeatures({ rules, features, globalOpacity, images });
return Promise.all(styledFeatures.map((currentFeature) => {
Expand Down
5 changes: 3 additions & 2 deletions web/client/utils/styleparser/LeafletStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ function getStyleFuncFromRules({ rules: geoStylerStyleRules = [] }) {
return ({
opacity: globalOpacity = 1,
layer = {},
features
} = {}) => drawIcons({ rules: geoStylerStyleRules }, { features }).then((images = []) => {
features,
loadFontAwesomeForIcons
} = {}) => drawIcons({ rules: geoStylerStyleRules, loadFontAwesomeForIcons }, { features }).then((images = []) => {

if (layer._msAdditionalLayers) {
layer._msAdditionalLayers.forEach((additionalLayer) => {
Expand Down

0 comments on commit fb02dab

Please sign in to comment.