简体   繁体   English

您可以在mapbox上设置圆的动画吗,并且也可以有空心圆

[英]Can you animate circles on mapbox, and also, just have hollow circles

I know you can animate circles on google maps , see example 我知道您可以为Google地图上的圈子设置动画,请参见示例

http://jsbin.com/nuwem/1/edit?html,output http://jsbin.com/nuwem/1/edit?html,output

 .....But can you do the same thing on Mapbox

I am creating a live earthquake map www.livehazards.com. 我正在创建地震现场地图www.livehazards.com。 Each earthquake mag is respresent by a circle 每个地震mag用一个​​圆圈表示

I would just like the outline of the circle and to be able to animate it. 我只想要圆圈的轮廓并能够对其进行动画处理。

I have tried using circle-stroke for just the outline but it did not work 我尝试仅将笔划用作轮廓线,但它没有用

Thanks 谢谢

To animate your circle you can simply change its paint property several times: map.setPaintProperty('yourmarker', 'circle-radius', 20) 要为您的圈子设置动画,您可以简单地多次更改其绘画属性: map.setPaintProperty('yourmarker', 'circle-radius', 20)

If you only want the circle outline, set "circle-opacity":0 and "circle-stroke-width": 1 . 如果只需要圆形轮廓,则设置"circle-opacity":0"circle-stroke-width": 1

Codepen Codepen

const map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/light-v9',
    center: [ 2.35, 48.85 ],
    zoom: 3
});

map.on('load', () => {
  let radius = 1;

  map.addLayer({
        "id": "points",
        "type": "circle",

        // Create the marker
        "source": {
            "type": "geojson",
            "data": {
                "type": "FeatureCollection",
                "features": [{
                    "type": "Feature",
                    "geometry": {
                        "type": "Point",
                        "coordinates": [ 2.35, 48.85 ]
                    }
                }]
            }
        },

        // Draw the circle
        "paint": {
          "circle-opacity": 0,
          "circle-stroke-width": 1,
          "circle-stroke-color": "#000",
          "circle-radius": radius,
          "circle-radius-transition": {
            "duration": 0
          }
        }
    });

    // Animate the circle
    setInterval(() => {
      map.setPaintProperty('points', 'circle-radius', radius);
      radius = ++radius % 30;
    }, 50);
});
 var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [ 2.35, 48.85 ],
zoom: 3

}); });

map.on('load', function() {
     let radius = 1;
   map.addSource("earthquakes", {
    type: "geojson",
    data: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson",
});
  map.addLayer({
    "id": "earthquake-layer",
    "type": "circle",
    "source": "earthquakes",
    "paint": {
      "circle-opacity": 0.4,
      "circle-color": "#830300",
      "circle-stroke-width": 2,
      "circle-stroke-color": "#fff",
      "circle-radius": {
            "property": "mag",
            "base": 2.5,
            "stops": [
                [{zoom: 0,  value: 2}, 1],
                [{zoom: 0,  value: 8}, 40],
                [{zoom: 11, value: 2}, 10],
                [{zoom: 11, value: 8}, 2400],
                [{zoom: 20, value: 2}, 20],
                [{zoom: 20, value: 8}, 6000]
              "circle-radius-transition": {
        "duration": 0
      }
            ]
        }
    }
});
setInterval(() => {
  map.setPaintProperty('eaarthquake-layer', 'circle-radius', radius);
  radius = ++radius % 30
}, 50);

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM