簡體   English   中英

Openlayers功能選擇區域已偏移

[英]Openlayers feature selection area is offset

我有一個非常奇怪的問題,選擇框越靠近標記底部到地圖底部,其移動就越遠。

如果標記位於地圖的最上方,則選擇框位於標記的上方,但是如果距離標記更遠,則我必須在標記下方再單擊一次以選擇它。

其他人有沒有經歷過? 我正在使用Openlayers 4.1.1。 以下是一些可能相關的代碼塊(如果有幫助,我很樂意分享更多代碼!):

    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);
}

米克自己的解決方案通過調用map.updateSize()也為我解決了。 我尚未對其進行更深入的研究,但我認為這與離子應用程序初始化期間尺寸的變化有關。 至少可以快速解決更棘手的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM