Skip to content

Commit

Permalink
【feature】 创建label图层时,若text-field没有对应的数据,则不创建图层; revie by qiw
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Oct 16, 2024
1 parent a0c5874 commit 268f1c7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/mapboxgl/web-map/WebMapViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,11 @@ export default class WebMapViewModel extends WebMapBase {

private _addLabelLayer(layerInfo: any, features: any, addSource = false): void {
const labelStyle = layerInfo.labelStyle;
const properties = features[0]?.properties;
const textField = labelStyle.labelField.replace(/{(.+)}/g, '$1');
if (!properties || !properties[textField]) {
return;
}
let { backgroundFill } = labelStyle;
const fontFamily = labelStyle.fontFamily;
const { minzoom, maxzoom } = layerInfo;
Expand Down
57 changes: 57 additions & 0 deletions src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1950,4 +1950,61 @@ describe('WebMapViewModel.spec', () => {
};
viewModel.on({ addlayerssucceeded: callback });
});

it('label layer no label field', done => {
const layerInfo = {
layerType: 'UNIQUE',
visible: true,
themeSetting: {},
name: 'labeNoField',
featureType: 'POINT',
labelStyle: {
offsetX: 0,
textBaseline: 'bottom',
fontFamily: '黑体',
offsetY: -19,
outlineWidth: 0,
textAlign: 'center',
outlineColor: '#000000',
fontSize: '14px',
fill: '#333',
backgroundFill: [255, 255, 255, 0.8],
labelField: '{未设置}'
},
style: {
strokeWidth: 1,
offsetX: 0,
fillColor: '#E6F598',
offsetY: 0,
fillOpacity: 0.9,
radius: 15,
strokeColor: '#ffffff',
type: 'BASIC_POINT',
strokeOpacity: 1
},
projection: 'EPSG:4326',
enableFields: ['UserID']
};
const fetchResource = {
'https://fakeiportal.supermap.io/iportal/web/datas/676516522/content.json?pageSize=9999999&currentPage=1&parentResType=MAP&parentResId=undefined':
layerData_CSV,
'https://fakeiportal.supermap.io/iportal/web/datas/13136933/content.json?pageSize=9999999&currentPage=1&parentResType=MAP&parentResId=undefined':
layerData_geojson['POINT_GEOJSON']
};
mockFetch(fetchResource);
const id = {
...uniqueLayer_point,
level: '',
visibleExtent: [0, 1, 2, 3]
};
const callback = function (data) {
expect(data.layers.length).toBe(id.layers.length);
const spy = jest.spyOn(viewModel, '_addLayer');
viewModel._addLabelLayer(layerInfo, [{ properties: {} }], true);
expect(spy).not.toBeCalled();
done();
};
const viewModel = new WebMapViewModel(id, { ...commonOption });
viewModel.on({ addlayerssucceeded: callback });
});
});

0 comments on commit 268f1c7

Please sign in to comment.