如何在 Openlayers 4 地图上渲染表情符号?

How can I render Emojis on Openlayers 4 map?

我被告知要在 openlayers 4 地图上渲染表情符号。

现在我找到了几个关于如何使用自定义地图标记的示例,但这并不完全符合我的需要。

有没有办法在 openlayers 4 地图上渲染表情符号?

这是我使用的测试数据(GeoJSON):

 {
    features: [
        {
            type: 'Feature',
            id: '1016392629',
            geometry: {
                type: 'Point',
                coordinates: [6.0, 6.0]
            },
            properties: {
                text: '\u1F31E',
            }
        },
        {
            type: 'Feature',
            id: '-2026663018',
            geometry: {
                type: 'Point',
                coordinates: [0.0, 0.0]
            },
            properties: {
                text: '\u1F31E',
            }
        }
    ],
    type: 'FeatureCollection'
 }

并使用样式函数:

    style: (feature: Feature) => {
        const { font, textBaseline, fillColor } = this.options;
        const s: ol.style.Style = new ol.style.Style({
            text: new ol.style.Text({
                text: feature.getProperties().text,
                font,
                textBaseline,
                fill: new ol.style.Fill({
                    color: fillColor
                })
            }),
            zIndex: 1
        });

        return s;
    }

但这只给我:

JS中的表情符号有两个字符。 (UTF-16需要用两个编码表示)

所以笑脸表情符号是:'\uD83D\uDE00' =

现在,您的表情符号 '\u1F31E'(阳光)将是:'\uD83C\uDF1E' = .

在以下位置继续阅读有关引导代理和尾代理的信息:medium.com: emojis-in-javascript

简单 google 找到我映射表情符号的在线资源:timwhitlock.info emoji tables 你可以检查每个字符 timwhitlock.info inspect 1F31E