# Source: bemap-leaflet/bemap-map-leaflet-popup.js

    /**
     * Add a popup to the map
     * @public
     * @param {bemap.Popup} popup
     * @param {object} options
     * @return {bemap.LeafletMap} this
     */
     bemap.LeafletMap.prototype.addPopup = function(popup, options) {
       if (popup !== null && bemap.inheritsof(popup, bemap.Popup)) {
         popup.native = L.popup({
           autoPan: true
         });

         if (popup.map === null) {
           popup.map = this;
         }
         popup.native.setLatLng(popup.getCoordinate().getLatLonArray());
         popup.native.setContent(popup.getInformation());
         if (!this.native.popups) {
           this.native.popups = [];
         }
         this.native.popups.push(popup.native);
         popup.native.addTo(this.native);
       }
       return this;
     };

    /**
     * Remove a popup from the map.
     * @public
     * @param {bemap.Popup} popup the popup to remove from the map.
     * @return {bemap.LeafletMap} this;
     */
    bemap.LeafletMap.prototype.removePopup = function(popup) {
      if (popup !== null && bemap.inheritsof(popup, bemap.Popup)) {
        this.native.removeLayer(popup.native);
        popup.map = null;
      }
      return this;
    };

    /**
    * Remove all the popups from the map.
    * @return {bemap.LeafletMap} this;
     */
    bemap.LeafletMap.prototype.clearPopup = function() {
    var that = this.native;
    if (this.native.popups && this.native.popups.length !== 0) {
      this.native.popups.forEach(function(popup, index, object) {
        that.removeLayer(popup);
        object.splice(index, 1);
      });
      return that;
    }
    //alternative way to close all popups
     /*if ($(".leaflet-popup-close-button")[0]) {
        $(".leaflet-popup-close-button")[0].click();
      }*/
    };

    /**
     * Set the coordinate of the popup.
     * @param {bemap.Popup} popup the popup of wich to set the coordinate.
     * @param {bemap.Coordinate} coordinate the new coordinate.
     * @param {object} options Options.
     * @param {bemap.Layer} options.panningMap enable the map panning animation. move map from the current position to the popup anchor at the center of map.
     * @return {bemap.OlMap} this.
     */
    bemap.LeafletMap.prototype.setCoordinatePopup = function(popup, coordinate, options) {
      if (popup !== null && bemap.inheritsof(popup, bemap.Popup)) {
        popup.coordinate = coordinate;
        if (popup.native !== null) {
          popup.native.setLatLng(popup.getCoordinate().getLatLonArray());
        }
      }
      return this;
    };