Sha256: a74f2183ba31a9f83d930495b8a141c318fcfafa4b701cd45bf08302ee1f4a3f

Contents?: true

Size: 1.83 KB

Versions: 24

Compression:

Stored size: 1.83 KB

Contents

//= require geoblacklight/viewers/viewer

GeoBlacklight.Viewer.Map = GeoBlacklight.Viewer.extend({

  options: {
    /**
    * Initial bounds of map
    * @type {L.LatLngBounds}
    */
    bbox: [[-82, -144], [77, 161]],
    opacity: 0.75
  },

  overlay: L.layerGroup(),

  load: function() {
    if (this.data.mapGeom) {
      this.options.bbox = L.geoJSONToBounds(this.data.mapGeom);
    }
    this.map = L.map(this.element).fitBounds(this.options.bbox);

    // Add initial bbox to map element for easier testing
    if (this.map.getBounds().isValid()) {
      this.element.setAttribute('data-js-map-render-bbox', this.map.getBounds().toBBoxString());
    }

    this.map.addLayer(this.selectBasemap());
    this.map.addLayer(this.overlay);
    if (this.data.map !== 'index') {
      this.addBoundsOverlay(this.options.bbox);
    }
  },

  /**
   * Add a bounding box overlay to map.
   * @param {L.LatLngBounds} bounds Leaflet LatLngBounds
   */
  addBoundsOverlay: function(bounds) {
    if (bounds instanceof L.LatLngBounds) {
      this.overlay.addLayer(L.polygon([
        bounds.getSouthWest(),
        bounds.getSouthEast(),
        bounds.getNorthEast(),
        bounds.getNorthWest()
      ]));
    }
  },

  /**
   * Remove bounding box overlay from map.
   */
  removeBoundsOverlay: function() {
    this.overlay.clearLayers();
  },

  /**
   * Add a GeoJSON overlay to map.
   * @param {string} geojson GeoJSON string
   */
  addGeoJsonOverlay: function(geojson) {
    var layer = L.geoJSON();
    layer.addData(geojson);
    this.overlay.addLayer(layer);
  },

  /**
  * Selects basemap if specified in data options, if not return positron.
  */
  selectBasemap: function() {
    var _this = this;
    if (_this.data.basemap) {
      return GeoBlacklight.Basemaps[_this.data.basemap];
    } else {
      return GeoBlacklight.Basemaps.positron;
    }
  }
});

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
geoblacklight-4.4.2 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.4.1 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-3.8.1 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.4.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.4.0.rc1 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.3.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.2.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.1.1 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.1.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-3.8.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.0.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.0.0.pre.rc3 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-3.7.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.0.0.pre.rc2 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.0.0.pre.rc1 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-3.6.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-3.5.0 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.0.0.pre.alpha.3 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.0.0.pre.alpha.2 app/assets/javascripts/geoblacklight/viewers/map.js
geoblacklight-4.0.0.pre.alpha.1 app/assets/javascripts/geoblacklight/viewers/map.js