你没有弄清楚你所说的“行为奇怪”是什么意思,但我想这是关于放大和缩小后标记“浮动”的。这是因为您使用的是一个顶端位于底部的自定义标记图像,但默认情况下OpenLayers会将图标的中心设置在中间(因为它无法推断“尖”侧的位置)。
通过定义锚点可以轻松解决此问题。有多种方法可以
specify where the anchor should be
,使用
anchor
在这种情况下可能是最直接的:
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
opacity: 0.75,
anchor: [0.5, 1], // middle on the X axis, bottom on the Y axis
src: '//cdn4.iconfinder.com/data/icons/pictype-free-vector-icons/16/location-alt-32.png'
}))
});
这是您更新的JSFiddle,它显示了定义了锚的新行为:
http://jsfiddle.net/kryger/hv8w4o3u/2/