-
Notifications
You must be signed in to change notification settings - Fork 1
/
jQuery.ddYMap-1.4.min.js
32 lines (31 loc) · 4.13 KB
/
jQuery.ddYMap-1.4.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* jQuery ddYMap Plugin
* @version 1.4 (2015-07-23)
*
* @desc A jQuery library that allows Yandex.Maps to be rendered on a page in a simple way.
*
* @requires jQuery 1.10.2.
* @requires Yandex.Maps 2.1.
*
* Parameters of the “$.fn.ddYMap” method (transferred as plain object).
* @param placemarks {Array} - Array of placemarks to be put on the map. If there is more than one placemark, the map will be scaled to make all the placemarks visible. Also, a pair of coordinates still can be passed (like it was in 1.2 and earlier). @required
* @param placemarks[i] {Object} - Placemark data. @required
* @param placemarks[i].latLng {Array} - Placemark coordinates (latitude and longitude). @required
* @param [placemarks[i].content=''] {string} - Balloon content.
* @param [defaultZoom=15] {number} - Default map zoom.
* @param [defaultType='map'] {'map'|'satellite'|'hybrid'|'publicMap'|'publicMapHybrid'} - Default map type: 'map' — schematic map, 'satellite' — satellite map, 'hybrid' — hybrid map, 'publicMap' — public map, 'publicMapHybrid' - hybrid public map.
* @param [scrollZoom=false] {boolean} - Allow zoom while scrolling.
* @param [mapCenterOffset=[0, 0]] {Array} - Center offset of the map with respect to the center of the map container in pixels.
* @param [placemarkOptions={}] {Object} - Placemark options.
* @param [controls=[{name: 'zoomControl'},{name: 'typeSelector'},{name: 'fullscreenControl'},{name: 'geolocationControl'},{name: 'rulerControl'}]] {Object} - An array of controls to be added onto the map.
* @param [mapOptions={suppressMapOpenBlock: true}] {Object} - Represents yandex map options to be passed to the constructor.
*
* @link http://code.divandesign.biz/jquery/ddymap/1.4
*
* @copyright 2015–2017 DivanDesign {@link http://www.DivanDesign.biz }
*/
(function(b){b.extend(!0,{ddYMap:{defaults:{placemarks:[],element:"map",defaultZoom:15,defaultType:"map",scrollZoom:!1,mapCenterOffset:!1,placemarkOptions:{},controls:[{name:"zoomControl"},{name:"typeSelector"},{name:"fullscreenControl"},{name:"geolocationControl"},{name:"rulerControl"}],mapOptions:{suppressMapOpenBlock:!0}},verifyRenamedParams:function(a,e){var c={},f=[];b.each(e,function(d,e){"undefined"!=b.type(a[e])&&"undefined"==b.type(a[d])&&(c[d]=a[e],f.push("\u201c"+e+"\u201d must be renamed as \u201c"+
d+"\u201d;"))});if(0<f.length){console.group("$.ddYMap");console.warn("Some of the parameters have been renamed. Please, correct the following parameters:");for(var d=0;d<f.length;d++)console.warn(f[d]);console.groupEnd()}return c},preparePlacemarks:function(a){var e=new ymaps.GeoObjectCollection;if(!b.isArray(a.placemarks))return e;if(2==a.placemarks.length&&b.isNumeric(a.placemarks[0])&&b.isNumeric(a.placemarks[1]))e.add(new ymaps.Placemark(a.placemarks,{},a.placemarkOptions));else for(var c=0;c<
a.placemarks.length;c++)b.isPlainObject(a.placemarks[c])&&b.isArray(a.placemarks[c].latLng)&&2==a.placemarks[c].latLng.length&&e.add(new ymaps.Placemark(a.placemarks[c].latLng,{balloonContent:"string"==b.type(a.placemarks[c].content)?b.trim(a.placemarks[c].content):""},a.placemarkOptions));return e},init:function(a){var e=this;b.extend(a,e.verifyRenamedParams(a,{defaultZoom:"zoom",placemarks:"latLng"}));a=b.extend({},e.defaults,a);ymaps.ready(function(){var c=e.preparePlacemarks(a),f=c.getLength();
if(0<f){a.$element=b(a.element);0==a.$element.height()&&a.$element.height(400);var d=new ymaps.Map(a.element,{center:c.get(0).geometry.getCoordinates(),zoom:a.defaultZoom,type:"yandex#"+a.defaultType,controls:[]},a.mapOptions);b.isArray(a.controls)&&b.each(a.controls,function(a,b){b.name&&d.controls.add(b.name,b.options)});a.scrollZoom||d.behaviors.disable("scrollZoom");d.geoObjects.add(c);if(1<f)if(a.$element.is(":hidden"))d.events.once("sizechange",function(){d.setBounds(c.getBounds())});else d.setBounds(c.getBounds());
b.isArray(a.mapCenterOffset)&&2==a.mapCenterOffset.length&&(f=d.getGlobalPixelCenter(),d.setGlobalPixelCenter([f[0]-a.mapCenterOffset[0],f[1]-a.mapCenterOffset[1]]));a.$element.data("ddYMap",{map:d}).trigger("ddAfterInit")}})}}});b.fn.ddYMap=function(a){var e=b.ddYMap;return b(this).each(function(){e.init(b.extend(a,{element:this}))})}})(jQuery);