leaflet 地图上添加marker点击事件,自定义弹出框

var LeafIcon = L.Icon.extend({
				        options: {
//	 			            shadowUrl: test.png",//阴影图片,合理利用可以设置效果
				            iconSize:     [60, 64],
				        }
				        });  
var latLng = L.latLng(feature.y, feature.x);  
var icon=new LeafIcon({iconUrl:iconUrl});
var markers= L.marker(latLng,{icon: icon,attributes:feature})
				           .addTo(map)
				           .on('click', function (e) {
//		                     L.popup()
//		                    .setLatLng(e.latlng)
//		                    .setContent(setContent(e))
//		                    .openOn(map);//通过popup添加点击弹出框
                         //自定义弹框
				          var xset = e.containerPoint.x + 60 + "px";
                          var yset =e.containerPoint.y + "px";
                          $("#tstDiv").css({"left": xset, "top": yset, "z-index": '1000'});
                          $("#tstDiv").append(setContent(e));
                          $("#tstDiv").show();
                           });	//添加marker来设置点击事件


//二、通过L.geoJSON来添加marker或者line
resultLayer=L.geoJSON();
  resultLayer.addLayer(L.marker(latLng, {icon: icon,attributes:feature}).addTo(map).bindTooltip(feature.name+": "+feature.code, {
			               offset: L.point([0, -10]),//10, -60
				               direction: "top",
				               permanent: true
   			            })).openTooltip();//添加marker后直接打开标签
// 添加点击事件
 resultLayer.addLayer(L.marker(latLng, {icon: icon,attributes:feature}));
 var popup = L.popup().setContent(html);
 resultLayer.addTo(map).bindPopup(popup);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值