Unverified Commit e933312b authored by Jacob Kaufman's avatar Jacob Kaufman Committed by GitHub
Browse files

Merge pull request #69 from kaitlyndlee/draw

Draw Features
parents bb5c0cd5 2d0f7d8e
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ export default L.Map.AstroMap = L.Map.extend({
    center: [0, 0],
    zoom: 1,
    maxZoom: 8,
    crs: L.CRS.EPSG4326,
    attributionControl: false,
    fullscreenControl: true
  },
@@ -43,6 +42,9 @@ export default L.Map.AstroMap = L.Map.extend({
    this._target = target;
    this._astroProj = new AstroProj();
    this._radii = this._astroProj.getRadii(this._target);

    this._currentLayer = null;

    // Could not work with _
    this.layers = {
      northPolar: new LayerCollection(
@@ -61,10 +63,17 @@ export default L.Map.AstroMap = L.Map.extend({

    this._defaultProj = L.extend({}, L.CRS.EPSG4326, { R: this._radii["a"] });
    this.options["crs"] = this._defaultProj;
    this._currentProj = "EPSG:4326";

    L.setOptions(this, options);
    L.Map.prototype.initialize.call(this, this._mapDiv, this.options);
    this.loadLayerCollection("cylindrical");

    // Listen to baselayerchange event so that we can set the current layer being
    // viewed by the map.
    this.on("baselayerchange", function(e) {
      this.setCurrentLayer(e["layer"]);
    });
  },

  /**
@@ -93,11 +102,14 @@ export default L.Map.AstroMap = L.Map.extend({
        resolutions: [8192, 4096, 2048, 1024, 512, 256, 128],
        origin: [0, 0]
      });
      this._currentProj = proj["code"];
    }

    this.options.crs = newCRS;
    this.setView(center, 1, true);
    this.loadLayerCollection(name);

    // this.fire("projChange", { proj: this._currentProj });
  },

  /**
@@ -120,9 +132,38 @@ export default L.Map.AstroMap = L.Map.extend({

  /**
   * @details Returns the name of the target.
   *
   * @return {String} Name of target.
   */
  target: function() {
    return this._target;
  },

  /**
   * @details Returns the name of the current projection of the map.
   *
   * @return {String} Proj-code of the projection.
   */
  projection: function() {
    return this._currentProj;
  },

  /**
   * @details Sets the value of the current layer of the map.
   *          Set by the LayerCollection in the onAdd method.
   */
  setCurrentLayer: function(layer) {
    this._currentLayer = layer;
  },

  /**
   * @details Returns the current layer of the map. Used by the LayerCollection
   *          so that it can remove the layer of the map without having to
   *          remove all layers, including drawn shapes.
   *
   * @return {L.Layer} Current layer of the map.
   */
  currentLayer: function() {
    return this._currentLayer;
  }
});
+42 −39
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import { func } from "prop-types";
 */
export default L.Control.AstroDraw = L.Control.Draw.extend({
  options: {
		position: 'topleft',
    position: "topleft",
    draw: {},
    edit: false
  },
@@ -40,9 +40,10 @@ export default L.Control.AstroDraw = L.Control.Draw.extend({
   * @return {Object} The div-container the control is in.
   */
  onAdd: function(map) {
    let container = L.DomUtil.create('div', 'leaflet-draw'),
    this._map = map;
    let container = L.DomUtil.create("div", "leaflet-draw"),
      addedTopClass = false,
			topClassName = 'leaflet-draw-toolbar-top',
      topClassName = "leaflet-draw-toolbar-top",
      toolbarContainer;

    for (let toolbarId in this._toolbars) {
@@ -64,17 +65,18 @@ export default L.Control.AstroDraw = L.Control.Draw.extend({

    this.wktTextBox = L.DomUtil.get("wktTextBox");
    this.wkt = new Wkt.Wkt();
    this.myLayer = L.geoJSON().addTo(map);
    this.myLayer = L.Proj.geoJson().addTo(map);

    this.wktButton = L.DomUtil.get("wktButton");
    L.DomEvent.on(this.wktButton, "click", this.mapWKTString, this);

    map.on("draw:created", this.shapesToWKT, this);

    // map.on("projChange", this.reprojectFeature, this);

    return container;
  },


  /**
   * Is called when a user draws a shape using the on map drawing features.
   * Converts the shaped drawn into a Well-Known text string and inserts it into the
@@ -83,11 +85,11 @@ export default L.Control.AstroDraw = L.Control.Draw.extend({
   */
  shapesToWKT: function(e) {
    this.myLayer.clearLayers();
    this.options.edit['featureGroup'].clearLayers();
    this.options.edit["featureGroup"].clearLayers();

    this.options.edit['featureGroup'].addLayer(e.layer);
    this.options.edit["featureGroup"].addLayer(e.layer);
    let geoJson = e.layer.toGeoJSON();
    geoJson = geoJson['geometry'];
    geoJson = geoJson["geometry"];

    this.wkt.read(JSON.stringify(geoJson));
    this.wktTextBox.value = this.wkt.write();
@@ -101,7 +103,7 @@ export default L.Control.AstroDraw = L.Control.Draw.extend({
   */
  mapWKTString: function(e) {
    this.myLayer.clearLayers();
    this.options.edit['featureGroup'].clearLayers();
    this.options.edit["featureGroup"].clearLayers();

    let wktValue = this.wktTextBox.value;

@@ -109,8 +111,7 @@ export default L.Control.AstroDraw = L.Control.Draw.extend({

    try {
      this.wkt.read(wktValue);
    }
    catch (err){
    } catch (err) {
      alert("Invalid Well Known Text String");
      return;
    }
@@ -118,12 +119,14 @@ export default L.Control.AstroDraw = L.Control.Draw.extend({
    let geoJson = this.wkt.toJson();

    let geojsonFeature = {
      "type": "Feature",
      "geometry": geoJson
      type: "Feature",
      geometry: geoJson
    };

    this.myLayer.addData(geojsonFeature);
  }

});
  // reprojectFeature: function(e) {

  // }
});
+21 −22
Original line number Diff line number Diff line
@@ -121,6 +121,8 @@ export default L.LayerCollection = L.Class.extend({
      this._overlays[name] = overlay;
    }

    // Only add feature names to cylindrical
    if (this._projName == "cylindrical") {
      this._wfsLayer = new L.GeoJSON(null, {
        onEachFeature: function(feature, layer) {
          if (feature.properties && feature.properties.name) {
@@ -132,6 +134,7 @@ export default L.LayerCollection = L.Class.extend({
        }
      });
      this._overlays["Show Feature Names"] = this._wfsLayer;
    }
  },

  /**
@@ -141,10 +144,9 @@ export default L.LayerCollection = L.Class.extend({
   * @param {AstroMap} map - Map to add layers to.
   */
  addTo: function(map) {
    // Remove old layers
    map.eachLayer(function(layer) {
      map.removeLayer(layer);
    });
    if (map.currentLayer() != null) {
      map.removeLayer(map.currentLayer());
    }

    if (L.LayerCollection.layerControl) {
      L.LayerCollection.layerControl.remove();
@@ -153,6 +155,7 @@ export default L.LayerCollection = L.Class.extend({
    if (!this.isEmpty()) {
      let defaultLayer = Object.keys(this._baseLayers)[this._defaultLayerIndex];
      this._baseLayers[defaultLayer].addTo(map);
      map.setCurrentLayer(this._baseLayers[defaultLayer]);

      L.LayerCollection.layerControl = L.control.layers(
        this._baseLayers,
@@ -161,9 +164,9 @@ export default L.LayerCollection = L.Class.extend({
      L.LayerCollection.layerControl.addTo(map);
    }

    if (this._projName == "cylindrical") {
      this.loadWFS(map);
    // Commented out for now because WFS queries are super slow.
    // map.on("moveend", this.loadWFS);
    }
  },

  /**
@@ -195,11 +198,7 @@ export default L.LayerCollection = L.Class.extend({
      srsName: "EPSG:4326"
    };

    let customParams = {
      bbox: map.getBounds().toBBoxString()
    };

    let parameters = L.Util.extend(defaultParameters, customParams);
    let parameters = L.Util.extend(defaultParameters);
    console.log(geoJsonUrl + L.Util.getParamString(parameters));

    let thisContext = this;