OpenLayers下使用Jquery tooltip(Qtip)让要素信息自动显示或隐藏

阅读更多
首先在官网下载qtip插件:http://craigsworks.com/projects/qtip/
1、导入插件
 
 
 
 

2、编写js
(1)、在地图帮助类JS中加入:
//要素tip文字控件
var tooltipControl = new OpenLayers.Control.SelectFeature(com.nwd.map._vectorLayer_, {
				hover: true,
				highlightOnly: true,
				eventListeners: {
					beforefeaturehighlighted: showQtip,
				}
			});
  this.map.addControl(tooltipControl);
//QTip文字显示==此方法也可以加入到JSP页面里
function showQtip(olEvent){
	var elem = document.getElementById(olEvent.feature.geometry.id);
	$(elem).qtip({
		overwrite: false,
		content: olEvent.feature.attributes.name,
		position: {  
			at: 'right center',
			my:'left center'
		  }, 
		show: {
			ready: true
		},
		style: {
			classes: 'ui-tooltip-shadow ui-tooltip-blue'
		}
	}).qtip('show');
}

(2)、在页面JS中加入:
function carInfoPOI(geoPoint,img) {
	var address=geoPoint.address+"",address1,address2;
	if(address.length>23){
		address1=address.substring(0,23);
		address2=address.substring(23,address.length);
		address=address1+"
"+address2; } var divContent="
" +getCarNumber(geoPoint.deviceId)+"
设备编号:" +geoPoint.deviceId+"
" +"速度:"+geoPoint.speed+"km/h
" +"方向:"+geoPoint.direction+"点方向
" +"告警数据:"+geoPoint.alarm+"
" +"地址:"+address+"
"; var attributes = { 'name': divContent, 'longitude': geoPoint.lon_, 'latitude': geoPoint.lat_ }; var feature= new OpenLayers.Feature.Vector(geoPoint, attributes, intCarStyle(img,geoPoint.deviceId)); feature.deviceId=deviceId;feature.geoPoint=geoPoint; return feature; }

你可能感兴趣的:(jquery,jsp,JavaScript,openlayers,feature)