QtScrcpy 安卓投屏与键鼠映射指南:手机秒变大屏
2026/9/10 11:50:17
EPSG:3857)。Leaflet、Mapbox GL JS、Cesium(3D)。Cesium地形、建筑与相机控制,坐标与时间视角。示例:Leaflet 地图初始化与底图加载。
<!doctypehtml><htmllang="zh"><head><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1"/><title>Leaflet WebGIS 示例</title><linkrel="stylesheet"href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/><style>#map{height:600px;}</style></head><body><divid="map"></div><scriptsrc="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script><script>constmap=L.map('map').setView([39.9,116.4],11);constosm=L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{maxZoom:19,attribution:'© OpenStreetMap contributors'}).addTo(map);</script></body></html>示例:Mapbox GL JS 初始化(需替换为你自己的accessToken)。
<scriptsrc="https://api.mapbox.com/mapbox-gl-js/v2.16.1/mapbox-gl.js"></script><linkhref="https://api.mapbox.com/mapbox-gl-js/v2.16.1/mapbox-gl.css"rel="stylesheet"/><divid="glmap"style="height:600px"></div><script>mapboxgl.accessToken='YOUR_MAPBOX_ACCESS_TOKEN';constglmap=newmapboxgl.Map({container:'glmap',style:'mapbox://styles/mapbox/streets-v11',center:[116.4,39.9],zoom:11});</script>示例:在 Leaflet 中加载GeoJSON并应用样式与图层控制。
<script>// 叠加矢量层(示例数据需放置在 data/features.geojson)fetch('data/features.geojson').then(res=>res.json()).then(geojson=>{conststyle={color:'#2F5597',weight:1,fillColor:'#4F81BD',fillOpacity:0.4};constoverlay=L.geoJSON(geojson,{style}).addTo(map);constbaseLayers={OSM:osm};constoverlays={要素图层:overlay};L.control.layers(baseLayers,overlays,{collapsed:false}).addTo(map);});</script>示例:点击高亮与弹窗,鼠标悬停改变样式。
<script>functiononEachFeature(feature,layer){layer.on({click:(e)=>{constprops=feature.properties||{};constcontent=`<b>名称</b>:${props.name||'N/A'}<br/>`+`<b>ID</b>:${props.id||'N/A'}`;layer.bindPopup(content).openPopup();layer.setStyle({color:'#D35400',weight:2});},mouseover:()=>layer.setStyle({weight:3}),mouseout:()=>layer.setStyle({weight:1})});}// 加载时添加交互fetch('data/features.geojson').then(r=>r.json()).then(gj=>{L.geoJSON(gj,{onEachFeature}).addTo(map);});</script>GeoJSON通过fetch + L.geoJSON或map.addSource(Mapbox GL)。示例:Cesium 基本初始化。
<linkhref="https://cdnjs.cloudflare.com/ajax/libs/cesium/1.115/Widgets/widgets.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/cesium/1.115/Cesium.js"></script><divid="cesiumContainer"style="height:600px"></div><script>constviewer=newCesium.Viewer('cesiumContainer',{terrainProvider:Cesium.createWorldTerrain()});viewer.camera.flyTo({destination:Cesium.Cartesian3.fromDegrees(116.4,39.9,10000)});</script>以下流程图概述 WebGIS 前端交互的主要步骤:初始化 → 图层加载 → 事件绑定 → 弹窗与样式响应 → 产出与排障。
区分前端从数据源到图层渲染的主要链路,辅助理解性能与样式控制位置。
GeoJSON,实现缩放、图层切换与弹窗信息。index.html,按 14.4.1/14.4.2 加载底图与GeoJSON。index.html/assets/)、示例数据(data/features.geojson)、演示截图或预览链接。EPSG:3857或在后端进行重投影。accessToken过期或配额限制导致加载失败。gis_examples/ch14可一键运行与演示。gis_examples/ch14)gis_examples/ch14/index.html前端演示页面gis_examples/ch14/assets/本地样式与脚本gis_examples/ch14/data/features.geojson示例专题数据gis_examples/ch14/serve.py本地预览与静态资源服务TILE_URL指定底图(如https://tile.openstreetmap.org/{z}/{x}/{y}.png)MVT_URL指定矢量切片服务(若集成后端,参考第15章)data/*.geojson;不可用时展示提示并降级到空图层。ERR_CONNECTION_REFUSED)时,自动切换到备用源(TILE_URL_FALLBACK)。index.html),避免跨目录引用。示例伪代码(前端初始化与降级):
consttileUrl=window.TILE_URL||'https://tile.openstreetmap.org/{z}/{x}/{y}.png';constfallback='https://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png';constlayer=L.tileLayer(tileUrl);layer.on('tileerror',()=>{if(!layer._usedFallback){layer._usedFallback=true;layer.setUrl(fallback);console.warn('底图切换到备用源');}});layer.addTo(map);gis_examples/ch14目录,执行:python3 serve.pyhttp://localhost:<port>/进行预览(端口由脚本输出确认)。index.html与data/不同层级;统一为相对路径并在本地服务下测试。index.html拓展为可配置演示:支持底图切换、专题过滤、错误提示与降级。gis_examples/ch14下完成预览演示并提交截图与简要说明。cd gis_examples/ch14 python3 serve.py # 浏览器访问 http://localhost:<port>/ 并检查交互与降级策略