2019-11-04 10:59:08 +01:00
|
|
|
<!DOCTYPE html>
|
2019-11-11 12:34:43 +01:00
|
|
|
<html lang="en" class="dark-mode">
|
2019-11-04 10:59:08 +01:00
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<title>MapApp</title>
|
|
|
|
|
2019-11-11 12:34:43 +01:00
|
|
|
<script src="../../3rdparty/highlight/highlight.pack.js"></script>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../../../fonts/material-icon-font/material-icons.css">
|
|
|
|
<link rel='stylesheet' href='../../3rdparty/highlight/styles/vs2015.css'>
|
2019-11-04 10:59:08 +01:00
|
|
|
<link rel='stylesheet' href='../../../css/doctest.css'>
|
|
|
|
|
|
|
|
<script src="../../../dist/iwmlib.3rdparty.js"></script>
|
|
|
|
<script src="../../../dist/iwmlib.js"></script>
|
|
|
|
<script src="../../../dist/iwmlib.pixi.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.controls {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="Doctest.run()">
|
|
|
|
<h1>MapApp</h1>
|
|
|
|
<p>
|
|
|
|
This class extends the PIXIApp to simplify the process of rendering
|
|
|
|
Maps in the canvas. For that reason, it contains useful functions
|
|
|
|
for an easier handling of maps in the canvas.
|
|
|
|
</p>
|
|
|
|
<canvas id="canvas"></canvas>
|
2019-11-11 12:34:43 +01:00
|
|
|
<div id="mapControl"></div>
|
2019-11-04 10:59:08 +01:00
|
|
|
<div id="cityControl" class="controls"></div>
|
|
|
|
<p><strong>WHAT TO SEE:</strong> The map should focus Paris.</p>
|
2019-11-11 12:34:43 +01:00
|
|
|
<script>
|
|
|
|
let osmConfig = {
|
|
|
|
"projection": "mercator",
|
|
|
|
"type": "deepzoom",
|
|
|
|
"tiles": {
|
|
|
|
"tileSize": 256,
|
|
|
|
"format": "png",
|
|
|
|
"overlap": 0,
|
|
|
|
"type": "map",
|
|
|
|
"height": 1024,
|
|
|
|
"width": 1024,
|
|
|
|
"path": "../assets/maps/osm",
|
|
|
|
"urlTileTemplate": "{path}/{level}/{row}/{column}.{format}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let testConfig = {
|
|
|
|
"projection": "mercator",
|
|
|
|
"type": "deepzoom",
|
|
|
|
"tiles": {
|
|
|
|
"tileSize": 128,
|
|
|
|
"format": "jpg",
|
|
|
|
"overlap": 0,
|
|
|
|
"type": "map",
|
|
|
|
"height": 4096,
|
|
|
|
"width": 4096,
|
|
|
|
"path": "../assets/maps/test",
|
|
|
|
"urlTileTemplate": "{path}/{level}/{row}/{column}.{format}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
2019-11-04 10:59:08 +01:00
|
|
|
<script class="doctest">
|
|
|
|
let capitals = {
|
|
|
|
london: { x: 51.5, y: -0.083333 },
|
|
|
|
rome: { x: 41.9, y: 12.483333 },
|
|
|
|
madrid: { x: 40.4, y: -3.683333 },
|
|
|
|
paris: { x: 48.833986, y: 2.346989 }
|
|
|
|
}
|
|
|
|
|
|
|
|
// You may define a focus point ...
|
|
|
|
let focus = capitals.paris
|
|
|
|
|
|
|
|
// ... and a zoom level.
|
|
|
|
let zoom = 1
|
|
|
|
|
|
|
|
// Name has to be app (like all other PIXIApps).
|
|
|
|
const app = (window.app = new MapApp({
|
|
|
|
focus,
|
|
|
|
zoom,
|
|
|
|
view: canvas,
|
|
|
|
coordsLogging: true,
|
|
|
|
width: 512,
|
|
|
|
height: 512
|
|
|
|
}))
|
|
|
|
|
|
|
|
// As map an image of europe is used.
|
|
|
|
let europe = '../assets/maps/pixabay/europe.jpg'
|
|
|
|
|
|
|
|
//Preload all required sprites for the image map.
|
|
|
|
app.loadSprites([europe], sprites => ready(sprites), {
|
|
|
|
resolutionDependent: false
|
|
|
|
})
|
|
|
|
|
|
|
|
// The mapdata object contains informations,
|
|
|
|
// how the displayed map has to be interpreted.
|
|
|
|
// e.g. which projection is used or how the
|
|
|
|
// image is clipped.
|
2019-12-11 16:45:26 +01:00
|
|
|
let europeData = new MapProjection(new Projection.Mercator(), {
|
2019-11-04 10:59:08 +01:00
|
|
|
clip: {
|
|
|
|
min: { x: 32.863294, y: -18.58 },
|
|
|
|
max: { x: 57.467973, y: 44.277158 }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
function ready(sprites) {
|
2019-11-13 12:42:06 +01:00
|
|
|
|
|
|
|
const cover = true
|
|
|
|
|
2019-11-04 10:59:08 +01:00
|
|
|
// When resources are loaded, the ImageMap can be instantiated.
|
|
|
|
let imageMap = new ImageMap(sprites.get(europe), europeData, {
|
|
|
|
coordsLogging: true,
|
|
|
|
maxScale: 1,
|
2019-11-13 12:42:06 +01:00
|
|
|
cover
|
2019-11-04 10:59:08 +01:00
|
|
|
})
|
|
|
|
|
2019-12-11 16:45:26 +01:00
|
|
|
let testMapProjection = new DeepZoomMapProjection(new Projection.Mercator(), testConfig.tiles, {
|
2019-11-11 12:34:43 +01:00
|
|
|
app
|
|
|
|
})
|
2019-12-11 16:45:26 +01:00
|
|
|
let testMap = new DeepZoomMap(testMapProjection, Object.assign({}, testConfig.tiles, { app }), { cover })
|
2019-11-11 12:34:43 +01:00
|
|
|
app.addMap("test", testMap)
|
|
|
|
|
2019-12-11 16:45:26 +01:00
|
|
|
let osmMapProjection = new DeepZoomMapProjection(new Projection.Mercator(), osmConfig.tiles, {
|
2019-11-11 12:34:43 +01:00
|
|
|
app
|
|
|
|
})
|
2019-12-11 16:45:26 +01:00
|
|
|
let deepZoomMap = new DeepZoomMap(osmMapProjection, Object.assign({}, osmConfig.tiles, { app }), { cover })
|
2019-11-11 12:34:43 +01:00
|
|
|
app.addMap("osm", deepZoomMap)
|
|
|
|
|
2019-11-04 10:59:08 +01:00
|
|
|
// Finally apply the map to the MapApp
|
|
|
|
app.setMap('europe', imageMap)
|
|
|
|
|
|
|
|
// The app requires a map before beeing able to run.
|
|
|
|
// So start the app here.
|
|
|
|
app.setup().run()
|
2019-11-11 12:34:43 +01:00
|
|
|
|
|
|
|
for (let [key, val] of Object.entries(app.mapList.maps)) {
|
|
|
|
let mapBtn = document.createElement("button")
|
|
|
|
mapBtn.innerText = key
|
|
|
|
mapBtn.addEventListener("click", () => {
|
|
|
|
app.mapLayer.changeMap(val)
|
|
|
|
})
|
|
|
|
mapControl.appendChild(mapBtn)
|
|
|
|
}
|
2019-11-04 10:59:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let [key, val] of Object.entries(capitals)) {
|
|
|
|
let cityBtn = document.createElement("button")
|
|
|
|
cityBtn.innerText = key
|
|
|
|
cityBtn.addEventListener("click", () => {
|
|
|
|
app.mapLayer.map.moveTo(val)
|
|
|
|
})
|
|
|
|
cityControl.appendChild(cityBtn)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|