-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
95 lines (82 loc) · 3.26 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Layer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="https://js.arcgis.com/3.21/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.21/esri/css/esri.css">
<style>
html, body, #mapDiv, .map.container {
padding:0;
margin:0;
height:100%;
}
</style>
<script src="https://js.arcgis.com/3.21/"></script>
<script>
var map;
require([
"esri/map", "esri/layers/FeatureLayer", "esri/InfoTemplate",
"esri/tasks/GeometryService",
"esri/layers/TableDataSource", "esri/layers/LayerDataSource",
"esri/symbols/SimpleFillSymbol", "esri/renderers/SimpleRenderer",
"esri/config",
"esri/Color", "dojo/domReady!"
], function(
Map, FeatureLayer, InfoTemplate,
GeometryService,
TableDataSource, LayerDataSource,
SimpleFillSymbol, SimpleRenderer,
esriConfig,
Color
) {
esriConfig.defaults.geometryService = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
map = new Map("mapDiv", {
basemap: "satellite",
center: [0, 0],
zoom: 2
});
map.on("load", initOperationalLayer);
function initOperationalLayer() {
var content = "<b>Name</b>: ${name}" + "<br /><b>Area</b>: ${ss6.gdb.Lakes.area:NumberFormat(places:0)}";
var infoTemplate = new InfoTemplate("Dynamic Layer", content);
//define the layer's data source from a table
var dataSource = new TableDataSource();
dataSource.workspaceId = "MyDatabaseWorkspaceIDSSR2";
dataSource.dataSourceName = "ss6.gdb.Lakes";
var layerSource = new LayerDataSource();
layerSource.dataSource = dataSource;
//create a new feature layer based on the table data source
var featureLayer = new FeatureLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/dynamicLayer", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
infoTemplate: infoTemplate,
source: layerSource
});
featureLayer.on("load", function(evt){
//project the extent if the map's spatial reference is different that the layer's extent.
var gs = esriConfig.defaults.geometryService;
var extent = evt.layer.fullExtent;
if ( extent.spatialReference.wkid === map.spatialReference.wkid ) {
map.setExtent(extent);
} else {
gs.project([extent], map.spatialReference).then(function (results) {
map.setExtent(results[0]);
});
}
});
var renderer = new SimpleRenderer(
new SimpleFillSymbol("solid", null, new Color([255, 0, 255, 0.75]) // fuschia lakes!
));
featureLayer.setRenderer(renderer);
map.addLayer(featureLayer);
map.infoWindow.resize(150, 105);
}
});
</script>
</head>
<body class="claro">
<div id="mapDiv"></div>
</body>
</html>