Skip to content

Commit

Permalink
fix issue that markers' watcher should take the deep watch mode. and …
Browse files Browse the repository at this point in the history
…previous markers should be remove after markers changed
  • Loading branch information
leftstick committed Jun 17, 2015
1 parent c1f9e2e commit 0c3ca0a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
18 changes: 16 additions & 2 deletions baiduMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
* <baidu-map options='options' ></baidu-map>
* comments: An improvement that the map should update automatically while coordinates changes
*
* @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
*
*/
(function(global, factory) {
'use strict';
Expand Down Expand Up @@ -126,6 +129,8 @@
}
//create markers

var previousMarkers = [];

var openInfoWindow = function(infoWin) {
return function() {
this.openInfoWindow(infoWin);
Expand All @@ -134,7 +139,15 @@

var mark = 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];
var pt = new BMap.Point(marker.longitude, marker.latitude);
var marker2;
Expand All @@ -149,6 +162,7 @@

// add marker to the map
map.addOverlay(marker2);
previousMarkers.push(marker2);

if (!marker.title && !marker.content) {
return;
Expand All @@ -172,7 +186,7 @@

$scope.$watch('options.markers', function(newValue, oldValue) {
mark();
});
}, true);

},
template: '<div style="width: 100%; height: 100%;"></div>'
Expand Down
2 changes: 1 addition & 1 deletion baiduMap.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BaiduMapForAngularJS",
"version": "1.2.0",
"version": "1.2.1",
"homepage": "https://github.com/leftstick/BaiduMapForAngularJS",
"authors": [
"Howard.Zuo"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-baidu-map",
"version": "1.2.0",
"version": "1.2.1",
"description": "A baidu-map directive for AngularJS",
"main": "./src/baiduMap.js",
"repository": {
Expand Down
18 changes: 16 additions & 2 deletions src/baiduMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
* <baidu-map options='options' ></baidu-map>
* comments: An improvement that the map should update automatically while coordinates changes
*
* @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
*
*/
(function(global, factory) {
'use strict';
Expand Down Expand Up @@ -126,6 +129,8 @@
}
//create markers

var previousMarkers = [];

var openInfoWindow = function(infoWin) {
return function() {
this.openInfoWindow(infoWin);
Expand All @@ -134,7 +139,15 @@

var mark = 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];
var pt = new BMap.Point(marker.longitude, marker.latitude);
var marker2;
Expand All @@ -149,6 +162,7 @@

// add marker to the map
map.addOverlay(marker2);
previousMarkers.push(marker2);

if (!marker.title && !marker.content) {
return;
Expand All @@ -172,7 +186,7 @@

$scope.$watch('options.markers', function(newValue, oldValue) {
mark();
});
}, true);

},
template: '<div style="width: 100%; height: 100%;"></div>'
Expand Down

0 comments on commit 0c3ca0a

Please sign in to comment.