Browse Source

Merge pull request #401 from jasongrout/maps

fix leaflet maps
Steven Silvester 8 years ago
parent
commit
246125fa03
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/leafletwidget/widget.ts

+ 4 - 2
src/leafletwidget/widget.ts

@@ -40,7 +40,7 @@ class MapWidget extends Widget {
     this.node.tabIndex = -1;
     this.addClass(MAP_CLASS);
 
-    this._map = leaflet.map(this.node);
+    this._map = leaflet.map(this.node).fitWorld();
     leaflet.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
         attribution : 'Map data (c) <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',
         min_zoom : 0,
@@ -85,7 +85,9 @@ class MapWidget extends Widget {
       return;
     }
     let content = JSON.parse(this._context.model.toString());
-    this._map.removeLayer(this._geojsonLayer);
+    if (this._geojsonLayer) {
+      this._map.removeLayer(this._geojsonLayer);
+    }
     this._geojsonLayer = leaflet.geoJson(content, {
       pointToLayer: function (feature, latlng) {
           return leaflet.circleMarker(latlng);