Commit 21063169 authored by Kaitlyn's avatar Kaitlyn
Browse files

Sorted features by diameter so that smaller features are on top of larger features.

parent 66882370
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -66,10 +66,10 @@
    "webpack-merge": "^4.2.2"
  },
  "dependencies": {
    "jquery": "^3.4.1",
    "@material-ui/core": "^4.9.0",
    "@material-ui/icons": "^4.5.1",
    "@material-ui/lab": "^4.0.0-alpha.41",
    "jquery": "^3.4.1",
    "leaflet": "^1.6.0",
    "proj4": "^2.6.0",
    "proj4leaflet": "^1.0.2",
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ export default class App extends Component {
  }

  componentDidMount() {
    let map = new AstroMap("map-container", "MIMAS", {});
    let map = new AstroMap("map-container", "mars", {});
    let projectionControl = new Projection();
    projectionControl.addTo(map);

+33 −3
Original line number Diff line number Diff line
@@ -67,8 +67,10 @@ export default L.LayerCollection = L.Class.extend({
                this.defaultLayerIndex = layers["base"].length - 1;
              }
            } else {
              if (currentLayer["displayname"] != "Show Feature Names") {
                layers["overlays"].push(currentLayer);
              }
            }
          } else {
            layers["wfs"].push(currentLayer);
          }
@@ -124,9 +126,12 @@ export default L.LayerCollection = L.Class.extend({
        if (feature.properties && feature.properties.name) {
          layer.bindPopup(feature.properties.name);
        }
      },
      pointToLayer: function(feature, latlng) {
        return new L.CircleMarker(latlng, { radius: 3, fillOpacity: 1 });
      }
    });
    this.overlays["Show Feature Names WFS"] = this.wfsLayer;
    this.overlays["Show Feature Names"] = this.wfsLayer;
  },

  /**
@@ -203,9 +208,34 @@ export default L.LayerCollection = L.Class.extend({
      dataType: "json",
      timeout: 30000,
      success: function(data) {
        // this.featureLayer.clearLayers();
        let sortedFeatures = thisContext.sortFeatures(data["features"]);
        data["features"] = sortedFeatures;
        thisContext.wfsLayer.clearLayers();
        thisContext.wfsLayer.addData(data);
      }
    });
  },

  /**
   * @details Sorts the features by diameter so that smaller features are on
   *          top of the larger features on the map. Features with smaller
   *          diameters will be put at the end of the list.
   *
   * @param  {List} data - List of features.
   *
   * @return {Integer} Returns -1 if f1 < f2, 1 if f2 > f1, and 0 if f1==f2.
   */
  sortFeatures: function(data) {
    return data.sort(function(a, b) {
      var f1 = a["properties"]["diameter"];
      var f2 = b["properties"]["diameter"];
      if (f1 < f2) {
        return 1;
      } else if (f1 > f2) {
        return -1;
      } else {
        return 0;
      }
    });
  }
});