Commit 3f17b179 authored by Scott Ames's avatar Scott Ames
Browse files

finished viewCenter, pulling Kaitlyn's changes

parent 1056e738
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import ProjectionControl from "./ProjectionControl";
import MousePositionControl from "./MousePositionControl";
import AstroDrawControl from "./AstroDrawControl";
import AstroSidebarControl from "./SidebarControl";
import ViewCenterControl from "./ViewCenterControl";

/**
 * @class AstroControlManager
@@ -28,6 +29,8 @@ export default L.AstroControlManager = L.Class.extend({

    this._zoomControl = new L.Control.Zoom();

    this._viewCenterControl = new ViewCenterControl();

    let drawnItems = new L.FeatureGroup();
    map.addLayer(drawnItems);

@@ -53,13 +56,13 @@ export default L.AstroControlManager = L.Class.extend({
    map.addControl(this._mouseControl);
    map.addControl(this._drawControl);
    map.addControl(this._zoomControl);
    map.addControl(this._viewCenterControl);
    map.addControl(new L.Control.Scale({ imperial: false }));

    let that = this;
    map.on("fullscreenchange", function() {
      if (map.isFullscreen()) {
        map.addControl(that._sidebarControl);
        console.log(that._sidebarControl.getContainer());
      } else {
        map.removeControl(that._sidebarControl);
      }
+42 −0
Original line number Diff line number Diff line
import L from "leaflet";

export default L.Control.ViewCenter = L.Control.extend({
  options: {
    position: "topleft"
  },

  initialize: function(map) {
    this._centerLatLng = [0, 0];
  },

  onAdd: function(map) {
    let container = L.DomUtil.create("div", "leaflet-bar");
    let className = "leaflet-control-view-center";

    this._createButton(
      this.options,
      className,
      container,
      this.setCenterView,
      map
    );

    return container;
  },
  _createButton: function(options, className, container, fn, map) {
    let link = L.DomUtil.create("a", className, container);
    link.href = "#";
    link.title = "Center map";
    L.DomEvent //.on(link, "click", L.DomEvent.stopPropagation)
      //.on(link, "click", L.DomEvent.preventDefault)
      .on(
        link,
        "click",
        function() {
          map.flyTo([0, 0], map.getZoom());
        },
        map
      );
    return link;
  }
});
+4 −0
Original line number Diff line number Diff line
@@ -26,3 +26,7 @@ Controls the CSS for projection buttons when there is no available projection
  background: #fff;
  border-radius: 5px;
}

.leaflet-control-view-center {
  background-image: url("https://raw.github.com/pwldp/leaflet.viewcenter/master/icon-viewcenter.png");
}