[Mapbox GL]添加一个视频

           在顶端添加卫星栅格基础层


<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8' />
    <title></title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.29.0/mapbox-gl.js'></script>
    <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.29.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        body { margin:0; padding:0; }
        #map { position:absolute; top:0; bottom:0; width:100%; }
    </style>
</head>
<body>

<div id='map'></div>
<script>
mapboxgl.accessToken = '<your access token here>';
var videoStyle = {            /* 在创建map时就添加source和layer */
    "version": 8,
    "sources": {
        "satellite": {
            "type": "raster", /* raster类型资源 */
            "url": "mapbox://mapbox.satellite",
            "tileSize": 256   /* 在layer上显示瓦片的最小可视化尺寸,单位是像素 */   
        },
        "video": {
            "type": "video",  /* video类型资源 */
            "urls": ["https://www.mapbox.com/drone/video/drone.mp4", "https://www.mapbox.com/drone/video/drone.webm"],
            "coordinates": [
                [-122.51596391201019, 37.56238816766053],
                [-122.51467645168304, 37.56410183312965],
                [-122.51309394836426, 37.563391708549425],
                [-122.51423120498657, 37.56161849366671]
            ]
        }
    },
    "layers": [{
        "id": "background",
        "type": "background",
        "paint": {
            "background-color": "rgb(4,7,14)"
        }
    }, {
        "id": "satellite",
        "type": "raster",
        "source": "satellite"
    }, {
        "id": "video",
        "type": "raster",
        "source": "video"
    }]
};

var map = new mapboxgl.Map({
    container: 'map',
    minZoom: 14,
    zoom: 17,
    center: [-122.514426, 37.562984],
    bearing: -96,
    style: videoStyle,
    hash: false
});
</script>

</body>
</html>


以下是一个使用MapboxGL添加一个marker并实现高亮闪烁效果的完整代码示例: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>MapboxGL Marker Highlight Animation</title> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> <script src="https://api.mapbox.com/mapbox-gl-js/v2.5.1/mapbox-gl.js"></script> <link href="https://api.mapbox.com/mapbox-gl-js/v2.5.1/mapbox-gl.css" rel="stylesheet" /> <style> body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; } .highlight-animation { animation: highlight 1s infinite; } @keyframes highlight { 0% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.5); } 100% { opacity: 1; transform: scale(1); } } </style> </head> <body> <div id="map"></div> <script> mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN'; var lng = -122.4194; // 经度 var lat = 37.7749; // 纬度 var zoomLevel = 12; // 缩放级别 // 创建地图实例 var map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v11', center: [lng, lat], zoom: zoomLevel }); // 创建一个图层,并向地图添加一个marker var marker = new mapboxgl.Marker({ element: createMarkerElement() }) .setLngLat([lng, lat]) .addTo(map); // 为标记元素添加动画类 marker.getElement().classList.add('highlight-animation'); // 创建标记元素及样式 function createMarkerElement() { var el = document.createElement('div'); el.className = 'marker'; el.style.backgroundImage = 'url(https://example.com/your-marker-icon.png)'; // 替换为您自己的标记图标URL el.style.width = '40px'; el.style.height = '40px'; el.style.backgroundRepeat = 'no-repeat'; el.style.backgroundSize = 'cover'; return el; } </script> </body> </html> ``` 请确保将YOUR_MAPBOX_ACCESS_TOKEN替换为您自己的Mapbox访问令牌,并将`https://example.com/your-marker-icon.png`替换为您自己的标记图标的URL。 通过上述代码,您将能够在MapboxGL地图上添加一个marker,并为其添加高亮闪烁的动画效果。根据您的需求,您可以调整地图的样式、标记的位置和动画效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值