ArcGIS JS API 4.0在三维模式下如何添加不被遮挡的标注?(weixin公众号【图说GIS】)

问题回顾

有人问我,在三维模式下,文本要素是覆盖在坐标点上的,想让文本向上或者向下偏移有没有什么办法?经过测试offset不起作用,代码如下:

在这里插入图片描述

const map = new EsriMap({
    basemap: "dark-gray",
});

const view = new SceneView({
    container: "map",
    map: map,
    camera: {
        position: {
            spatialReference: { wkid: 102100 },
            x: -8238359,
            y: 4967229,
            z: 686
        },
        heading: 353,
        tilt: 66
    }
});

// const symbol = {
//     type: "picture-marker",
//     url: "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1337419192,366595857&fm=26&gp=0.jpg",
//     width: "50px",
//     height: "50px",
//     outline: {
//         style: "solid"
//     },
// };

const point1: any = {
    type: "point",
    x: -74.01,
    y: 40.71,
    z: 0,
    SpatialReference: 4326
};

const symbol1 = {
    angle: 90,
    type: "text",
    color: "white",
    text: "兰州",
    xoffset: 100,
    yoffset: 100, //3d地图不起作用
    font: {
        size: 12,
    },
};

const symbol2: any = {
    type: "point-3d",
    symbolLayers: [
        {
            type: "icon",
            size: 12,
            resource: {
                primitive: "square"
            },
            material: {
                color: "orange"
            },
            outline: {
                color: "white",
                size: 1
            }
        }
    ]
};

const graphicsLayer = new GraphicsLayer()
const pointGraphic1 = new Graphic({
    geometry: point1,
    symbol: symbol1,
});
const pointGraphic2 = new Graphic({
    geometry: point1,
    symbol: symbol2,
});
graphicsLayer.add(pointGraphic2);
graphicsLayer.add(pointGraphic1);
map.add(graphicsLayer);

解决方案

经过查询API,可以通过FeatureLayer去实现,代码如下
在这里插入图片描述

  const iconSymbol = {
            type: "point-3d", // autocasts as new PointSymbol3D()
            symbolLayers: [
                {
                    type: "icon", // autocasts as new IconSymbol3DLayer()
                    size: 12,
                    resource: {
                        primitive: "square"
                    },
                    material: {
                        color: "orange"
                    },
                    outline: {
                        color: "white",
                        size: 1
                    }
                }
            ]
        };

        const iconSymbolRenderer: any = {
            type: "simple",
            symbol: iconSymbol,
        };

        const labelClass = new LabelClass({
            symbol: {
                type: "label-3d",
                symbolLayers: [
                    {
                        type: "text",
                        material: {
                            color: "white"
                        },
                        size: 10
                    } as any
                ]
            },
            labelPlacement: "above-center",
            labelExpressionInfo: {
                expression: 'DefaultValue($feature.place, "no data")'
            }
        });
        const point = {
            type: "point",
            x: -74.00897626922108,
            y: 40.70374571999779,
            SpatialReference: 4326
        };
        const pointGraphic = new Graphic({
            geometry: point,
            attributes: {
                place: "兰州"
            }
        } as any);

        const featureLayer = new FeatureLayer({
            source: [pointGraphic],
            renderer: iconSymbolRenderer,
            outFields: ["place"],
            maxScale: 0,
            minScale: 0,
            fields: [{
                name: "ObjectID",
                alias: "ObjectID",
                type: "oid"
            }, {
                name: "place",
                alias: "Place",
                type: "string"
            }],
            objectIdField: "ObjectID",
            geometryType: "point",
            labelingInfo: [labelClass]
        });
        map.add(featureLayer);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值