und*_*und 4 javascript styles point openlayers
我正在尝试在OpenLayers 4中的矢量源中设置点的样式.
我定义了一种风格:
var pStyle = new ol.style.Style({
stroke: new ol.style.Stroke({
width: 6, color: [255, 0, 0, 1]
})
});
Run Code Online (Sandbox Code Playgroud)
并在图层定义中添加了样式
var pLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [p]
}),
style: pStyle
});
Run Code Online (Sandbox Code Playgroud)
注释样式定义使得该点出现在地图上,所以我假设其余的代码都没问题.但我无法明白地图上的红色.
小提琴:https://codepen.io/fundef/pen/VXKYjP
我哪里错了?
如果你想使用fill和stroke
var myStyle = new ol.style.Style({
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({color: 'black'}),
stroke: new ol.style.Stroke({
color: [255,0,0], width: 2
})
})
})
Run Code Online (Sandbox Code Playgroud)
小智 0
你可以用ol.style.icon它。
这是一个例子:
<script>
iconFeature.setStyle(new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
color: '#8959A8',
crossOrigin: 'anonymous',
src: 'https://openlayers.org/en/v4.6.4/examples/data/dot.png'
}))
}));
<script>
Run Code Online (Sandbox Code Playgroud)