当前位置: 代码迷 >> Web前端 >> openlayer 平添marker弹出窗口
  详细解决方案

openlayer 平添marker弹出窗口

热度:472   发布时间:2012-10-08 19:54:56.0
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;
        } 
 

?

  相关解决方案