要素微件
此示例使用 要素微件 基于 PopupTemplate 显示信息。 您可以使用此小部件显示通常在 弹出窗口 中找到的信息,而无需使用 弹出窗口 本身。 您还可以在自定义微件或应用程序的其他部分中使用此信息。
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
// Provide graphic to a new instance of a Feature widget
const feature = new Feature({
graphic: graphic,
map: view.map,
spatialReference: view.spatialReference
});
view.ui.add(feature, "bottom-left");
view.whenLayerView(fLayer).then((layerView) => {
let highlight;
let objectId;
const debouncedUpdate = promiseUtils.debounce((event) => {
// Perform a hitTest on the View
view.hitTest(event)
.then((event) => {
// Make sure graphic has a popupTemplate
const results = event.results.filter((result) => {
return result.graphic.layer.popupTemplate;
});
const result = results[0];
const newObjectId = result && result.graphic.attributes[fLayer.objectIdField];
if (!newObjectId) {
highlight && highlight.remove();
objectId = feature.graphic = null;
} else if (objectId !== newObjectId) {
highlight && highlight.remove();
objectId = newObjectId;
feature.graphic = result.graphic;
highlight = layerView.highlight(result.graphic);
}
})
});
// Listen for the pointer-move event on the View
// and make sure that function is not invoked more
// than one at a time
view.on("pointer-move", (event) => {
debouncedUpdate(event).catch((err) => {
if (!promiseUtils.isAbortError(err)) {
throw err;
}
});
});
});