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
<!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: Relationship</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/views/MapView",
"geoscene/WebMap",
"geoscene/layers/FeatureLayer",
"geoscene/widgets/Legend",
"geoscene/widgets/Expand",
"geoscene/smartMapping/renderers/relationship"
], function (
geosceneConfig,
MapView,
WebMap,
FeatureLayer,
Legend,
Expand,
relationshipRendererCreator
) {
geosceneConfig.apiKey = "YOUR_API_KEY";
const layer = new FeatureLayer({
portalItem: {
id: "1cbb0faa0f1f424bbe213bfae9319309"
},
blendMode: "multiply",
definitionExpression: "STATE = 'AZ'"
});
const map = new WebMap({
portalItem: {
id: "9cf503b654144873a8e33f996f91ba1d"
},
layers: [ layer ]
});
const referenceScale = 9244650*2;
const view = new MapView({
container: "viewDiv",
map: map,
scale: 1155580,
center: [ -111.868, 33.411 ],
// Set dock options on the view's popup
popup: {
dockEnabled: true,
dockOptions: {
breakpoint: false
}
},
constraints: {
snapToZoom:false
}
});
view.ui.add(new Expand({
content: new Legend({
view
}),
view
}), "top-right");
layer.when()
.then(createRelationshipRenderer)
.then(applyRenderer);
function createRelationshipRenderer() {
const params = {
layer: layer,
view: view,
field1: {
field: "AVGHHSZ_CY",
label: "Household size"
},
field2: {
field: "AVGVAL_CY",
label: "Home value"
},
focus: null,
numClasses: 3,
outlineOptimizationEnabled: true
};
return relationshipRendererCreator.createRenderer(params);
}
function applyRenderer(response) {
const renderer = response.renderer;
renderer.uniqueValueInfos.forEach(function (info) {
switch (info.value) {
case "HH":
info.label = "Large households; Expensive homes";
break;
case "HL":
info.label = "Large households; Cheaper homes";
break;
case "LH":
info.label = "Small households; Expensive homes"
break;
case "LL":
info.label = "Small households; Cheaper homes";
break;
}
});
layer.renderer = renderer;
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>