var init=!1,globalIndex=0,BaiduMapWidget={getOption:function($container){var initValue;try{try{initValue=JSON.parse($container.attr("data-baidu-map-widget"))}catch(e){eval("initValue = "+$container.attr("data-baidu-map-widget"))}}catch(t){initValue={}}return $.extend({initAddress:""},initValue)},init:function(){if(!init){init=!0;var t=function(t){var e=$(t),a=new BMap.Geocoder,i=new BMap.Geolocation,n=this;this.map=null,this.marker=null,this.init=function(){var t="__baiduMapWidget__"+globalIndex++;e.find("[data-map]").attr("id",t),n.map=new BMap.Map(t),n.marker=new BMap.Marker(116.404,39.915),n.marker.enableDragging(),n.map.addOverlay(n.marker),n.map.enableScrollWheelZoom(),n.map.addEventListener("click",function(t){n.setMarkerPoint(t.point)}),n.marker.addEventListener("dragend",function(t){n.setMarkerPoint(t.point)}),i.getCurrentPosition(function(t){var e=this;setTimeout(function(){e.getStatus()===BMAP_STATUS_SUCCESS?(n.map.centerAndZoom(t.point,15),n.setMarkerPoint(t.point)):a.getPoint("北京",function(t){n.map.centerAndZoom(t,15),n.setMarkerPoint(t)})},3e3)},{enableHighAccuracy:!0})},this.setMarkerPoint=function(t){n.marker.setPosition(t),a.getLocation(t,function(a){var i=a.addressComponents;e.find("[data-map-address]").val(i.province+i.city+i.district+i.street+i.streetNumber),e.find("[data-map-address-province]").val(i.province),e.find("[data-map-address-city]").val(i.city),e.find("[data-map-address-district]").val(i.district),e.find("[data-map-address-detail]").val(i.street+i.streetNumber),e.find("[data-map-lat]").val(t.lat),e.find("[data-map-lng]").val(t.lng),e.trigger("baidu-map-widget.change",[{address:i.province+i.city+i.district+i.street+i.streetNumber,addressProvince:i.province,addressCity:i.city,addressDistrict:i.district,addressDetail:i.street+i.streetNumber,lat:t.lat,lng:t.lng}])})},this.searchTimer=null,this.search=function(t){n.searchTimer&&clearTimeout(n.searchTimer),n.searchTimer=setTimeout(function(){a.getPoint(t,function(a){e.find("[data-map-search]").val(t),n.map.centerAndZoom(a,15),n.setMarkerPoint(a)})},500)}};$.fn.extend({baiduMapWidget:function(){if($(this).length>1)return alert("ImagesWidget only accept one dom"),null;var e=$(this).data("widget");return e||(e=new t(this),$(this).data("widget",e),e)}}),$(function(){$("[data-baidu-map-widget]").each(function(t,e){$(e).baiduMapWidget().init()})})}}};module.exports=BaiduMapWidget;