-
Notifications
You must be signed in to change notification settings - Fork 1
/
jQuery.ddMap.min.js
2 lines (2 loc) · 3.02 KB
/
jQuery.ddMap.min.js
1
2
/* jQuery.ddMap v2.1 (2024-02-27) | © https://Ronef.ru */
!function(e){class t{static isStaticInited=!1;static initStatic(t){if(!this.isStaticInited&&(this.isStaticInited=!0,"undefined"==typeof ymaps)){var n="//api-maps.yandex.ru/2.1/?lang="+navigator.language;t.apiKey.length>0&&(n+="&apikey="+t.apiKey),e("head").append('<script defer src="'+n+'"><\/script>')}}constructor(e){var t=this,n=t.constructor;t.markers=new Array,t.$element="map",t.defaultZoom=15,t.defaultType="map",t.scrollZoom=!1,t.mapCenterOffset=!1,t.markerOptions={},t.controls=[{name:"zoomControl"},{name:"typeSelector"},{name:"fullscreenControl"},{name:"geolocationControl"},{name:"rulerControl"}],t.mapOptions={suppressMapOpenBlock:!0},t.apiConnectionAttempts=0,t.setProps(e),n.initStatic({apiKey:void 0===e.apiKey?"":e.apiKey}),t.constructor_init()}constructor_init(){var t=this;"undefined"==typeof ymaps?(t.apiConnectionAttempts++,t.apiConnectionAttempts<10&&setTimeout(t.constructor_init.bind(t),500+100*t.apiConnectionAttempts)):ymaps.ready((function(){var n=t.prepareMarkers(),i=n.getLength();if(i>0){t.$element=e(t.$element),t.$element.trigger("ddBeforeInit"),t.$element.empty(),0==t.$element.height()&&t.$element.height(400);var r=new ymaps.Map(t.$element.get(0),{center:n.get(0).geometry.getCoordinates(),zoom:t.defaultZoom,type:"yandex#"+t.defaultType,controls:[]},t.mapOptions);if(Array.isArray(t.controls)&&t.controls.forEach((e=>{e.name&&r.controls.add(e.name,e.options)})),t.scrollZoom||r.behaviors.disable("scrollZoom"),r.geoObjects.add(n),i>1&&(t.$element.is(":hidden")?r.events.once("sizechange",(function(){r.setBounds(n.getBounds())})):r.setBounds(n.getBounds())),Array.isArray(t.mapCenterOffset)&&2==t.mapCenterOffset.length){var o=r.getGlobalPixelCenter();r.setGlobalPixelCenter([o[0]-t.mapCenterOffset[0],o[1]-t.mapCenterOffset[1]])}t.$element.on("resize",(()=>{r.container.fitToViewport()})).data("ddMap",{map:r}).trigger("ddAfterInit")}}))}prepareMarkers(){var t=this,n=new ymaps.GeoObjectCollection;return Array.isArray(t.markers)?(2==t.markers.length&&e.isNumeric(t.markers[0])&&e.isNumeric(t.markers[1])?n.add(new ymaps.Placemark(t.markers,{},t.markerOptions)):t.markers.forEach((i=>{if(e.isPlainObject(i)&&Array.isArray(i.latLng)&&2==i.latLng.length){var r=e.extend(!0,{},t.markerOptions);"object"==typeof i.icon&&"string"==typeof i.icon.src&&i.icon.src.length>0&&"object"==typeof i.icon.size&&e.isNumeric(i.icon.size.width)&&e.isNumeric(i.icon.size.height)&&(i.icon.size.width=parseInt(i.icon.size.width),i.icon.size.height=parseInt(i.icon.size.height),r.iconLayout="default#image",r.iconImageHref=i.icon.src,r.iconImageSize=[i.icon.size.width,i.icon.size.height],r.iconImageOffset=[i.icon.size.width/-2,-1*i.icon.size.height]),n.add(new ymaps.Placemark(i.latLng,{balloonContent:"string"==typeof i.content?e.trim(i.content):""},r))}})),n):n}setProps(t){var n=this;e.isPlainObject(t)&&Object.entries(t).forEach((([t,i])=>{void 0!==n[t]&&(e.isPlainObject(n[t])?e.extend(n[t],i):n[t]=i)}))}}e.fn.ddMap=function(n){return e(this).each((function(){new t(e.extend(n,{$element:this}))}))}}(jQuery);