繁体   English   中英

Openlayers 3 - 创建自定义符号,如openlayers 2 - > OpenLayers.Renderer.symbol.anySymbol

[英]Openlayers 3 - Create custom symbol like openlayers 2 -> OpenLayers.Renderer.symbol.anySymbol

Openlayers v2我可以添加如下符号:

OpenLayers.Renderer.symbol.pointToIcon = [100, 70, 20, 50, 42, 70, 20, 90];

我怎样才能使用Openlayers 3?

openlayers 3我可以使用此功能:

var starSymbol = new ol.style.RegularShape({
    points: 4,
    opacity: .5,
    radius: 10,
    radius2: 10 * .5,
    angle: 130,
    fill: new ol.style.Fill({
        color: "blue"
    }),
    stroke: new ol.style.Stroke({
        color: "red",
        width: 1
    })
});

我可以制作其他数字,但我不能制作下图。

在此输入图像描述

另外,我不使用'Icon'之类的:

new ol.style.Style({
    image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
        anchor: [0.5, 46],
        anchorXUnits: 'fraction',
        anchorYUnits: 'pixels',
        opacity: 0.75,
        src: 'data/icon.png'
    }))
})

因为图标的颜色是固定的,我不能使用我需要的颜色。

如果你帮助我,我真的很感激。

您可以将自定义符号绘制到画布,并将其用作图标图像。 OpenLayers为此提供了一个非常好的API。 您可能需要查看示例: http//openlayers.org/en/v3.12.1/examples/earthquake-custom-symbol.html

对于您的特定符号,代码可能如下所示:

var canvas = document.createElement('canvas');
var render = ol.render.toContext(canvas.getContext('2d'),
    {size: [50, 45]});
render.setFillStrokeStyle(
    new ol.style.Fill({ color: 'red' }),
    new ol.style.Stroke({ color: 'black' }));
render.drawPolygonGeometry(new ol.geom.Polygon(
    [[[50, 35], [10, 25], [21,35], [10, 45], [50, 35]]]));
var style = new ol.style.Style({
  image: new ol.style.Icon({
    img: canvas,
    imgSize: [canvas.width, canvas.height],
  })
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM