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
Merged
Show file tree
Hide file tree
Changes from 2 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
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
2 changes: 1 addition & 1 deletion web/client/utils/styleparser/OLStyleParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class OlStyleParser {
*/
geoStylerStyleToOlParserStyleFct(geoStylerStyle) {
const rules = geoStylerStyle.rules;
const olStyle = ({ map, features } = {}) => drawIcons(geoStylerStyle, { features })
const olStyle = ({ map, features, loadFontAwesomeForIcons } = {}) => drawIcons({...geoStylerStyle, loadFontAwesomeForIcons}, { features })
.then((images) => {
this._getImages = () => images;
this._getImageSrc = createGetImagesSrc();
Expand Down
3 changes: 2 additions & 1 deletion web/client/utils/styleparser/StyleParserUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ export const drawIcons = (geoStylerStyle, options) => {
}, []);
const marks = symbolizers.filter(({ kind }) => kind === 'Mark');
const icons = symbolizers.filter(({ kind }) => kind === 'Icon');
return loadFontAwesome()
const shouldLoadFontAwesomeForIcons = (geoStylerStyle.loadFontAwesomeForIcons && icons.length > 0) ? loadFontAwesome() : Promise.resolve();
return shouldLoadFontAwesomeForIcons
.then(
() => new Promise((resolve) => {
if (marks.length > 0 || icons.length > 0) {
Expand Down
Loading