Ped*_*ram 3 javascript gis maps openlayers openlayers-3
在Openlayers v2我可以添加如下符号:
OpenLayers.Renderer.symbol.pointToIcon = [100, 70, 20, 50, 42, 70, 20, 90];
Run Code Online (Sandbox Code Playgroud)
我怎样才能使用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
})
});
Run Code Online (Sandbox Code Playgroud)
我可以制作其他数字,但我不能制作下图.
另外,我不使用'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'
}))
})
Run Code Online (Sandbox Code Playgroud)
因为图标的颜色是固定的,我不能使用我需要的颜色.
如果你帮助我,我真的很感激.
您可以将自定义符号绘制到画布,并将其用作图标图像.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],
})
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
675 次 |
| 最近记录: |