Skip to content
Browse files

fixes #16 Added remove method to delete map gracefully

  • Loading branch information...
1 parent aa1a05b commit 2175602294b7b76e90df290ff9a1a6710cbee572 @bjornd committed
Showing with 20 additions and 4 deletions.
  1. +15 −4 lib/world-map.js
  2. +5 −0 tests/markers.html
View
19 lib/world-map.js
@@ -80,7 +80,8 @@ jvm.WorldMap = function(params) {
this.regionsColors = {};
this.regionsData = {};
- this.container = this.params.container;
+ this.container = $('<div>').css({width: '100%', height: '100%'});
+ this.params.container.append( this.container );
this.container.data('mapObject', this);
this.container.css({
position: 'relative',
@@ -92,9 +93,10 @@ jvm.WorldMap = function(params) {
this.setBackgroundColor(this.params.backgroundColor);
- $(window).resize(function(){
+ this.onResize = function(){
map.setSize();
- });
+ }
+ $(window).resize(this.onResize);
for (e in jvm.WorldMap.apiEvents) {
if (this.params[e]) {
@@ -102,7 +104,7 @@ jvm.WorldMap = function(params) {
}
}
- this.canvas = new jvm.VectorCanvas(this.params.container[0], this.width, this.height);
+ this.canvas = new jvm.VectorCanvas(this.container[0], this.width, this.height);
if ( ('ontouchstart' in window) || (window.DocumentTouch && document instanceof DocumentTouch) ) {
this.bindContainerTouchEvents();
@@ -786,6 +788,15 @@ jvm.WorldMap.prototype = {
);
}
}
+ },
+
+ /**
+ * Gracefully remove the map and and all its accessories, unbind event handlers.
+ */
+ remove: function(){
+ this.label.remove();
+ this.container.remove();
+ $(window).unbind('resize', this.onResize);
}
};
View
5 tests/markers.html
@@ -159,6 +159,9 @@
$('.button-clear-selected-markers').click(function(){
map.clearSelectedMarkers();
});
+ $('.button-remove-map').click(function(){
+ map.remove();
+ });
});
</script>
</head>
@@ -175,5 +178,7 @@
&nbsp;&nbsp;&nbsp;
<input type="button" value="Clear selected regions" class="button-clear-selected-regions"/>
<input type="button" value="Clear selected markers" class="button-clear-selected-markers"/>
+ &nbsp;&nbsp;&nbsp;
+ <input type="button" value="Remove map" class="button-remove-map"/>
</body>
</html>

0 comments on commit 2175602

Please sign in to comment.
Something went wrong with that request. Please try again.