Chris
Chris

Reputation: 677

Basic ESRI tilelayer not displaying using ArcGIS JavaScript API v4.12

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>

Upvotes: 1

Views: 273

Answers (1)

Muhammet Can TONBUL
Muhammet Can TONBUL

Reputation: 3538

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>

Upvotes: 1

Related Questions