2

OpenLayers では、カーソルがその上を移動すると、ベクター レイヤーの機能を強調表示しようとしています。私はこれを機能させることができます。

また、機能を選択可能にし、クリックするとポップアップ ボックスが表示されるようにしようとしています。これも機能します。

私がうまくいかないのは、両方を同時に行うことです。ホバー選択はポップアップ選択を上書きするようです。コードはhttp://dev.openlayers.org/releases/OpenLayers-2.11/examples/highlight-feature.htmlに基づいていますが、いくつかの違いがあります。ホバー選択と選択が共存できない理由を誰かが知っていますか?

select = new OpenLayers.Control.SelectFeature(vector_Layer, {clickout: true}); 
        vector_Layer.events.on({
            "featureselected": onFeatureSelect,
            "featureunselected": onFeatureUnselect
        });
        map.addControl(select);
        select.activate();

        select.handlers['feature'].stopDown = false; 
        select.handlers['feature'].stopUp = false;

//REMOVED AS OVERRODE SELECT selectHover = new OpenLayers.Control.SelectFeature(vector_Layer, {hover: true});

function onPopupClose(event) {
    select.unselectAll();
}

function onFeatureSelect(event) {
        var feature = event.feature;
        var content = "<p>"+feature.attributes.SHEET.value + "</p>" + feature.attributes.description;
        if (content.search("<script") != -1) {
            content = "Content contained Javascript! Escaped content below.<br>" + content.replace(/</g, "&lt;");
        }
        popup = new OpenLayers.Popup.FramedCloud("chicken", 
                                 feature.geometry.getBounds().getCenterLonLat(),
                                 new OpenLayers.Size(100,100),
                                 content,
                                 null, true, onPopupClose);
        feature.popup = popup;
        map.addPopup(popup);
}  

function onFeatureUnselect(event) {
        var feature = event.feature;
        if(feature.popup) {
            map.removePopup(feature.popup);
            feature.popup.destroy();
            delete feature.popup;
        }
}

var info = function(evt) {
            OpenLayers.Console.log(evt.type, evt.feature.id);
        };

//REMOVED OF OVERODE SELECT var highlight = new OpenLayers.Control.SelectFeature(vector_Layer, {
//                hover: true,
//                highlightOnly: true,
//                renderIntent: "temporary",
//                eventListeners: {
//                    beforefeaturehighlighted: info ,
//                    featurehighlighted: info ,
//                    featureunhighlighted: info 
//                }
//            });
//map.addControl(highlight);
//highlight.activate();

var vector_style_d = new OpenLayers.Style({
    'fillColor': '#669933',
    'fillOpacity': .5,
    'strokeColor': '#aaee77',
    'strokeWidth': 3,
    'cursor': 'pointer'
})

var vector_style_s = new OpenLayers.Style({
    'fillColor': '#FE2E2E',
    'fillOpacity': .8,
    'strokeColor': '#aaee47',
    'strokeWidth': 4,
    'cursor': 'pointer'
})

var vector_style_t = new OpenLayers.Style({
    'fillColor': '#FE2E2E',
    'fillOpacity': .8,
    'strokeColor': '#aaee47',
    'strokeWidth': 3,
    'cursor': 'pointer'
})

var vector_style_map = new OpenLayers.StyleMap({
    'default': vector_style_d,
    'select': vector_style_s,
    'temporary': vector_style_t,
});

vector_Layer.styleMap = vector_style_map;
4

1 に答える 1

0

私は同じ問題を抱えていましたが、OLページ(http://openlayers.org/dev/examples/highlight-feature.html)で提供されている例を見ていました。私にとってのトリックは、コンストラクターの順序を変更することでした両方のコントロールが呼び出されます (最初にホバーしてから選択する必要があります)。

乾杯

于 2013-12-20T10:43:50.310 に答える