angular-baidu-map
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -41,2 +41,5 @@ /** | ||
* | ||
* @version 1.2.1 | ||
* comments: Accounding to 史魁杰's comments, markers' watcher should have set deep watch equal to true, and previous overlaies should be removed | ||
* | ||
*/ | ||
@@ -130,2 +133,4 @@ (function(global, factory) { | ||
var previousMarkers = []; | ||
var openInfoWindow = function(infoWin) { | ||
@@ -139,3 +144,11 @@ return function() { | ||
for (var i in opts.markers) { | ||
var i = 0; | ||
for (i = 0; i < previousMarkers.length; i++) { | ||
previousMarkers[i].removeEventListener('click', openInfoWindow(infoWindow2)); | ||
map.removeOverlay(previousMarkers[i]); | ||
} | ||
previousMarkers.length = 0; | ||
for (i = 0; i < opts.markers.length; i++) { | ||
var marker = opts.markers[i]; | ||
@@ -155,2 +168,3 @@ var pt = new BMap.Point(marker.longitude, marker.latitude); | ||
map.addOverlay(marker2); | ||
previousMarkers.push(marker2); | ||
@@ -179,3 +193,3 @@ if (!marker.title && !marker.content) { | ||
mark(); | ||
}); | ||
}, true); | ||
@@ -182,0 +196,0 @@ }, |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("angular")):"function"==typeof define&&define.amd?define(["angular"],t):t(e.angular)}(window,function(e){"use strict";var t=function(e,t){if(!e)throw new Error(t)},n=function(e,t){for(var n in t)"undefined"==typeof e[n]&&(e[n]=t[n])},o=function(){return{restrict:"E",scope:{options:"="},link:function(e,o,i){var r={navCtrl:!0,scaleCtrl:!0,overviewCtrl:!0,enableScrollWheelZoom:!0,zoom:10},a=e.options;n(a,r),t(a.center,"options.center must be set"),t(a.center.longitude,"options.center.longitude must be set"),t(a.center.latitude,"options.center.latitude must be set"),t(a.city,"options.city must be set");var l=new BMap.Map(o.find("div")[0]);if(l.centerAndZoom(new BMap.Point(a.center.longitude,a.center.latitude),a.zoom),a.navCtrl&&l.addControl(new BMap.NavigationControl),a.scaleCtrl&&l.addControl(new BMap.ScaleControl),a.overviewCtrl&&l.addControl(new BMap.OverviewMapControl),a.enableScrollWheelZoom&&l.enableScrollWheelZoom(),l.setCurrentCity(a.city),a.markers){var c=function(e){return function(){this.openInfoWindow(e)}},d=function(){for(var e in a.markers){var t,n=a.markers[e],o=new BMap.Point(n.longitude,n.latitude);if(n.icon){var i=new BMap.Icon(n.icon,new BMap.Size(n.width,n.height));t=new BMap.Marker(o,{icon:i})}else t=new BMap.Marker(o);if(l.addOverlay(t),!n.title&&!n.content)return;var r=new BMap.InfoWindow("<p>"+(n.title?n.title:"")+"</p><p>"+(n.content?n.content:"")+"</p>",{enableMessage:!!n.enableMessage});t.addEventListener("click",c(r))}};d(),e.$watch("options.center",function(t,n){a=e.options,l.centerAndZoom(new BMap.Point(a.center.longitude,a.center.latitude),a.zoom),d()},!0),e.$watch("options.markers",function(e,t){d()})}},template:'<div style="width: 100%; height: 100%;"></div>'}},i=e.module("baiduMap",[]);i.directive("baiduMap",[o])}); | ||
!function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("angular")):"function"==typeof define&&define.amd?define(["angular"],t):t(e.angular)}(window,function(e){"use strict";var t=function(e,t){if(!e)throw new Error(t)},n=function(e,t){for(var n in t)"undefined"==typeof e[n]&&(e[n]=t[n])},o=function(){return{restrict:"E",scope:{options:"="},link:function(e,o,r){var i={navCtrl:!0,scaleCtrl:!0,overviewCtrl:!0,enableScrollWheelZoom:!0,zoom:10},a=e.options;n(a,i),t(a.center,"options.center must be set"),t(a.center.longitude,"options.center.longitude must be set"),t(a.center.latitude,"options.center.latitude must be set"),t(a.city,"options.city must be set");var l=new BMap.Map(o.find("div")[0]);if(l.centerAndZoom(new BMap.Point(a.center.longitude,a.center.latitude),a.zoom),a.navCtrl&&l.addControl(new BMap.NavigationControl),a.scaleCtrl&&l.addControl(new BMap.ScaleControl),a.overviewCtrl&&l.addControl(new BMap.OverviewMapControl),a.enableScrollWheelZoom&&l.enableScrollWheelZoom(),l.setCurrentCity(a.city),a.markers){var c=[],d=function(e){return function(){this.openInfoWindow(e)}},s=function(){var e=0;for(e=0;e<c.length;e++)c[e].removeEventListener("click",d(i)),l.removeOverlay(c[e]);for(c.length=0,e=0;e<a.markers.length;e++){var t,n=a.markers[e],o=new BMap.Point(n.longitude,n.latitude);if(n.icon){var r=new BMap.Icon(n.icon,new BMap.Size(n.width,n.height));t=new BMap.Marker(o,{icon:r})}else t=new BMap.Marker(o);if(l.addOverlay(t),c.push(t),!n.title&&!n.content)return;var i=new BMap.InfoWindow("<p>"+(n.title?n.title:"")+"</p><p>"+(n.content?n.content:"")+"</p>",{enableMessage:!!n.enableMessage});t.addEventListener("click",d(i))}};s(),e.$watch("options.center",function(t,n){a=e.options,l.centerAndZoom(new BMap.Point(a.center.longitude,a.center.latitude),a.zoom),s()},!0),e.$watch("options.markers",function(e,t){s()},!0)}},template:'<div style="width: 100%; height: 100%;"></div>'}},r=e.module("baiduMap",[]);r.directive("baiduMap",[o])}); |
{ | ||
"name": "BaiduMapForAngularJS", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"homepage": "https://github.com/leftstick/BaiduMapForAngularJS", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -6,3 +6,3 @@ ## Basic Usage | ||
Latest stable version: v1.1.0 | ||
Latest stable version: v1.2.0 | ||
@@ -9,0 +9,0 @@ ```shell |
{ | ||
"name": "angular-baidu-map", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A baidu-map directive for AngularJS", | ||
@@ -5,0 +5,0 @@ "main": "./src/baiduMap.js", |
@@ -41,2 +41,5 @@ /** | ||
* | ||
* @version 1.2.1 | ||
* comments: Accounding to 史魁杰's comments, markers' watcher should have set deep watch equal to true, and previous overlaies should be removed | ||
* | ||
*/ | ||
@@ -130,2 +133,4 @@ (function(global, factory) { | ||
var previousMarkers = []; | ||
var openInfoWindow = function(infoWin) { | ||
@@ -139,3 +144,11 @@ return function() { | ||
for (var i in opts.markers) { | ||
var i = 0; | ||
for (i = 0; i < previousMarkers.length; i++) { | ||
previousMarkers[i].removeEventListener('click', openInfoWindow(infoWindow2)); | ||
map.removeOverlay(previousMarkers[i]); | ||
} | ||
previousMarkers.length = 0; | ||
for (i = 0; i < opts.markers.length; i++) { | ||
var marker = opts.markers[i]; | ||
@@ -155,2 +168,3 @@ var pt = new BMap.Point(marker.longitude, marker.latitude); | ||
map.addOverlay(marker2); | ||
previousMarkers.push(marker2); | ||
@@ -179,3 +193,3 @@ if (!marker.title && !marker.content) { | ||
mark(); | ||
}); | ||
}, true); | ||
@@ -182,0 +196,0 @@ }, |
31245
429