<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <!-- Include the CesiumJS JavaScript and CSS files --> <script src="https://cesium.com/downloads/cesiumjs/releases/1.100/Build/Cesium/Cesium.js"></script> <link href="https://cesium.com/downloads/cesiumjs/releases/1.100/Build/Cesium/Widgets/widgets.css" rel="stylesheet"> </head> <body> <div id="cesiumContainer"></div> <script> // Your access token can be found at: https://cesium.com/ion/tokens. // Replace `your_access_token` with your Cesium ion access token.
// Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID. const viewer = new Cesium.Viewer('cesiumContainer', { terrainProvider: Cesium.createWorldTerrain() }); // Add Cesium OSM Buildings, a global 3D buildings layer. const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings()); // Fly the camera to San Francisco at the given longitude, latitude, and height. viewer.camera.flyTo({ destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400), orientation : { heading : Cesium.Math.toRadians(0.0), pitch : Cesium.Math.toRadians(-15.0), } }); </script> </div> </body> </html>
通常會噴類似以下的訊息 Access to XMLHttpRequest at 'http://localhost:8080/geoserver/ows?SERVICE=WMS&REQUEST=GetCapabilities&tiled=true' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
首先找到這個檔案 webapps\geoserver\WEB-INF\web.xml 看是用 Jetty or Tomcat 把它標示的註解打開就好 Uncomment following filter to enable CORS in Jetty. Do not forget the second config block further down 接著要找到這串 Uncomment following filter to enable CORS 一樣把註解打開