1/** 2 * jQuery ddYMap Plugin 3 * @version 1.4 (2015-07-23) 4 * 5 * @desc A jQuery library that allows Yandex.Maps to be rendered on a page in a simple way. 6 * 7 * @requires jQuery 1.10.2. 8 * @requires Yandex.Maps 2.1. 9 * 10 * Parameters of the â$.fn.ddYMapâ method (transferred as plain object). 11 * @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 12 * @param placemarks[i] {Object} - Placemark data. @required 13 * @param placemarks[i].latLng {Array} - Placemark coordinates (latitude and longitude). @required 14 * @param [placemarks[i].content=''] {string} - Balloon content. 15 * @param [defaultZoom=15] {number} - Default map zoom. 16 * @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. 17 * @param [scrollZoom=false] {boolean} - Allow zoom while scrolling. 18 * @param [mapCenterOffset=[0, 0]] {Array} - Center offset of the map with respect to the center of the map container in pixels. 19 * @param [placemarkOptions={}] {Object} - Placemark options. 20 * @param [controls=[{name: 'zoomControl'},{name: 'typeSelector'},{name: 'fullscreenControl'},{name: 'geolocationControl'},{name: 'rulerControl'}]] {Object} - An array of controls to be added onto the map. 21 * @param [mapOptions={suppressMapOpenBlock: true}] {Object} - Represents yandex map options to be passed to the constructor. 22 * 23 * @link http://code.divandesign.biz/jquery/ddymap/1.4 24 * 25 * @copyright 2015, DivanDesign 26 * http://www.DivanDesign.biz 27 */ 28 29(function($){ 30$.extend(true, {ddYMap: { 31 defaults: { 32 placemarks: new Array(), 33 element: 'map', 34 defaultZoom: 15, 35 defaultType: 'map', 36 scrollZoom: false, 37 mapCenterOffset: false, 38 placemarkOptions: {}, 39 controls: [ 40 {name: 'zoomControl'}, 41 {name: 'typeSelector'}, 42 {name: 'fullscreenControl'}, 43 {name: 'geolocationControl'}, 44 {name: 'rulerControl'} 45 ], 46 mapOptions: { 47 suppressMapOpenBlock: true 48 } 49 }, 50 //TODO: пеÑенеÑÑи меÑод в $.ddTools 51 verifyRenamedParams: function(params, compliance){ 52 var result = {}, 53 msg = new Array(); 54 55 //ÐеÑебиÑаем ÑаблиÑÑ ÑооÑвеÑÑÑÐ²Ð¸Ñ 56 $.each(compliance, function(newName, oldName){ 57 //ÐÑли ÑÑаÑÑй паÑамеÑÑ Ð·Ð°Ð´Ð°Ð½, а новÑй âÂ Ð½ÐµÑ 58 if ($.type(params[oldName]) != 'undefined' && $.type(params[newName]) == 'undefined'){ 59 //Ðададим 60 result[newName] = params[oldName]; 61 msg.push('â' + oldName + 'â must be renamed as â' + newName + 'â;'); 62 } 63 }); 64 65 if (msg.length > 0){ 66 console.group('$.ddYMap'); 67 console.warn('Some of the parameters have been renamed. Please, correct the following parameters:'); 68 69 for (var i = 0; i < msg.length; i++){ 70 console.warn(msg[i]); 71 } 72 73 console.groupEnd(); 74 } 75 76 return result; 77 }, 78 preparePlacemarks: function(params){ 79 var geoObjects = new ymaps.GeoObjectCollection(); 80 81 if (!$.isArray(params.placemarks)){return geoObjects;} 82 83 //ÐÑли пеÑедана пÑоÑÑо паÑа кооÑÐ´Ð¸Ð½Ð°Ñ 84 if (params.placemarks.length == 2 && $.isNumeric(params.placemarks[0]) && $.isNumeric(params.placemarks[1])){ 85 //ÐнаÑÐ¸Ñ ÑоÑка одна 86 geoObjects.add(new ymaps.Placemark(params.placemarks, {}, params.placemarkOptions)); 87 }else{ 88 //ÐеÑебеÑÑм вÑе ÑоÑки 89 for (var i = 0; i < params.placemarks.length; i++){ 90 //ÐÑли кооÑдинаÑÑ Ð·Ð°Ð´Ð°Ð½Ñ 91 if ( 92 $.isPlainObject(params.placemarks[i]) && 93 $.isArray(params.placemarks[i].latLng) && 94 params.placemarks[i].latLng.length == 2 95 ){ 96 //СоздаÑм меÑÐºÑ 97 geoObjects.add(new ymaps.Placemark(params.placemarks[i].latLng, { 98 balloonContent: $.type(params.placemarks[i].content) == 'string' ? $.trim(params.placemarks[i].content) : '' 99 }, params.placemarkOptions)); 100 } 101 } 102 } 103 104 return geoObjects; 105 }, 106 init: function(params){ 107 var _this = this; 108
109 $.extend(params, _this.verifyRenamedParams(params, { 110 'defaultZoom': 'zoom', 111 'placemarks': 'latLng' 112 })); 113 114 params = $.extend({}, _this.defaults, params); 115 116 ymaps.ready(function(){ 117 //ÐодгоÑавливаем ÑоÑки 118 var geoObjects = _this.preparePlacemarks(params), 119 //ÐолиÑеÑÑво ÑоÑек 120 geoObjects_len = geoObjects.getLength(); 121 122 //ÐÑли ÑоÑки Ð·Ð°Ð´Ð°Ð½Ñ 123 if (geoObjects_len > 0){ 124 params.$element = $(params.element); 125 126 //УÑÑановим вÑÑоÑÑ Ñ ÑлеменÑа, еÑли она не задана 127 if (params.$element.height() == 0){ 128 params.$element.height(400); 129 } 130 131 //СоздаÑм каÑÑÑ 132 var map = new ymaps.Map(params.element, { 133 center: geoObjects.get(0).geometry.getCoordinates(), 134 zoom: params.defaultZoom, 135 type: 'yandex#' + params.defaultType, 136 controls: [] 137 }, params.mapOptions); 138 139 //ÐÑли Ð·Ð°Ð´Ð°Ð½Ñ ÐºÐ¾ÑÑÐ¾Ð»Ñ 140 if($.isArray(params.controls)){ 141 $.each(params.controls, function(index, control){ 142 if(control.name){ 143 //ÐобавлÑем Ð¸Ñ 144 map.controls.add(control.name, control.options); 145 } 146 }); 147 } 148 149 //ÐÑли зÑм не нÑжен 150 if (!params.scrollZoom){ 151 //ÐÑклÑÑим маÑÑÑабиÑование колеÑом мÑÑи (Ñ.к. в 2.1 по ÑмолÑÐ°Ð½Ð¸Ñ Ð¾Ð½ вклÑÑÑн) 152 map.behaviors.disable('scrollZoom'); 153 } 154 155 //ÐобавлÑем меÑки на каÑÑÑ 156 map.geoObjects.add(geoObjects); 157 158 //ÐÑли меÑок неÑколÑко 159 if (geoObjects_len > 1){ 160 //ÐÑли ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ñ ÐºÐ°ÑÑой ÑкÑÑÑ 161 if (params.$element.is(':hidden')){ 162 //ÐÑи пеÑвом изменении ÑазмеÑа (инаÑе, еÑли каÑÑа бÑла ÑкÑÑÑа, вÑÐ¹Ð´ÐµÑ Ð¿Ð»Ð¾Ñ Ð¾) 163 map.events.once('sizechange', function(){ 164 //Ðадо, ÑÑÐ¾Ð±Ñ Ð¾Ð½Ð¸ вÑе влезли 165 map.setBounds(geoObjects.getBounds()); 166 }); 167 }else{ 168 //Ðадо, ÑÑÐ¾Ð±Ñ Ð¾Ð½Ð¸ вÑе влезли 169 map.setBounds(geoObjects.getBounds()); 170 } 171 } 172 173 //ÐÑли нÑжно ÑмеÑение ÑенÑÑа каÑÑÑ 174 if ($.isArray(params.mapCenterOffset) && params.mapCenterOffset.length == 2){ 175 var position = map.getGlobalPixelCenter(); 176 177 map.setGlobalPixelCenter([position[0] - params.mapCenterOffset[0], position[1] - params.mapCenterOffset[1]]); 178 } 179 180 params.$element.data('ddYMap', {map: map}).trigger('ddAfterInit'); 181 } 182 }); 183 } 184}}); 185 186$.fn.ddYMap = function(params){ 187 var _this = $.ddYMap; 188 189 return $(this).each(function(){ 190 _this.init($.extend(params, {element: this})); 191 }); 192}; 193})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.