-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathya-map-2.1.min.js
2 lines (2 loc) · 9.91 KB
/
ya-map-2.1.min.js
1
2
/*! yaMap 16-09-2015 */
"use strict";angular.module("yaMap",[]).constant("GEOMETRY_TYPES",{POINT:"Point",LINESTRING:"LineString",RECTANGLE:"Rectangle",POLYGON:"Polygon",CIRCLE:"Circle"}).provider("yaMapSettings",function(){var a={version:"2.1",lang:"ru_RU",order:"longlat"};this.setLanguage=function(b){return a.lang=b,this},this.setOrder=function(b){return a.order=b,this},this.$get=[function(){return a}]}).factory("mapApiLoad",["yaMapSettings",function(a){var b=!1,c=[],d=function(){for(var a;c.length;)a=c.splice(0,1),a[0]()},e="//api-maps.yandex.ru/"+a.version+"/?load=package.full&lang="+a.lang+"&coordorder="+a.order,f=!1,g=function(a,b){if(!f){f=!0;var c=document.createElement("script");c.type="text/javascript",c.readyState?c.onreadystatechange=function(){("loaded"==c.readyState||"complete"==c.readyState)&&(c.onreadystatechange=null,b())}:c.onload=function(){b()},c.src=a,document.getElementsByTagName("head")[0].appendChild(c)}};return function(a){c.push(a),b?d():f||g(e,function(){ymaps.ready(function(){b=!0,d()})})}}]).service("yaLayer",[function(){this.create=function(a,b){return new ymaps.Layer(a,b)}}]).service("yaMapType",[function(){this.create=function(a,b){return new ymaps.MapType(a,b)}}]).service("layerStorage",["mapApiLoad",function(a){this.get=function(b){if(this._storage)b(this._storage);else{var c=this;a(function(){c._storage=ymaps.layer.storage,b(c._storage)})}}}]).service("mapTypeStorage",["mapApiLoad",function(a){this.get=function(b){if(this._storage)b(this._storage);else{var c=this;a(function(){c._storage=ymaps.mapType.storage,b(c._storage)})}}}]).service("yaSubscriber",function(){var a=/^yaEvent(\w*)?([A-Z]{1}[a-z]+)$/;this.subscribe=function(b,c,d,e){var f=a.exec(d),g=f[2].toLowerCase(),h=f[1]?f[1][1].toLowerCase()+f[1].substring(1):void 0;e[d]=function(a){return c(e.$parent||e,a)};var i=h?b[h].events:b.events;i.add(g,function(a){setTimeout(function(){e.$apply(function(){e[d]({$event:a})})})})}}).service("templateLayoutFactory",["mapApiLoad",function(a){this._cache={},this.get=function(a){return this._cache[a]||a},this.create=function(b,c,d){if(!this._cache[b]){var e=this;a(function(){e._cache[b]=ymaps.templateLayoutFactory.createClass(c,d)})}}}]).directive("yaTemplateLayout",["templateLayoutFactory",function(a){return{restrict:"E",priority:1001,scope:{overrides:"=yaOverrides"},compile:function(b){var c=b.html();return b.children().remove(),function(b,d,e){if(!e.yaKey)throw new Error('not require attribute "key"');var f=e.yaKey;a.create(f,c,b.overrides)}}}}]).controller("YaMapCtrl",["$scope","mapApiLoad",function(a,b){var c=this;b(function(){c.addGeoObjects=function(b){a.map.geoObjects.add(b)},c.removeGeoObjects=function(b){a.map.geoObjects.remove(b)},c.addControl=function(b,c){a.map.controls.add(b,c)},c.getMap=function(){return a.map},c.addImageLayer=function(b,c){var d=new ymaps.Layer(b,c);a.map.layers.add(d)},c.addHotspotLayer=function(b,c,d){var e=new ymaps.hotspot.ObjectSource(b,c),f=new ymaps.hotspot.Layer(e,d);a.map.layers.add(f)}})}]).directive("yaMap",["$compile","mapApiLoad","yaMapSettings","$window","yaSubscriber","$parse","$q","$timeout",function(a,b,c,d,e,f,g,h){return{restrict:"E",scope:{yaCenter:"@",yaType:"@",yaBeforeInit:"&",yaAfterInit:"&"},compile:function(c){var d=c.children(),i=null;return c.children().remove(),function(c,j,k){var l=function(a){try{return c.$eval(a)}catch(b){return a}},m=function(a){return i&&i.reject(),i=g.defer(),a?angular.isArray(a)?h(function(){i.resolve(a)}):angular.isString(a)&&b(function(){ymaps.geocode(a,{results:1}).then(function(a){var b=a.geoObjects.get(0);c.$apply(function(){i.resolve(b.geometry.getCoordinates())})},function(a){c.$apply(function(){i.reject(a)})})}):b(function(){ymaps.geolocation.get({provider:"yandex"}).then(function(a){h(function(){i.resolve(a.geoObjects.position)})})}),i.promise},n=Number(k.yaZoom),o=k.yaBehaviors?k.yaBehaviors.split(" "):["default"],p=["default"];k.yaControls?p=k.yaControls.split(" "):angular.isDefined(k.yaControls)&&(p=[]);for(var q,r=[],s=[],t=0,u=o.length;u>t;t++)q=o[t],"-"===q[0]?r.push(q.substring(1)):s.push(q);0>n?n=0:n>23&&(n=23);var v,w=function(h){var i=g.defer();return b(function(){c.yaBeforeInit();var b=k.yaOptions?c.$eval(k.yaOptions):void 0;b&&b.projection&&(b.projection=new ymaps.projection[b.projection.type](b.projection.bounds)),c.map=new ymaps.Map(j[0],{center:h,zoom:n,controls:p,type:k.yaType||"yandex#map",behaviors:s},b),c.map.behaviors.disable(r);for(var g in k)if(0===g.indexOf("yaEvent")){var l=f(k[g]);e.subscribe(c.map,l,g,c)}i.resolve(c.map),c.yaAfterInit({$target:c.map}),j.append(d),setTimeout(function(){c.$apply(function(){a(j.children())(c.$parent)})})}),i.promise};c.$watch("yaCenter",function(a){var b=l(a);m(b).then(function(a){if(!v){v=w(a);var b=!0}v.then(function(c){b||c.setCenter(a)})})}),c.$watch("yaType",function(a){a&&v&&v.then(function(b){b.setType(a)})}),c.$on("$destroy",function(){c.map&&c.map.destroy()})}},controller:"YaMapCtrl"}}]).directive("yaControl",["yaSubscriber","templateLayoutFactory","$parse",function(a,b,c){return{restrict:"E",require:"^yaMap",scope:{yaAfterInit:"&"},link:function(d,e,f,g){var h=f.yaType[0].toUpperCase()+f.yaType.substring(1),i=function(a){try{return d.$eval(a)}catch(b){return a}},j=i(f.yaParams),k=f.yaOptions?d.$eval(f.yaOptions):void 0;if(k&&k.layout&&(k.layout=b.get(k.layout)),k&&k.itemLayout&&(k.itemLayout=b.get(k.itemLayout)),j&&j.items){for(var l,m=[],n=0,o=j.items.length;o>n;n++)l=j.items[n],m.push(new ymaps.control.ListBoxItem(l));j.items=m}var p=new ymaps.control[h](j);for(var q in k)k.hasOwnProperty(q)&&p.options.set(q,k[q]);for(q in f)if(0===q.indexOf("yaEvent")){var r=c(f[q]);a.subscribe(p,r,q,d)}g.addControl(p,k),d.yaAfterInit({$target:p})}}}]).controller("CollectionCtrl",["$scope",function(a){this.addGeoObjects=function(b){a.collection.add(b)},this.removeGeoObjects=function(b){a.collection.remove(b)}}]).directive("yaCollection",["$compile","yaMapSettings","$timeout","yaSubscriber","$parse",function(a,b,c,d,e){return{require:"^yaMap",restrict:"E",scope:{yaAfterInit:"&"},compile:function(b){var f=b.contents();return b.children().remove(),function(b,g,h,i){var j=h.yaOptions?b.$eval(h.yaOptions):{},k=angular.isDefined(h.showAll)&&"false"!=h.showAll;if(k){var l,m=i.getMap(),n=function(){l&&c.cancel(l),l=c(function(){m.geoObjects.events.remove("add",n);var a=m.geoObjects.getBounds();a&&m.setBounds(a)},300)};m.geoObjects.events.add("add",n)}b.collection=new ymaps.GeoObjectCollection({},j);for(var o in h)if(0===o.indexOf("yaEvent")){var p=e(h[o]);d.subscribe(b.collection,p,o,b)}i.addGeoObjects(b.collection),b.yaAfterInit({$target:b.collection}),b.$on("$destroy",function(){b.collection&&i.removeGeoObjects(b.collection)}),g.append(f),a(g.children())(b.$parent)}},controller:"CollectionCtrl"}}]).directive("yaCluster",["yaMapSettings","yaSubscriber","$compile","templateLayoutFactory","$parse",function(a,b,c,d,e){return{require:"^yaMap",restrict:"E",scope:{yaAfterInit:"&"},compile:function(a){var f=a.contents();return a.children().remove(),function(a,g,h,i){var j=h.yaOptions?a.$eval(h.yaOptions):{};j&&j.clusterBalloonItemContentLayout&&(j.clusterBalloonItemContentLayout=d.get(j.clusterBalloonItemContentLayout)),j&&j.clusterBalloonContentLayout&&(j.clusterBalloonContentLayout=d.get(j.clusterBalloonContentLayout)),a.collection=new ymaps.Clusterer(j);for(var k in h)if(0===k.indexOf("yaEvent")){var l=e(h[k]);b.subscribe(a.collection,l,k,a)}i.addGeoObjects(a.collection),a.yaAfterInit({$target:a.collection}),a.$on("$destroy",function(){a.collection&&i.removeGeoObjects(a.collection)}),g.append(f),c(g.children())(a.$parent)}},controller:"CollectionCtrl"}}]).directive("yaGeoObject",["GEOMETRY_TYPES","yaSubscriber","templateLayoutFactory","$parse",function(a,b,c,d){return{restrict:"E",require:["^yaMap","?^yaCollection","?^yaCluster"],scope:{yaSource:"=",yaShowBalloon:"=",yaAfterInit:"&"},link:function(e,f,g,h){var i,j=h[2]||h[1]||h[0],k=g.yaOptions?e.$eval(g.yaOptions):void 0;k&&k.balloonContentLayout&&(k.balloonContentLayout=c.get(k.balloonContentLayout)),k.balloonLayout&&(k.balloonLayout=c.get(k.balloonLayout)),k&&k.iconLayout&&(k.iconLayout=c.get(k.iconLayout));var l=function(a,c){i=new ymaps.GeoObject(a,c);for(var f in g)if(0===f.indexOf("yaEvent")){var h=d(g[f]);b.subscribe(i,h,f,e)}j.addGeoObjects(i),e.yaAfterInit({$target:i}),m(g.yaEdit),n(g.yaDraw),o(e.yaShowBalloon)};e.$watch("yaSource",function(b){if(b)if(i){i.geometry.setCoordinates(b.geometry.coordinates),i.geometry.getType()===a.CIRCLE&&i.geometry.setRadius(b.geometry.radius);var c=b.properties;for(var d in c)c.hasOwnProperty(d)&&i.properties.set(d,c[d])}else l(b,k);else i&&j.removeGeoObjects(i)},angular.equals);var m=function(a){angular.isDefined(a)&&"false"!==a?i&&i.editor.startEditing():angular.isDefined(a)&&i&&i.editor.stopEditing()},n=function(a){angular.isDefined(a)&&"false"!==a?i&&i.editor.startDrawing():angular.isDefined(a)&&i&&i.editor.stopDrawing()},o=function(a){a?i&&i.balloon.open():i&&i.balloon.close()};g.$observe("yaEdit",m),g.$observe("yaDraw",n),e.$watch("yaShowBalloon",o),e.$on("$destroy",function(){i&&j.removeGeoObjects(i)})}}}]).directive("yaHotspotLayer",[function(){return{restrict:"E",require:"^yaMap",link:function(a,b,c,d){if(!c.yaUrlTemplate)throw new Error('not exists required attribute "url-template"');if(!c.yaKeyTemplate)throw new Error('not exists required attribute "key-template"');var e=c.yaOptions?a.$eval(c.yaOptions):void 0;d.addHotspotLayer(c.yaUrlTemplate,c.yaKeyTemplate,e)}}}]).directive("yaImageLayer",[function(){return{restrict:"E",require:"^yaMap",link:function(a,b,c,d){if(!c.yaUrlTemplate)throw new Error('not exists required attribute "url-template"');var e=c.yaOptions?a.$eval(c.yaOptions):void 0;d.addImageLayer(c.yaUrlTemplate,e)}}}]).directive("yaDragger",["yaSubscriber","$parse","mapApiLoad",function(a,b,c){return{restrict:"EA",scope:{yaAfterInit:"&"},link:function(d,e,f){var g=f.yaOptions?d.$eval(f.yaOptions):{};c(function(){g.autoStartElement=e[0];var c=new ymaps.util.Dragger(g);for(var h in f)if(0===h.indexOf("yaEvent")){var i=b(f[h]);a.subscribe(c,i,h,d)}d.yaAfterInit({$target:c})})}}}]);