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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title> GeoScene Developer Guide: Street condition complaints</title>
<link rel="stylesheet" href="https://js.geoscene.cn/4.23/geoscene/themes/light/main.css" />
<script src="https://js.geoscene.cn/4.23/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script>
require([
"geoscene/config",
"geoscene/WebMap",
"geoscene/views/MapView",
"geoscene/layers/FeatureLayer",
"geoscene/widgets/Legend",
"geoscene/widgets/Expand",
"geoscene/smartMapping/labels/clusters",
"geoscene/smartMapping/popup/clusters",
"geoscene/core/promiseUtils"
], function (geosceneConfig,WebMap, MapView, FeatureLayer, Legend, Expand,
clusterLabelCreator,
clusterPopupCreator,
promiseUtils
) {
geosceneConfig.apiKey = "YOUR_API_KEY";
const colors = [ "#2799ff", "#423a3a", "#ff3333" ];
const renderer = {
type: "simple",
label: "Observed hurricane location",
symbol: {
type: "simple-marker",
size: 6,
outline: {
width: 0.5,
color: [255,255,255,0.5]
}
},
visualVariables: [{
type: "color",
valueExpression: "DateDiff($feature['closed_time'], $feature['due_time'], 'days')",
valueExpressionTitle: "Days it took to close incident",
stops: [
{ value: -21, color: colors[0], label: "21 weeks early" },
{ value: 0, color: colors[1], label: "On time" },
{ value: 21, color: colors[2], label: "21 weeks late" }
]
}]
};
const layer = new FeatureLayer({
portalItem: {
id: "f624a9f4afa947fe98acd0ed38fbe436"
},
title: "Street condition complaints",
renderer: renderer,
definitionExpression: "Complaint_Type = 'Street Condition'"
});
const map = new WebMap({
portalItem: {
id: "75a3ce8990674a5ebd5b9ab66bdab893"
},
layers: [ layer ]
});
const view = new MapView({
container: "viewDiv",
map: map,
scale: 144447,
center: [ -73.863, 40.7 ],
constraints: {
snapToZoom:false
}
});
view.ui.add(new Expand({
content: new Legend({
view: view
}),
view: view,
expanded: true
}), "top-right");
view.when()
.then(generateClusterConfig)
.then(function(featureReduction){
layer.featureReduction = featureReduction;
});
function generateClusterConfig() {
// generates default popupTemplate
const popupPromise = clusterPopupCreator
.getTemplates({
layer: layer
})
.then(function (popupTemplateResponse) {
return popupTemplateResponse.primaryTemplate.value;
});
// generates default labelingInfo
const labelPromise = clusterLabelCreator
.getLabelSchemes({
layer: layer,
view: view
})
.then(function (labelSchemes) {
return labelSchemes.primaryScheme;
});
return promiseUtils
.eachAlways([ popupPromise, labelPromise ])
.then(function (result) {
const popupTemplate = result[0].value;
const primaryLabelScheme = result[1].value;
const labelingInfo = primaryLabelScheme.labelingInfo;
// Ensures the clusters are large enough to fit labels
const clusterMinSize = primaryLabelScheme.clusterMinSize;
return {
type: "cluster",
popupTemplate: popupTemplate,
labelingInfo: labelingInfo,
clusterMinSize: clusterMinSize,
clusterRadius: 50
};
})
.catch(function (error) {
console.error(error);
});
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>