orgchart
Version:
Simple and direct organization chart(tree-like hierarchy) library based on pure DOM.
108 lines (101 loc) • 3.62 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>OrgChart Map Integration Demo</title>
<link rel="icon" href="img/logo.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol.css">
<link rel="stylesheet" href="css/orgchart.css">
<link rel="stylesheet" href="css/style.css">
<style type="text/css">
#map {
position: fixed;
inset: 0;
z-index: 0;
}
#chart-container {
position: absolute;
top: 10px;
left:40px;
height: auto;
max-height: 330px;
width: calc(100% - 80px);
z-index: 1;
border-color: rgba(217, 83, 79, 0.9);
}
.orgchart {
background: rgba(255,255,255,0.75);
}
</style>
</head>
<body id="pageBody">
<section class="demo-notes demo-notes--overlay">
<h1>Map Integration Demo</h1>
<p>This demo overlays the org chart on a map and recenters the map view when users click a node with geographic coordinates.</p>
</section>
<div id="map"></div>
<div id="chart-container"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol.js"></script>
<script type="text/javascript" src="js/orgchart.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
const map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
attributions: '© OpenStreetMap contributors © CARTO',
crossOrigin: 'anonymous',
url: 'https://{a-d}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png'
}),
preload: 4
})
],
target: 'map',
view: new ol.View({
center: ol.proj.transform([-87.6297980, 41.8781140], 'EPSG:4326', 'EPSG:3857'),
zoom: 10
})
});
const datasource = {
'name': 'Lao Lao',
'title': 'President Office',
'position': [-87.6297980, 41.8781140],
'children': [
{ 'name': 'Bo Miao', 'title': 'Administration Dept.', 'position': [-83.0457540, 42.3314270]},
{ 'name': 'Su Miao', 'title': 'R & D Dept.', 'position': [-81.6943610, 41.4993200]},
{ 'name': 'Yu Jie', 'title': 'Product Dept.', 'position': [-71.0588800, 42.3600820]},
{ 'name': 'Yu Li', 'title': 'Legal Dept.', 'position': [-74.0059410, 40.7127840]},
{ 'name': 'Hong Miao', 'title': 'Finance Dept.', 'position': [-80.8431270, 35.2270870]},
{ 'name': 'Yu Wei', 'title': 'Security Dept.', 'position': [-81.6556510, 30.3321840]},
{ 'name': 'Chun Miao', 'title': 'HR Dept. ', 'position': [-81.3792360, 28.5383350]},
{ 'name': 'Yu Tie', 'title': 'Marketing Dept.', 'position': [-80.1917900, 25.7616800] }
]
};
const oc = new OrgChart({
chartContainer: '#chart-container',
'data' : datasource,
'nodeContent': 'title',
'createNode': function(node, data) {
node.addEventListener('click', () => {
const view = map.getView();
const duration = 2000;
const start = +new Date();
const pan = ol.animation.pan({
duration: duration,
source: view.getCenter(),
start: start
});
const bounce = ol.animation.bounce({
duration: duration,
resolution: 4 * view.getResolution(),
start: start
});
map.beforeRender(pan, bounce);
view.setCenter(ol.proj.transform(data.position, 'EPSG:4326', 'EPSG:3857'));
});
}
});
});
</script>
</body>
</html>