AnsweredAssumed Answered

eLayer

Question asked by jwmarijampole on Aug 16, 2017
Latest reply on Aug 16, 2017 by rscheitlin

Hello, i've got a problem:

 when I'am trying add layer to my map, it isn't works:

TypeError: view.graphics is undefined

Without this layer everything ok.

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Maps</title>
<style>
  html, body, #viewDiv {
    padding: 0;
    margin: 0;
    height: 100%;
    width: 100%;
  }
</style>
  <link rel="stylesheet" href="https://js.arcgis.com/4.3/esri/css/main.css">
<script src="https://js.arcgis.com/4.3/"></script>
<script>
require([
     /* ADDED*/
  "esri/layers/TileLayer",
  /*---*/
  "esri/Map",
  "esri/views/MapView",
  "esri/Graphic",
  "esri/geometry/Point",
  "esri/symbols/SimpleMarkerSymbol",
  "esri/geometry/Polyline",
  "esri/symbols/SimpleLineSymbol",
  "esri/geometry/Polygon",
  "esri/symbols/SimpleFillSymbol",
  "dojo/domReady!"
], function(Map, MapView,
      Graphic, Point, SimpleMarkerSymbol,
      Polyline, SimpleLineSymbol,
      Polygon, SimpleFillSymbol,
       TileLayer
) {
/* ADDED */
var layer = new TileLayer({
url: "http://www.maps.lt/arcgis/rest/services/mapslt/MapServer"
         });
/*---*/
  var map = new Map({
    basemap: "streets",
     /* ADDED */
     layers: [layer]
     /* ---*/
  });

  
  var view = new MapView({
    container: "viewDiv", 
    map: map,
    center: [23.27928,55.13558],
    zoom: 10
  });
 
 
 
  // Create a point
  var point = new Point({
    longitude: 23.29507,
    latitude: 55.13501
  });

  // Create a symbol for drawing the point
  var markerSymbol = new SimpleMarkerSymbol({
    color: [226, 119, 40],
    outline: {
      color: [255, 255, 255],
      width: 1
    }
  });
 
  // Create attributes
  var attributes = {
    Name: "I am a point",  // The name of the pipeline
    Park: "Griffith Park",  // The owner of the pipeline
    City: "Los Angeles"  // The length of the pipeline
  };
 
  // Create popup template
  var popupTemplate = {
    title: "{Name}",
    content: "I live in <b>{Park}</b> in the city of <b>{City}</b>."
  };

  // Create a graphic and add the geometry and symbol to it
  var pointGraphic = new Graphic({
    geometry: point,
    symbol: markerSymbol,
    attributes: attributes,
    popupTemplate: popupTemplate
  });
   
  view.graphics.add(pointGraphic);
 
  // Create a line geometry
  var polyline = new Polyline({
    paths: [
      [23.29026, 55.1816],
      [23.26451, 55.09664]
    ]
  });

  // Create a symbol for drawing the line
  var lineSymbol = new SimpleLineSymbol({
    color: [226, 119, 40],
    width: 2
  });

  // Create a line graphic
  var polylineGraphic = new Graphic({
    geometry: polyline,
    symbol: lineSymbol
  });

  // Add the graphic to the view
  view.graphics.add(polylineGraphic);

  // Create a polygon geometry
  var polygon = new Polygon({
    rings: [
      [23.27653, 55.15121],
      [23.2446, 55.15462],
      [23.22915, 55.14439],
      [23.23327, 55.12279],
      [23.25318, 55.10972],
      [23.26486, 55.11625],
      [23.27653, 55.15121]
    ]
  });

  // Create a symbol for rendering the graphic
  var fillSymbol = new SimpleFillSymbol({
    color: [227, 139, 79, 0.8],
    outline: {
      color: [255, 255, 255],
      width: 1
    }
  });

  // Add the geometry and symbol to a new graphic
  var polygonGraphic = new Graphic({
    geometry: polygon,
    symbol: fillSymbol
  });

  // Add the graphic to the view
  view.graphics.add(polygonGraphic);

});</script>
</head>
<body>
  <div id="viewDiv"></div>
</body>
</html>

I only want to add this layer: mapslt (MapServer)  and some polygons.

What's wrong? Can anybody help me?

Outcomes