|
| 1 | +<!--******************************************************************** |
| 2 | +* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved. |
| 3 | +*********************************************************************--> |
| 4 | +<!--******************************************************************** |
| 5 | +* 该示例需要引入 |
| 6 | +* G6 (https://github.com/antvis/G6) |
| 7 | +*********************************************************************--> |
| 8 | +<!DOCTYPE html> |
| 9 | +<html> |
| 10 | + <head> |
| 11 | + <meta charset="utf-8" /> |
| 12 | + <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> |
| 13 | + <title data-i18n="resources.title_knowledgeGraphMap"></title> |
| 14 | + <script type="text/javascript" include="jquery" src="../js/include-web.js"></script> |
| 15 | + <style> |
| 16 | + body { |
| 17 | + margin: 0; |
| 18 | + padding: 0; |
| 19 | + width: 100%; |
| 20 | + height: 100vh; |
| 21 | + overflow: hidden; |
| 22 | + } |
| 23 | + |
| 24 | + #knowledgeGraph { |
| 25 | + width: 100%; |
| 26 | + height: 100%; |
| 27 | + } |
| 28 | + .short-path-panel { |
| 29 | + position: fixed; |
| 30 | + top: 60px; |
| 31 | + right: 30px; |
| 32 | + display: flex; |
| 33 | + flex-direction: column; |
| 34 | + align-items: center; |
| 35 | + justify-content: center; |
| 36 | + width: 350px; |
| 37 | + padding: 15px; |
| 38 | + background-color: antiquewhite; |
| 39 | + border: 1px solid gray; |
| 40 | + } |
| 41 | + .node-item { |
| 42 | + display: inline-flex; |
| 43 | + width: 100%; |
| 44 | + margin-top: 15px; |
| 45 | + } |
| 46 | + .node-item input { |
| 47 | + width: 150px; |
| 48 | + } |
| 49 | + .node-item button { |
| 50 | + margin: 0 5px; |
| 51 | + } |
| 52 | + .buttons { |
| 53 | + display: inline-flex; |
| 54 | + justify-content: center; |
| 55 | + margin-top: 20px; |
| 56 | + width: 100%; |
| 57 | + } |
| 58 | + #analysis { |
| 59 | + width: 80px; |
| 60 | + margin-right: 10px; |
| 61 | + } |
| 62 | + #reset { |
| 63 | + width: 80px; |
| 64 | + } |
| 65 | + </style> |
| 66 | + </head> |
| 67 | + |
| 68 | + <body> |
| 69 | + <div id="knowledgeGraph"></div> |
| 70 | + <div class="short-path-panel"> |
| 71 | + <div class="title" data-i18n="resources.text_graphmap_shortest_analysis"></div> |
| 72 | + <div class="node-item start-node"> |
| 73 | + <span data-i18n="resources.text_startNode"></span> <input class="start" disabled /><button |
| 74 | + id="select-start-node" |
| 75 | + data-i18n="resources.text_selectStartNode" |
| 76 | + ></button> |
| 77 | + </div> |
| 78 | + <div class="node-item end-node"> |
| 79 | + <span data-i18n="resources.text_endeNode"></span><input class="end" disabled /><button |
| 80 | + id="select-end-node" |
| 81 | + data-i18n="resources.text_selectEndNode" |
| 82 | + ></button> |
| 83 | + </div> |
| 84 | + <div class="buttons"> |
| 85 | + <button id="analysis" data-i18n="resources.text_analysis"></button> |
| 86 | + <button id="reset" data-i18n="resources.text_reset"></button> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + <script type="text/javascript" include="g6" src="../../dist/mapboxgl/include-mapboxgl.js"></script> |
| 90 | + <script type="text/javascript"> |
| 91 | + var host = window.isLocal ? window.server : 'https://iserver.supermap.io'; |
| 92 | + const graphmap = new mapboxgl.supermap.GraphMap( |
| 93 | + host + '/iserver/services/knowledgeGraph-budongchan/restjsr/graph/graphmaps/图谱', |
| 94 | + { config: { dragNode: false } } |
| 95 | + ); |
| 96 | + graphmap.on('loaded', () => { |
| 97 | + graphmap.graph.on('click', (e) => { |
| 98 | + if (selectType && e.item && e.item._cfg.type === 'node') { |
| 99 | + const model = e.item.get('model'); |
| 100 | + const { id, label } = model; |
| 101 | + |
| 102 | + const oldNodeId = shortestPathParams[`${selectType}ID`]; |
| 103 | + graphmap.clearHighlight({ nodeIDs: [oldNodeId], edgeIDs: [] }); |
| 104 | + |
| 105 | + $(`.${selectType}`).val(label); |
| 106 | + shortestPathParams[`${selectType}ID`] = id; |
| 107 | + graphmap.highlight({ nodeIDs: [id], edgeIDs: [] }); |
| 108 | + } |
| 109 | + }); |
| 110 | + }); |
| 111 | + |
| 112 | + var shortestPathParams = { startID: '', endID: '' }; |
| 113 | + var oldHeightNodesEdges = { nodeIDs: [], edgeIDs: [] }; |
| 114 | + var selectType = ''; |
| 115 | + $('#select-start-node').on('click', () => { |
| 116 | + selectType = 'start'; |
| 117 | + resetStartEndNode(selectType); |
| 118 | + }); |
| 119 | + $('#select-end-node').on('click', () => { |
| 120 | + selectType = 'end'; |
| 121 | + resetStartEndNode(selectType); |
| 122 | + }); |
| 123 | + $('#analysis').on('click', () => { |
| 124 | + selectType = ''; |
| 125 | + setShortestPath(shortestPathParams); |
| 126 | + }); |
| 127 | + |
| 128 | + $('#reset').on('click', () => { |
| 129 | + selectType = ''; |
| 130 | + resetAll(); |
| 131 | + }); |
| 132 | + |
| 133 | + function resetStartEndNode(selectType) { |
| 134 | + $(`.${selectType}`).val(''); |
| 135 | + graphmap.clearHighlight({ nodeIDs: [shortestPathParams[`${selectType}ID`]], edgeIDs: [] }); |
| 136 | + shortestPathParams[`${selectType}ID`] = ''; |
| 137 | + } |
| 138 | + |
| 139 | + function resetAll() { |
| 140 | + resetStartEndNode('start'); |
| 141 | + resetStartEndNode('end'); |
| 142 | + graphmap.clearHighlight(oldHeightNodesEdges); |
| 143 | + } |
| 144 | + |
| 145 | + function setShortestPath({ startID, endID }) { |
| 146 | + graphmap.getShortestPath({ startID, endID }, (res) => { |
| 147 | + if (res.type === 'processCompleted' && res.result.succeed) { |
| 148 | + highlightShortestPath(res.result); |
| 149 | + } else { |
| 150 | + alert(res.error.errorMsg, false); |
| 151 | + } |
| 152 | + }); |
| 153 | + } |
| 154 | + |
| 155 | + function highlightShortestPath({ nodeIDs, edgeIDs }) { |
| 156 | + graphmap.clearHighlight(oldHeightNodesEdges); |
| 157 | + graphmap.highlight({ nodeIDs, edgeIDs }); |
| 158 | + oldHeightNodesEdges = { nodeIDs, edgeIDs }; |
| 159 | + } |
| 160 | + </script> |
| 161 | + </body> |
| 162 | +</html> |
0 commit comments