简体   繁体   English

Openlayers功能选择区域已偏移

[英]Openlayers feature selection area is offset

I have this very odd problem, where the selection box shifts further and further down the closer the marker is to the bottom of the map. 我有一个非常奇怪的问题,选择框越靠近标记底部到地图底部,其移动就越远。

If the marker is at the very top of the map the selection box is right on top of the marker, but if it's further down the map I have to click further and further under the marker to select it. 如果标记位于地图的最上方,则选择框位于标记的上方,但是如果距离标记更远,则我必须在标记下方再单击一次以选择它。

Has anyone else experienced this? 其他人有没有经历过? I'm using Openlayers 4.1.1. 我正在使用Openlayers 4.1.1。 Here are some code chunks that could be relevant (I'm more than happy to share more code if that can help!): 以下是一些可能相关的代码块(如果有帮助,我很乐意分享更多代码!):

    var imageStyleFunction = function (feature, resolution) {
        if (feature.iconSrc) {
            var anchorX = feature.anchorX ? feature.anchorX : 0.5;
            var anchorY = feature.anchorY ? feature.anchorY : 0.5;
            return [new ol.style.Style({
                image: new ol.style.Icon({
                    src: feature.iconSrc,
                    anchor: [anchorX, anchorY]
                })
            })];
        }
    };

... ...

    markerLayer = new ol.layer.Vector({
        source: new ol.source.Vector(),
        style: imageStyleFunction
    });

... ...

    selectionInteraction = new ol.interaction.Select({
        condition: ol.events.condition.click,
        //hitTolerance: 20,
        style: imageStyleFunction
    });

    selectionInteraction.on('select', function (e) {
        var userLocationFeature = _.find(e.target.getFeatures().getArray(),
        function (feature) {
            return feature.markerType === "userLocation";
        });

        if (userLocationFeature) {
            store.commit("setSelectedUserLocation", userLocationFeature);
        } else {
            store.commit("setSelectedUserLocation", null);
            selectionInteraction.getFeatures().clear();
        }
    });

... ...

function createMarker(location, iconFile, markerType, markerId) {
    var markerLayerSource = markerLayer.getSource();
    var markerFeature = new ol.Feature({
        geometry: new ol.geom.Point(transformLonLat(location.longitude, location.latitude))
    });
    markerFeature.iconSrc = app.config.map.iconPath + iconFile;
    if (markerType) {
        markerFeature.markerType = markerType;
    }

    if (markerId) {
        markerFeature.markerId = markerId;
    }

    markerLayerSource.addFeature(markerFeature);
}

Mick's own solution by calling map.updateSize() solved it for me also. 米克自己的解决方案通过调用map.updateSize()也为我解决了。 I haven't investigated it more closely but I'm assuming it has to do with sizes changing during init of my ionic app. 我尚未对其进行更深入的研究,但我认为这与离子应用程序初始化期间尺寸的变化有关。 It's a quick fix to a more difficult problem at least. 至少可以快速解决更棘手的问题。

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

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