Skip to content

Commit

Permalink
Fix unsync() combined with cursorSync
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed May 19, 2016
1 parent 0a9261d commit 5cb382d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
32 changes: 19 additions & 13 deletions L.Map.Sync.js
Expand Up @@ -33,24 +33,28 @@
if (options.syncCursor) {
map.cursor = L.circleMarker([0, 0], options.syncCursorMarkerOptions).addTo(map);

var cursors = this._cursors;
cursors.push(map.cursor);
this._cursors.push(map.cursor);

this.on('mousemove', function (e) {
cursors.forEach(function (cursor) {
cursor.setLatLng(e.latlng);
});
});
this.on('mouseout', function (e) {
cursors.forEach(function (cursor) {
// TODO: hide cursor in stead of moving to 0, 0
cursor.setLatLng([0, 0]);
});
});
this.on('mousemove', this._cursorSyncMove, this);
this.on('mouseout', this._cursorSyncOut, this);
}
return this;
},

_cursorSyncMove: function (e) {
this._cursors.forEach(function (cursor) {
cursor.setLatLng(e.latlng);
});
},

_cursorSyncOut: function (e) {
this._cursors.forEach(function (cursor) {
// TODO: hide cursor in stead of moving to 0, 0
cursor.setLatLng([0, 0]);
});
},


// unsync maps from each other
unsync: function (map) {
var self = this;
Expand All @@ -65,6 +69,8 @@
}
});
}
this.off('mousemove', this._cursorSyncMove, this);
this.off('mouseout', this._cursorSyncOut, this);

return this;
},
Expand Down
6 changes: 6 additions & 0 deletions examples/syncCursor_dual.html
Expand Up @@ -46,6 +46,12 @@
map1.sync(map2, {syncCursor: true});
map2.sync(map1, {syncCursor: true});

// unsync after 5s.
setTimeout(function () {
map1.unsync(map2);
map2.unsync(map1);
}, 5000);

</script>
</body>
</html>

0 comments on commit 5cb382d

Please sign in to comment.