您的位置:首页 > 其它

当鼠标滑过,点击地图时,高亮显示,触发事件

2016-03-21 23:40 435 查看
回调函数
var wfs = new OpenLayers.Layer.Vector("WFS", {
strategies: [new OpenLayers.Strategy.Fixed()],
projection: new OpenLayers.Projection("EPSG:4326"),
styleMap: myStyles,
displayInLayerSwitcher: true,
//styleMap: new OpenLayers.StyleMap({ externalGraphic: "../images/pic_left.png", graphicOpacity: 0.3, graphicWidth: 10, graphicHeight: 10 }),
protocol: new OpenLayers.Protocol.WFS({
version: "1.0.0",
url: "http://" + WMS_ipAdress + "/geoserver/TJDG/wfs",
featureType: "xqpostgis5326",
featurePrefix: "TJDG",
featureNS: "http://www.tjdg.com",
srsName: "EPSG:4326",
geometryName: "the_geom"
})
});

map.addLayers([wfs]);

/*    var select =  new OpenLayers.Control.SelectFeature(
wfs,
{
clickout: true,
toggle: false,
multiple: false,
hover: false,
toggleKey: "ctrlKey", // ctrl key removes from selection
multipleKey: "shiftKey", // shift key adds to selection
box: true
}
);
map.addControl(select);
select.activate();
*/

var selecthover = new OpenLayers.Control.SelectFeature(
wfs,
{
toggle: true,
highlightOnly:true
}
);
map.addControl(selecthover);
selecthover.activate();
selecthover.events.on({
'featurehighlighted': function(feature) {
var sFch = feature.feature;
var pt = sFch.geometry.getBounds().getCenterLonLat();
alert(pt.lon);

},
'featureunhighlighted': function(feature) {
//alert(1);
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: