Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link rel="stylesheet" href="https://js.arcgis.com/4.28/esri/themes/light/main.css">

<script src="https://js.arcgis.com/4.28/"></script>

<script type="module" src="https://js.arcgis.com/calcite-components/1.11.0/calcite.esm.js"></script>

<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/1.11.0/calcite.css" />

<calcite-shell>

  <div id="SpeciesMap" />
  <calcite-shell-panel slot="panel-start" position="start" width-scale="l">
    <div id="ShowLayersDiv" />
  </calcite-shell-panel>

</calcite-shell>
              
            
!

CSS

              
                #SpeciesMap {
  flex: 1;
}

              
            
!

JS

              
                require([
  "esri/Map",
  "esri/views/MapView",
  "esri/Graphic",
  "esri/layers/FeatureLayer",
  "esri/widgets/LayerList",
  "esri/widgets/ScaleBar",
  "esri/widgets/Locate",
  "esri/widgets/BasemapToggle"
], function (
  Map,
  MapView,
  Graphic,
  FeatureLayer,
  LayerList,
  ScaleBar,
  Locate,
  BasemapToggle
) {
  // var sightings = <?php echo json_encode($coords) ?>;
  // var	speciesName = <?php echo json_encode($thisTaxon) ?>;
  // var	commonName = <?php echo json_encode($evernacular) ?>;
  const sightings = [
    {
      MapAlt: "757",
      MapDate: "2021-05-08",
      MapFullName: "xxxxxx",
      MapID: "249",
      MapLat: "39.748225",
      MapLocation: "Mt. Pandokrator",
      MapLong: "19.855923",
      MapQty: "1",
      Stage: "P",
      stageQty: null
    },
    {
      MapAlt: "757",
      MapDate: "2021-05-08",
      MapFullName: "xxxxxx",
      MapID: "250",
      MapLat: "39.8",
      MapLocation: "Mt. Pandokrator",
      MapLong: "19.9",
      MapQty: "1",
      Stage: "A",
      stageQty: null
    },
    {
      MapAlt: "757",
      MapDate: "2021-05-08",
      MapFullName: "xxxxxx",
      MapID: "250",
      MapLat: "39.9",
      MapLocation: "Mt. Pandokrator",
      MapLong: "19.8",
      MapQty: "1",
      Stage: "L",
      stageQty: null
    }
  ];
  const speciesName = "species name";
  const commonName = "common name";
  const stageLetters = "AEWLP";
  const stageText = ["Adult", "Egg", "Larval Web", "Larva", "Pupa"];
  const stagePlurals = ["Adults", "Eggs", "Larval Webs", "Larvae", "Pupae"];
  const stageColours = ["Green", "Yellow", "Orange", "Blue", "Red"];
  const map = new Map({
    basemap: "topo-vector"
  });
  var view = new MapView({
    container: "SpeciesMap",
    map: map,
    center: [19.870373, 39.589907],
    zoom: 10
  });
  var scaleBar = new ScaleBar({
    view: view,
    style: "ruler",
    unit: "metric"
  });
  view.ui.add(scaleBar, {
    position: "bottom-right"
  });
  var basemapToggle = new BasemapToggle({
    view: view,
    nextBasemap: "satellite"
  });
  view.ui.add(basemapToggle, "bottom-left");
  let fields = [
    {
      name: "MapID",
      type: "oid"
    },
    {
      name: "MapDate",
      type: "string"
    },
    {
      name: "CommName",
      type: "string"
    },
    {
      name: "SpName",
      type: "string"
    },
    {
      name: "MapFullName",
      type: "string"
    },
    {
      name: "MapLocation",
      type: "string"
    },
    {
      name: "MapAlt",
      type: "integer"
    },
    {
      name: "MapQty",
      type: "integer"
    },
    {
      name: "Stage",
      type: "string"
    }
  ];
  // client side feature layer using the adult graphics as the source
  const adultFeatureLayer = new FeatureLayer({
    geometryType: "point",
    spatialReference: { wkid: 4326 },
    source: [],
    objectIdField: "MapID",
    fields: fields,
    title: "Adults",
    renderer: {
      type: "simple",
      symbol: {
        type: "simple-marker",
        size: 9,
        color: "green"
      }
    }
  });
  const eggFeatureLayer = new FeatureLayer({
    geometryType: "point",
    spatialReference: { wkid: 4326 },
    source: [],
    objectIdField: "MapID",
    fields: fields,
    title: "Eggs",
    renderer: {
      type: "simple",
      symbol: {
        type: "simple-marker",
        size: 9,
        color: "yellow"
      }
    }
  });
  const webFeatureLayer = new FeatureLayer({
    geometryType: "point",
    spatialReference: { wkid: 4326 },
    source: [],
    objectIdField: "MapID",
    fields: fields,
    title: "Larval webs",
    renderer: {
      type: "simple",
      symbol: {
        type: "simple-marker",
        size: 9,
        color: "orange"
      }
    }
  });
  const larvaFeatureLayer = new FeatureLayer({
    geometryType: "point",
    spatialReference: { wkid: 4326 },
    source: [],
    objectIdField: "MapID",
    fields: fields,
    renderer: {
      type: "simple",
      symbol: {
        type: "simple-marker",
        size: 9,
        color: "blue"
      }
    },
    title: "Larvae"
  });
  const pupaFeatureLayer = new FeatureLayer({
    geometryType: "point",
    spatialReference: { wkid: 4326 },
    source: [],
    objectIdField: "MapID",
    fields: fields,
    renderer: {
      type: "simple",
      symbol: {
        type: "simple-marker",
        size: 9,
        color: "red"
      }
    },
    title: "Pupae"
  });
  map.addMany([
    pupaFeatureLayer,
    larvaFeatureLayer,
    webFeatureLayer,
    eggFeatureLayer,
    adultFeatureLayer
  ]);
  var someAdults = false;
  var someEggs = false;
  var someWebs = false;
  var someLarvae = false;
  var somePupae = false;
  sightings.forEach((coords) => {
    // var MapQty = parseInt(coords.MapQty);
    // var MapAlt = parseInt(coords.MapAlt);
    // // var stageLetter = "A";
    // if (coords.MapQty > 0) {
    //   var MapQty = parseInt(coords.MapQty);
    //   var stageLetter = coords.Stage;
    // }
    // let stagePos = stageLetters.indexOf(stageLetter);
    // if (MapQty > 1) {
    //   var stageName = stagePlurals[stagePos];
    // } else {
    //   var stageName = stageText[stagePos];
    // }
    // let stageColour = stageColours[stagePos];
    const graphic = new Graphic({
      geometry: {
        type: "point",
        longitude: coords.MapLong,
        latitude: coords.MapLat
      },
      attributes: {
        MapID: coords.MapID,
        MapDate: coords.MapDate,
        // CommName: commonName,
        // SpName: speciesName,
        MapFullName: coords.MapFullName,
        MapLoc: coords.MapLocation,
        MapAlt: coords.MapAlt,
        MapQuantity: coords.MapQty,
        MapStageName: coords.Stage
      }
    });
    const popupTemplate = {
      title: "{CommName} (<i>{SpName}</i>)",
      content:
        "Record ID: <b>{MapID}</b><br>Recorded on <b>{MapDate}</b><br>Recorded by <b>{MapFullName}</b><br>Location: <b>{MapLoc}</b><br>Altitude: <b>{MapAlt} metres</b><br>Quantity <b>{MapQuantity}</b> {MapStageName}"
    };
    adultFeatureLayer.popupTemplate = popupTemplate;
    eggFeatureLayer.popupTemplate = popupTemplate;
    webFeatureLayer.popupTemplate = popupTemplate;
    larvaFeatureLayer.popupTemplate = popupTemplate;
    pupaFeatureLayer.popupTemplate = popupTemplate;
    switch (coords.Stage) {
      case "E":
        eggFeatureLayer.source.push(graphic);
        var someEggs = true;
        break;
      case "W":
        webFeatureLayer.source.push(graphic);
        var someWebs = true;
        break;
      case "L":
        larvaFeatureLayer.source.push(graphic);
        var someLarvae = true;
        break;
      case "P":
        pupaFeatureLayer.source.push(graphic);
        var somePupae = true;
        break;
      default:
        adultFeatureLayer.source.push(graphic);
        var someAdults = true;
        break;
    }
  });
  var layerCount = 0;
  const ShowLayers = new LayerList({
    label: "Life cycle stages",
    view: view,
    listItemCreatedFunction: async (event) => {
      const item = event.item;
      item.panel = {
        content: "legend",
        open: true
      };
      if (item) {
        const count = await item.layer.queryFeatureCount();
        if (count === 0) {
          item.layer.listMode = "hide";
        }
      }
      // const item = event.item;
      // layerCount++;
      // console.log(layerCount, item.title);
      // if (
      //   (item.title === "Larval webs" && someWebs === false) ||
      //   (item.title === "Pupae" && somePupae === false)
      // ) {
      //   item.visible = false;
      // }
      // if (item.visible === true) {
      //   item.panel = {
      //     content: "legend",
      //     open: true
      //   };
      // }
    },
    container: ShowLayersDiv
  });
  console.log(map.layers);
});

              
            
!
999px

Console