Openlayers怎么实现鼠标经过显示这种样式
openlayers的example下的feature-events是样例 首先在创建图层的时候传入styleMap 当然里面定义了default 和select 的样式 ,然后在feature的事件中 选择它的渲染样式 重绘。
e.feature.renderIntent = "select"; //渲染样式
e.feature.layer.drawFeature(e.feature) //重绘
var layerListeners = {
featureover: function(e) {
e.feature.renderIntent = "select";
e.feature.layer.drawFeature(e.feature);
log("Map says: Pointer entered " + e.feature.id + " on " + e.feature.layer.name);
},
featureout: function(e) {
e.feature.renderIntent = "default";
e.feature.layer.drawFeature(e.feature);
log("Map says: Pointer left " + e.feature.id + " on " + e.feature.layer.name);
}
};
var style = new OpenLayers.StyleMap({
'default': OpenLayers.Util.applyDefaults({
label: "${l}",
pointRadius: 10
},
OpenLayers.Feature.Vector.style["default"]
),
'select': OpenLayers.Util.applyDefaults({
pointRadius: 10
},
OpenLayers.Feature.Vector.style.select
)
});
var layer1 = new OpenLayers.Layer.Vector("Layer 1", {
styleMap: style,
eventListeners: layerListeners
});
layer1.addFeatures([
new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT("POINT(-1 -1)"), {
l: 1
}),
new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT("POINT(1 1)"), {
l: 1
})
]);
var layer2 = new OpenLayers.Layer.Vector("Layer 2", {
styleMap: style,
eventListeners: layerListeners
});