2017-08-16 15 views
0

forEachFeatureatPixel関数を使用すると、FirefoxとIEはOPENLAYERS 3で非常に遅く動作しています。私はそれをスピードアップする方法を見つけようとしています。本質的には、アプリケーション(www.penguinmap.comにあります)は、ユーザーがマップ上のあるポイントを飛び越したときに表示されるポップアップとして表示されます。しかし、Firefoxはこの機能に苦しんでいます。私はそれをスピードアップするために、次のコードで助けを探しています:私は(私はIE 11にも、パフォーマンスの低下の問題を抱えていた)独自の機能とポイントのために、この問題を解決しforEachFeatureatPixelでFirefoxが非常に遅い

var selectMouseMove = new ol.interaction.Select({ 
    condition: function (e) { 
     return e.originalEvent.type == 'mousemove'; 
    }, 
    style: hoverStyle 
}) 

// Change cursor 
var target = map.getTarget(); 
var jTarget = typeof target === "string" ? $("#" + target) : $(target); 
// On Hover, change the mouse cursor and display the name of the site 
$(map.getViewport()).on('mousemove', function (e) { 
    var pixel = map.getEventPixel(e.originalEvent); 
    var feature = map.forEachFeatureAtPixel(pixel, 
     function (feature, layer) { 
    return feature; 
}); 

if (feature) { 
    map.addInteraction(selectMouseMove) 
    jTarget.css("cursor", "pointer"); 
    var geometry = feature.getGeometry(); 
    var coord = geometry.getCoordinates(); 
    popup.setPosition(coord); 
    $(element).popover({ 
     'placement': 'top', 
     'html': true, 
     'content': feature.get('site_name') 
    }); 
    $(element).popover('show'); 
} else { 
    map.removeInteraction(selectMouseMove) 
    jTarget.css("cursor", ""); 
    $(element).popover('destroy'); 
    } 
}); 
var element = document.getElementById('popup'); 

var popup = new ol.Overlay({ 
    element: element, 
    positioning: 'bottom-center', 
    stopEvent: false 
}); 
map.addOverlay(popup); 

答えて

0

。私は "moveend" イベントで取得

// Alternative FeatureAtPixel-Function wegen FF 
// Sucht im Rechteck vom Punkt pixel aus in +/- x und +/- y 
function FFIE_getFeatureAtPixelQuadrat(pixel, DiffCoord) { 
    result = []; 
    mousepixel = map.getCoordinateFromPixel(pixel); 
    f = vectorSource.getFeatures(); 
    c = 0; 
    for (var i in f) { 
    if (f[i].point.flatCoordinates[0] > mousepixel[0] - DiffCoord && f[i].point.flatCoordinates[0] < mousepixel[0] + DiffCoord) { 
    if (f[i].point.flatCoordinates[1] > mousepixel[1] - DiffCoord && f[i].point.flatCoordinates[1] < mousepixel[1] + DiffCoord) { 
     c++; 
     result.push(f[i]); 
    }} 
    } 
    if (c > 0) { 
    return result; 
    } 
} 

パラメータDiffCoord:

// Event, wenn Zoom neu gesetzt 
map.on("moveend", function(evt) { 
    // Berechnen flatCoordinates per Pixel 
    var pixel = [0,0]; 
    startx = map.getCoordinateFromPixel(pixel)[0]; 
    pixel = [1,1]; 
    endx = map.getCoordinateFromPixel(pixel)[0]; 
    DiffCoord = (endx-startx) * 8; // 8 entspricht den +/- Pixeln in flatCoordinates 
}); 

今IEとFFは、MouseMoveの上にポップアップ表示するためのクロムよりも高速に等しくなるように思えます。 この例は、ポイントの原点を中心とする正方形内のフィーチャを検索するため、ポイントのみを対象としています。 こちらがお役に立てば幸いですか?