MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / _addLabelLayer

Method _addLabelLayer

src/common/mapping/WebMapV2.js:1411–1489  ·  view source on GitHub ↗
(layerInfo, features, addSource = false)

Source from the content-addressed store, hash-verified

1409 }
1410
1411 _addLabelLayer(layerInfo, features, addSource = false) {
1412 const labelLayerId = this._getSymbolLabelLayerName(layerInfo.layerID);
1413 if (this.map.getLayer(labelLayerId)) {
1414 return;
1415 }
1416 const labelStyle = layerInfo.labelStyle;
1417 const properties = features[0] && features[0].properties;
1418 const textField = labelStyle.labelField.replace(/{(.+)}/g, '$1');
1419 if (!properties || !Object.prototype.hasOwnProperty.call(properties, textField)) {
1420 return;
1421 }
1422 let { backgroundFill = [255, 255, 255, 0] } = labelStyle;
1423 const fontFamily = labelStyle.fontFamily;
1424 const { minzoom, maxzoom } = layerInfo;
1425 const textSize = parseFloat(labelStyle.fontSize || 14);
1426 let textBackgroundImageId = '';
1427 if (labelStyle.placement !== 'line') {
1428 textBackgroundImageId = this._addTextBackgroundImage(backgroundFill);
1429 }
1430 backgroundFill = `rgba(${backgroundFill.join(',')})`;
1431 let textHaloColor = 'rgba(255,255,255,0)';
1432 if (labelStyle.outlineColor && labelStyle.outlineWidth > 0) {
1433 textHaloColor = labelStyle.outlineColor;
1434 }
1435
1436 let textHaloWidth = (labelStyle.outlineWidth || 0) / 2;
1437 let textAnchor = labelStyle.textAlign || 'center';
1438 if (labelStyle.textBaseline && labelStyle.textBaseline !== 'middle') {
1439 textAnchor = `${labelStyle.textBaseline}${textAnchor === 'center' ? '' : `-${textAnchor}`}`;
1440 }
1441
1442 const textOffset =
1443 layerInfo.featureType === 'POINT'
1444 ? [labelStyle.offsetX / textSize || 0, labelStyle.offsetY / textSize || 0]
1445 : [0, 0];
1446 const layout = {
1447 'text-field': `{${labelStyle.labelField}}`,
1448 'text-size': textSize,
1449 'text-offset': textOffset,
1450 'text-font': fontFamily ? [fontFamily] : ['DIN Offc Pro Italic', 'Arial Unicode MS Regular'],
1451 'symbol-placement':
1452 labelStyle.placement === 'line' ? (layerInfo.featureType === 'POLYGON' ? 'line' : 'line-center') : 'point',
1453 'text-max-angle': layerInfo.featureType === 'POLYGON' ? 40 : 30,
1454 'symbol-spacing': layerInfo.featureType === 'POLYGON' ? 200 : 50,
1455 'text-anchor': textAnchor,
1456 'text-line-height': 1.2,
1457 visibility: layerInfo.visible
1458 };
1459 if (textBackgroundImageId) {
1460 Object.assign(layout, {
1461 'icon-image': textBackgroundImageId,
1462 'icon-allow-overlap': true,
1463 'icon-text-fit': 'both',
1464 'icon-text-fit-padding': [2, 4, 2, 4]
1465 });
1466 }
1467 this._addLayer(
1468 {

Callers 4

_addLayerSucceededMethod · 0.95
_addDataflowLayerMethod · 0.95
callbackFunction · 0.80
callbackFunction · 0.80

Calls 6

_addLayerMethod · 0.95
getLayerMethod · 0.45
getSourceMethod · 0.45
getMaxZoomMethod · 0.45

Tested by

no test coverage detected