-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation-scale.html
198 lines (181 loc) · 4.64 KB
/
location-scale.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!-- https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=visualization-sm-location-scale -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.15/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.15/"></script>
<style>
html,
body,
#viewDiv {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#infoDiv {
background: white;
padding: 10px;
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/renderers/SimpleRenderer",
"esri/renderers/smartMapping/creators/location"
], function(
Map,
MapView,
FeatureLayer,
SimpleRenderer,
locationRendererCreator
) {
const renderer = new SimpleRenderer({
symbol: {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
color: "dodgerblue",
outline: {
color: [255, 255, 255, 0.7],
width: 0.5
},
size: 7.5
},
sizeOptimizationEnabled: true
});
const layer = new FeatureLayer({
portalItem: {
id: "cb1886ff0a9d4156ba4d2fadd7e8a139"
},
renderer: renderer
})
layer.on("load", function(e){
console.log("layer loaded with: " + layer.graphics.length + " features");
console.log("Load event object properties: ",e);
});
layer.on("update-end", function(e) {
console.log("layer update-end with: " + layer.graphics.length + " features");
console.log("Update-end object properties: ", e);
});
const baseLayer = new FeatureLayer({
portalItem: {
id: "2b93b06dc0dc4e809d3c8db5cb96ba69"
},
legendEnabled: false,
popupEnabled: false,
renderer: {
type: "simple",
symbol: {
type: "simple-fill",
color: [200, 200, 200, 0.75],
outline: {
color: "white",
width: 0.5
}
}
},
spatialReference: {
wkid: 54035
}
});
const map = new Map({
layers: [baseLayer, layer]
});
const view = new MapView({
container: "viewDiv",
map: map,
center: {
x: 0,
y: 0,
spatialReference: baseLayer.spatialReference
},
scale: 100000000,
constraints: {
rotationEnabled: false
},
graphics: [
// outline of map
{
symbol: {
type: "simple-fill",
color: null,
outline: {
width: 1,
color: [200, 200, 200, 0.75]
}
},
geometry: {
type: "extent",
xmin: -180,
xmax: 180,
ymin: -90,
ymax: 90,
spatialReference: { wkid: 4326 }
}
}
]
});
// wait for layer to load
layer
.when(function() {
// This function will execute once the promise is resolved
let sizeOptimizationEnabled = true;
// generates a new renderer with a scale-dependent
// size visual variable to vary icon size by scale
locationRendererCreator
.createRenderer({
layer: layer,
view: view,
// sizeOptimizationEnabled: true
})
.then(function(rendererResponse) {
// the renderer contains a size variable with stops
// mapping icon sizes to scale values
const renderer = rendererResponse.renderer;
renderer.symbol.color = "dodgerblue";
renderer.visualVariables = [
{
type: "color",
field: "latitude",
stops: [
{
value: -90,
color: "#FFFCD4"
},
{
value: 90,
color: "#0D2644"
}
]
},
{
type: "size",
valueExpression: "$view.scale / 1000000",
// field: "longitude", // enabling this field disables the valueExpression
valueUnit: "miles"
},
]
layer.renderer = renderer;
window.layer = layer;
})
.catch(function(error) {
console.error(error);
});
})
.catch(e => { console.log(e)});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>