openlayer 添加marker弹出窗口

var markers,marker,popup;
		var markArr=new Array();
		function addMarker(){
			
			/* var url = 'http://www.openlayers.org/dev/img/marker.png';
                var sz = new OpenLayers.Size(20, 20);  //尺寸大小
                var calculateOffset = function(size) {
                                    return new OpenLayers.Pixel(-(size.w/2), -size.h);
                                 };
                var icon = new OpenLayers.Icon(url, sz, null, calculateOffset);
				
				marker = new OpenLayers.Marker(new OpenLayers.LonLat(116.34851,33.22630), icon);*/
				if(popup!=null){
					 onPopupMouseDown(); //先移除掉
				 }
				 feature = new OpenLayers.Feature(tiled, new OpenLayers.LonLat(116.34851,33.22630));
//tiled 是增加的图层名称,OpenLayers.Layer.WMS的对象	
 				marker = feature.createMarker();
				  markers.addMarker(marker);

				marker.events.register("mousedown", marker, function(evt){
					 if (popup == null) {
						popup = new OpenLayers.Popup("click", 
												 new OpenLayers.LonLat(116.34851,33.22630),
												 new OpenLayers.Size(100,100),
												 "click me",
												 true);
						 popup.setBorder("#999999 solid 1px");
						 popup.closeOnMove = true;
						map.addPopup(popup);
					} else {
						popup.toggle();
					 }
					OpenLayers.Event.stop(evt);
				});
		}
		//移除Popup
		function onPopupMouseDown() {
            markers.map.removePopup(popup);
            popup.destroy();
            popup = null;
        } 
 

 

转载自:https://blog.csdn.net/lting19880817/article/details/83919890

You may also like...