本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
如何为地图设置样式功能
Amazon Location Service 允许您设置样式功能以自定义地图。您可以向地图添加地形、等高线密度、交通和出行模式要素。
-
地形:启用地形可视化以显示海拔变化和地理特征,帮助用户了解其地图区域的物理景观。
-
ContourDensity:调整等高线密度等级以显示地形陡度和海拔变化。
-
交通:叠加实时交通数据以显示当前的交通状况,例如当前的道路拥堵、施工和事故,从而做出明智的路线决策。
-
TravelMode:选择特定于交通的图层,以显示具有道路限制的公共交通或卡车导航的相关路线信息。
在本示例中,您将创建一个带有复选框的地图,用于单独或同时可视化地形和等高线。
- Index.html
-
<!DOCTYPE html> <html lang="en"> <head> <title>Terrain and Contour Map</title> <meta charset='utf-8'> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel='stylesheet' href='https://unpkg.com/maplibre-gl@4.x/dist/maplibre-gl.css' /> <style> .controls { position: absolute; top: 10px; left: 10px; background: white; padding: 10px; border-radius: 5px; z-index: 1000; } </style> <script src='https://unpkg.com/maplibre-gl@4.x/dist/maplibre-gl.js'></script> </head> <body> <div class="controls"> <label><input type="checkbox" id="terrain" checked> Terrain</label><br> <label><input type="checkbox" id="contour" checked> Contour Lines</label> </div> <div id="map" style="width: 100%; height: 100vh;"></div> <script> const apiKey = "Add Your Api Key"; const mapStyle = "Standard"; const awsRegion = "us-east-1"; let terrainEnabled = true; let contourEnabled = true; function updateMap() { // Built-in JavaScript API that handles URL query parameters const params = new URLSearchParams({ key: apiKey }); if (terrainEnabled) params.append('terrain', 'Hillshade'); if (contourEnabled) params.append('contour-density', 'Medium'); const styleUrl = `https://maps.geo.${awsRegion}.amazonaws.com/v2/styles/${mapStyle}/descriptor?${params}`; map.setStyle(styleUrl); } const map = new maplibregl.Map({ container: 'map', style: `https://maps.geo.${awsRegion}.amazonaws.com/v2/styles/${mapStyle}/descriptor?terrain=Hillshade&contour-density=Medium&key=${apiKey}`, center: [-119.5383, 37.8651], // Yosemite coordinates for terrain visibility zoom: 10, }); document.getElementById('terrain').addEventListener('change', (e) => { terrainEnabled = e.target.checked; updateMap(); }); document.getElementById('contour').addEventListener('change', (e) => { contourEnabled = e.target.checked; updateMap(); }); </script> </body> </html>
在本示例中,您将创建启用卡车出行模式图层的地图,以显示卡车特定的路径信息和道路限制。
- Index.html
-
<!DOCTYPE html> <html lang="en"> <head> <title>Truck routing map</title> <meta charset='utf-8'> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel='stylesheet' href='https://unpkg.com/maplibre-gl@4.x/dist/maplibre-gl.css' /> <script src='https://unpkg.com/maplibre-gl@4.x/dist/maplibre-gl.js'></script> </head> <body> <div id="map" style="width: 100%; height: 100vh;"></div> <script> const apiKey = "Add Your Api Key"; const mapStyle = "Standard"; const awsRegion = "us-east-1"; const truckMapStyleUrl = `https://maps.geo.${awsRegion}.amazonaws.com/v2/styles/${mapStyle}/descriptor?travel-modes=Truck&key=${apiKey}`; const map = new maplibregl.Map({ container: 'map', style: truckMapStyleUrl, center: [-74.0060, 40.7128], // NYC coordinates zoom: 12, }); </script> </body> </html>
筛选 POI
静态地图