MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / getLabelStyle

Method getLabelStyle

src/openlayers/mapping/WebMap.js:3341–3384  ·  view source on GitHub ↗

* @private * @function WebMap.prototype.getLabelStyle * @description 获取标签样式 * @param {Object} parameters - 标签图层样式参数 * @param {Object} layerInfo - 图层样式参数 * @returns {ol.style.Style} 标签样式

(parameters, layerInfo)

Source from the content-addressed store, hash-verified

3339 * @returns {ol.style.Style} 标签样式
3340 */
3341 getLabelStyle(parameters, layerInfo) {
3342 let style = layerInfo.style || layerInfo.pointStyle;
3343 const { radius = 0, strokeWidth = 0 } = style,
3344 beforeOffsetY = -(radius + strokeWidth);
3345 const {
3346 fontSize = '14px',
3347 fontFamily,
3348 fill,
3349 backgroundFill,
3350 offsetX = 0,
3351 offsetY = beforeOffsetY,
3352 placement = 'point',
3353 textBaseline = 'bottom',
3354 textAlign = 'center',
3355 outlineColor = '#000000',
3356 outlineWidth = 0
3357 } = parameters;
3358 const option = {
3359 font: `${fontSize} ${fontFamily}`,
3360 placement,
3361 textBaseline,
3362 fill: new FillStyle({ color: fill }),
3363 backgroundFill: new FillStyle({ color: backgroundFill }),
3364 padding: [3, 3, 3, 3],
3365 offsetX: layerInfo.featureType === 'POINT' ? offsetX : 0,
3366 offsetY: layerInfo.featureType === 'POINT' ? offsetY : 0,
3367 overflow: true,
3368 maxAngle: 0
3369 };
3370 if (layerInfo.featureType === 'POINT') {
3371 //线面不需要此参数,否则超出线面overflow:true,也不会显示标签
3372 option.textAlign = textAlign;
3373 }
3374 if (outlineWidth > 0) {
3375 option.stroke = new StrokeStyle({
3376 color: outlineColor,
3377 width: outlineWidth
3378 });
3379 }
3380
3381 return new Style({
3382 text: new Text(option)
3383 });
3384 }
3385
3386 /**
3387 * @private

Callers 1

addLabelLayerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected