-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[requested-changes] Keep original aspect ratio of the image
- Loading branch information
1 parent
b308c54
commit 44e9fe7
Showing
2 changed files
with
124 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,137 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Indoor map</title> | ||
<meta charset="utf-8" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css" | ||
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" | ||
crossorigin="" | ||
/> | ||
<!-- theme can be easily customized via css --> | ||
<link href="../src/css/netjsongraph-theme.css" rel="stylesheet" /> | ||
<link href="../src/css/netjsongraph.css" rel="stylesheet" /> | ||
|
||
<head> | ||
<title>Indoor map</title> | ||
<meta charset="utf-8" /> | ||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css" | ||
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" | ||
crossorigin="" /> | ||
<!-- theme can be easily customized via css --> | ||
<link href="../src/css/netjsongraph-theme.css" rel="stylesheet" /> | ||
<link href="../src/css/netjsongraph.css" rel="stylesheet" /> | ||
<link rel="preload" href="./data/floorplan.png" as="image" /> | ||
<style> | ||
.njg-tooltip { | ||
background: rgba(0, 0, 0, 0.75) !important; | ||
border: none !important; | ||
} | ||
|
||
<link rel="preload" href="./data/indoormap.jpg" as="image" /> | ||
</head> | ||
|
||
<body> | ||
<script type="text/javascript" src="../dist/netjsongraph.min.js"></script> | ||
<script> | ||
/* | ||
.njg-tooltip-key, | ||
.njg-tooltip-value { | ||
color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<script type="text/javascript" src="../dist/netjsongraph.min.js"></script> | ||
<script> | ||
/* | ||
The demo is used to show how to set indoor map. | ||
Mainly the operation of leaflet. | ||
See `onLoad` below for details. | ||
*/ | ||
const graph = new NetJSONGraph("./data/netjsonmap-indoormap.json", { | ||
render: "map", | ||
// set map initial state. | ||
mapOptions: { | ||
center: [48.577, 18.539], | ||
zoom: 5.7, | ||
zoomSnap: 0.3, | ||
minZoom: 3.5, | ||
maxZoom: 9, | ||
nodeConfig: { | ||
label: { | ||
offset: [0, -10], | ||
fontSize: '14px', | ||
fontWeight: 'bold', | ||
color: 'red' | ||
const graph = new NetJSONGraph("./data/netjsonmap-indoormap.json", { | ||
render: "map", | ||
// set map initial state. | ||
mapOptions: { | ||
center: [48.577, 18.539], | ||
zoom: 5.5, | ||
zoomSnap: 0.3, | ||
minZoom: 3.5, | ||
maxZoom: 9, | ||
nodeConfig: { | ||
label: { | ||
offset: [0, -10], | ||
fontSize: "14px", | ||
fontWeight: "bold", | ||
color: "#D9644D", | ||
}, | ||
animation: false, | ||
}, | ||
animation: false, | ||
}, | ||
linkConfig: { | ||
linkStyle: { | ||
width: 4, | ||
linkConfig: { | ||
linkStyle: { | ||
width: 4, | ||
}, | ||
animation: false, | ||
}, | ||
animation: false, | ||
}, | ||
}, | ||
|
||
// Convert to internal json format | ||
prepareData: function (data) { | ||
data.nodes.map((node) => { | ||
node.label = node.name; | ||
node.properties = Object.assign(node.properties || {}, { | ||
location: node.location, | ||
// Convert to internal json format | ||
prepareData: function (data) { | ||
data.nodes.map((node) => { | ||
node.label = node.name; | ||
node.properties = Object.assign(node.properties || {}, { | ||
location: node.location, | ||
}); | ||
}); | ||
}); | ||
}, | ||
}, | ||
|
||
onLoad: function presentIndoormap() { | ||
const gui = this.utils.getGUI(this); | ||
gui.init(); | ||
if (this.config.metadata) { | ||
gui.createAboutContainer(graph); | ||
gui.sideBar.classList.add("hidden"); | ||
this.utils.updateMetadata.call(this); | ||
} | ||
if (this.config.switchMode) { | ||
gui.renderModeSelector.onclick = () => { | ||
if (this.config.render === this.utils.mapRender) { | ||
this.config.render = this.utils.graphRender; | ||
this.echarts.dispose(); | ||
graph = new NetJSONGraph(this.data, { | ||
...this.config, | ||
}); | ||
graph.render(); | ||
onLoad: function presentIndoormap() { | ||
const gui = this.utils.getGUI(this); | ||
gui.init(); | ||
if (this.config.metadata) { | ||
gui.createAboutContainer(graph); | ||
gui.sideBar.classList.add("hidden"); | ||
this.utils.updateMetadata.call(this); | ||
} | ||
if (this.config.switchMode) { | ||
gui.renderModeSelector.onclick = () => { | ||
if (this.config.render === this.utils.mapRender) { | ||
this.config.render = this.utils.graphRender; | ||
this.echarts.dispose(); | ||
graph = new NetJSONGraph(this.data, { | ||
...this.config, | ||
}); | ||
graph.render(); | ||
} else { | ||
this.config.render = this.utils.mapRender; | ||
this.config.render(this.data, this); | ||
} | ||
}; | ||
} | ||
this.config.onClickElement = (type, data) => { | ||
let nodeLinkData; | ||
if (type === "node") { | ||
nodeLinkData = this.utils.nodeInfo(data); | ||
} else { | ||
this.config.render = this.utils.mapRender; | ||
this.config.render(this.data, this); | ||
nodeLinkData = this.utils.linkInfo(data); | ||
} | ||
gui.getNodeLinkInfo(type, nodeLinkData); | ||
gui.sideBar.classList.remove("hidden"); | ||
}; | ||
} | ||
this.config.onClickElement = (type, data) => { | ||
let nodeLinkData; | ||
if (type === "node") { | ||
nodeLinkData = this.utils.nodeInfo(data); | ||
} else { | ||
nodeLinkData = this.utils.linkInfo(data); | ||
} | ||
gui.getNodeLinkInfo(type, nodeLinkData); | ||
gui.sideBar.classList.remove("hidden"); | ||
}; | ||
|
||
const netjsonmap = this.leaflet; | ||
const image = new Image(); | ||
image.src = './data/floorplan.png'; | ||
const netjsonmap = this.leaflet; | ||
const image = new Image(); | ||
image.src = "./data/floorplan.png"; | ||
|
||
const southWest = { lat: 53.39105802617281, lng: 2.258377075195313 }, | ||
northEast = { lat: 43.05747491746001, lng: 35.327825546264656 }; | ||
const aspectRatio = image.width / image.height; | ||
const height = 700; | ||
const width = aspectRatio * height; | ||
const southWest = {lat: 53, lng: 2}; | ||
const swPixel = netjsonmap.latLngToContainerPoint(southWest); | ||
const nePixel = swPixel.add(new L.Point(width, height)); | ||
const northEast = netjsonmap.containerPointToLatLng(nePixel); | ||
|
||
const bounds = new L.LatLngBounds(southWest, northEast); | ||
netjsonmap.setMaxBounds(bounds); | ||
const bounds = new L.LatLngBounds(southWest, northEast); | ||
netjsonmap.setMaxBounds(bounds); | ||
|
||
// remove the geographic map | ||
netjsonmap.eachLayer((layer) => { | ||
if (layer._url) { | ||
netjsonmap.removeLayer(layer); | ||
} | ||
}); | ||
// add indoormap image | ||
L.imageOverlay(image, bounds).addTo(netjsonmap); | ||
this.utils.hideLoading(); | ||
}, | ||
}); | ||
|
||
graph.render(); | ||
</script> | ||
</body> | ||
// remove the geographic map | ||
netjsonmap.eachLayer((layer) => { | ||
if (layer._url) { | ||
netjsonmap.removeLayer(layer); | ||
} | ||
}); | ||
// add indoormap image | ||
L.imageOverlay(image, bounds).addTo(netjsonmap); | ||
this.utils.hideLoading(); | ||
}, | ||
}); | ||
|
||
</html> | ||
graph.render(); | ||
</script> | ||
</body> | ||
</html> |