Hello, i've got a problem: i'am trying to add new layer and erros occured.
TypeError: view.graphics is undefined
<!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>
Without this layer everything ok.
I only want to add this layer: mapslt (MapServer) and some polygons, but isn't work. What's wrong? Could anybody help me?
Hello, I'm very glad for help. I started learn apI thIs week and I don't know a lot. But I'm tryIng me best to make somethIng and I thought You can help me.
So, I want to have thIs basemap: http://www.maps.lt/arcgIs/rest/servIces/mapslt/MapServer and some polygons on It. That's all. I changed what you saId, It works. But polygons doesn't apper. I don't know where the problem Is, It's the second day I'am lookIng for, but I don't found yet.
You should really ask this as a separate question.
The problem you're running into is that you are trying to add a tile layer that has a different projection (3346) than the map's basemap. You can add a dynamic layer or feature layer that has a different projection, but a tile layer is treated differently. A tile layer will only be visible for when it not only has the same projection as the basemap, but also has the same levels of detail (LODs).