マウスオーバー時にスタイリング機能に問題があります。私はイベントを得ることができますが、スタイルを変えるだけでは機能しません。選択するには有効ですが、ホバー/マウスオーバーの場合はまったく表示されません。誰もそれで私を助けてもらえますか?ここに私のコードは次のとおりです。openlayersで選択とホバーリスナーを使用する2 - ホバー変更スタイル
var map, vectorLayer, wmsLayer, selectControl;
window.onload = function() {
map = new OpenLayers.Map('map');
wmsLayer = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0?", {
layers: 'basic'
}, {
'attribution': 'Provided by OSGeo'
}
);
vectorLayer = new OpenLayers.Layer.Vector("My Layer Name", {
styleMap: new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
strokeColor: "#ff0000",
strokeOpacity: .7,
strokeWidth: 1,
fillColor: "#ff0000",
fillOpacity: 0,
'pointRadius': 30
}),
"temporary": new OpenLayers.Style({
strokeColor: "#ffff33",
strokeOpacity: .9,
strokeWidth: 2,
fillColor: "#ffff33",
fillOpacity: .3,
cursor: "pointer",
'pointRadius': 20
}),
"select": new OpenLayers.Style({
strokeColor: "#0033ff",
strokeOpacity: .7,
strokeWidth: 2,
fillColor: "#0033ff",
fillOpacity: 0,
graphicZIndex: 2,
'pointRadius': 10
})
})
});
map.addLayers([wmsLayer, vectorLayer]);
map.zoomToMaxExtent();
vectorLayer.addFeatures([
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(10, 10)
)
]);
var selectControlClicks = new OpenLayers.Control.SelectFeature(vectorLayer, {
onSelect: function(feature) {
console.log('select: number of selected features: ' + vectorLayer.selectedFeatures.length);
},
onUnselect: function(feature) {
console.log('unselect: number of selected features: ' + vectorLayer.selectedFeatures.length);
}
});
var selectControlHover = new OpenLayers.Control.SelectFeature(vectorLayer, {
hover: true,
highlightOnly: true,
renderIntent: 'temporary',
overFeature: function(feature) {
console.log('hover: number of selected features: ' + vectorLayer.selectedFeatures.length);
},
outFeature: function(feature) {
console.log('hover out: number of selected features: ' + vectorLayer.selectedFeatures.length);
},
});
map.addControl(selectControlHover);
selectControlHover.activate();
map.addControl(selectControlClicks);
selectControlClicks.activate();
}
多分私の穴のアプローチは、多分私はちょうど1 SelectControlを使用する必要があり、間違っていますか?
歓声
あなたは正しいです。ホバーリスナーの宣言に問題がありました。あなたのアプローチでは完璧に動作します!ありがとうございました!私はただ1つの選択コントローラを使用することを考えていましたが、ホバーと選択の両方が必要な場合は簡単ではないようです。最後に達成したいことは次のとおりです: - 機能をクリックする可能性があります - 機能 にカーソルを移動する可能性があります - プログラムで機能を選択し、選択されたフィーチャがプログラマチックに行われた場合のみ、呼び出されたフィーチャを呼び出す。それが穴のシナリオです。あなたの助けをもう一度ありがとう – pawelforums