1、使用幻燈片的案例
https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=webscene-slides
2、參照以上案例,自己寫個案例
上面的案例略微複雜,是以自己寫個簡單的vue元件的案例。
隻有webscene才有幻燈片,周遊webscene的presentation.slides,建立幻燈片。
<template>
<div id="viewDiv">
<div id="slidesDiv" class="esri-widget"></div>
</div>
</template>
<script>
import WebScene from "@arcgis/core/WebScene";
import SceneView from "@arcgis/core/views/SceneView";
import esriConfig from "@arcgis/core/config"
/*
建立幻燈片、試用webscene
*/
export default {
name:"test002",
data() {
return {
content:"Hello"
}
},
created(){
},
methods:{
},
mounted(){
esriConfig.apiKey = "your api key";
var scene = new WebScene({
basemap:"dark-gray-vector",
ground:"world-elevation",
portalItem: {
// autocasts as new PortalItem()
id: "3a9976baef9240ab8645ee25c7e9c096"
}
});
var view = new SceneView({
map: scene,
container: "viewDiv",
padding: {
top: 40
}
})
function createSlideUI(slide, placement) {
var slideElement = document.createElement("div");
// Assign the ID of the slide to the <span> element
slideElement.id = slide.id;
slideElement.classList.add("slide");
var slidesDiv = document.getElementById("slidesDiv");
if (placement === "first") {
slidesDiv.insertBefore(slideElement, slidesDiv.firstChild);
} else {
slidesDiv.appendChild(slideElement);
}
var title = document.createElement("div");
title.innerText = slide.title.text;
// Place the title of the slide in the <div> element
slideElement.appendChild(title);
var img = new Image();
// Set the src URL of the image to the thumbnail URL of the slide
img.src = slide.thumbnail.url;
// Set the title property of the image to the title of the slide
img.title = slide.title.text;
// Place the image inside the new <div> element
slideElement.appendChild(img);
/*********************************************************************
* Set up a click event handler on the newly created slide. When clicked,
* the code defined below will execute.
*********************************************************************/
slideElement.addEventListener("click", function() {
/*******************************************************************
* Remove the "active" class from all elements with the .slide class
*******************************************************************/
var slides = document.querySelectorAll(".slide");
Array.from(slides).forEach(function(node) {
node.classList.remove("active");
});
/*******************************************************************
* Add the "active" class on the current element being selected
*******************************************************************/
slideElement.classList.add("active");
slide.applyTo(view);
});
}
view.ui.add(["slidesDiv"], "top-right");
//發生在scene.when()之後
view.when(()=>{
console.log("所有圖層和底圖被加載");
var slides = scene.presentation.slides;
slides.forEach(createSlideUI);
})
}
}
</script>
<style scoped>
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#slidesDiv {
background-color: white;
opacity: 0.9;
color: black;
padding: 10px;
visibility: visible;
bottom: 20px;
overflow-y: auto;
text-align: center;
height: 260px;
}
#slidesDiv .slide {
/* Show cursor as pointer when on a slide */
cursor: pointer;
margin-bottom: 6px;
}
#slidesDiv .slide .title {
/* Center the title text */
text-align: center;
}
/* Draw active slide with a nice border around the thumbnail */
#slidesDiv .slide.active img {
box-shadow: 0px 0px 12px black;
border-style: solid;
border-width: thin;
border-color: black;
}
</style>