1

I am trying to load an ESRI Tile Layer within an HTML page but for some reason the map isn't displaying.

It should be a straightforward process and I cannot identify what the issue is (I receive no error messages within the console window).

Any suggestions?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Load a basic WebMap - 4.12</title>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

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

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

    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/TileLayer"
      ], function(TileLayer, Map, MapView) {
        var layer = new TileLayer({
          url:
            "https://services.arcgisonline.com/arcgis/rest/services/World_Terrain_Base/MapServer"
        });

        var map = new Map({
          layers: [layer]
        });

        var view = new MapView({
          container: "viewDiv",
          map: map
        });
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>

1 Answer 1

1

Because your imports order is wrong. You should change this line

function(TileLayer, Map, MapView)

to

function(Map, MapView,TileLayer) {

https://jsfiddle.net/h31m5ub7/

Full code:; `

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Load a basic WebMap - 4.12</title>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.12/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.12/"></script>
    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/TileLayer"
      ], function(Map, MapView,TileLayer) {
        var layer = new TileLayer({
          url:            "https://services.arcgisonline.com/arcgis/rest/services/World_Terrain_Base/MapServer"
        });
        var map = new Map({
          layers: [layer]
        });

        var view = new MapView({
          container: "viewDiv",
          map: map
        });
      });
    </script>
  </head>
  <body>
    <div id="viewDiv"></div>
  </body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.