mapbox - 如何将中心标记向右偏移?

标签 mapbox

我想实现这样的http://techblog.mappy.com/Leaflet-active-area/examples/index.html

我在该部分的左侧添加了 float 内容。因此标记必须保留在右侧。

这是一个demo .

JS:

// ***********************************************
 mapboxgl.accessToken = 'pk.eyJ1IjoiZmFseiIsImEiOiJjaXdmczJha28wMG9sMnVsZnlxZWt1bmxhIn0.v8SlQ70Ay1MzNoPXhlXWVg';
// ***********************************************
// DID YOU FORK THIS EXAMPLE?
// Enter your access token below
// and uncomment the line to keep your
// project online!
// Need a token? Create free account 
// mapbox.com/signup
// ***********************************************
// mapboxgl.accessToken = 'YOUR-ACCESS-TOKEN-HERE';
// ***********************************************
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/light-v9',
    center: [144.985258,-37.807426],
    zoom: 14
});

var framesPerSecond = 15; 
var initialOpacity = 1
var opacity = initialOpacity;
var initialRadius = 6;
var radius = initialRadius;
var maxRadius = 18;

map.on('load', function () {

    // Add a source and layer displaying a point which will be animated in a circle.
    map.addSource('point', {
        "type": "geojson",
        "data": {
            "type": "Point",
            "coordinates": [
                144.985258, -37.807426
            ]
        }
    });

    map.addLayer({
        "id": "point",
        "source": "point",
        "type": "circle",
        "paint": {
            "circle-radius": initialRadius,
            "circle-radius-transition": {duration: 0},
            "circle-opacity-transition": {duration: 0},
            "circle-color": "#007cbf"
        }
    });

    map.addLayer({
        "id": "point1",
        "source": "point",
        "type": "circle",
        "paint": {
            "circle-radius": initialRadius,
            "circle-color": "#007cbf"
        }
    });


    function animateMarker(timestamp) {
        setTimeout(function(){
            requestAnimationFrame(animateMarker);

            radius += (maxRadius - radius) / framesPerSecond;
            opacity -= ( .9 / framesPerSecond );

            map.setPaintProperty('point', 'circle-radius', radius);
            map.setPaintProperty('point', 'circle-opacity', opacity);

            if (opacity <= 0) {
                radius = initialRadius;
                opacity = initialOpacity;
            } 

        }, 1000 / framesPerSecond);

    }

    // Start the animation.
    animateMarker(0);
});

最佳答案

不幸的是,目前还不支持带有填充的 fitBounds 之类的东西。 https://github.com/mapbox/mapbox-gl-js/issues/1740

一个可能的解决方法是飞向带有偏移的标记。

  map.flyTo({
    center: [144.985258, -37.807426],
    offset: [300, 0],
    speed: 0.8,
    curve: .6
  });

关于mapbox - 如何将中心标记向右偏移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41035400/

相关文章:

geolocation - MapBox 通过 IP 地址进行地理定位

javascript - 切换传单侧边栏 V2

javascript - 检测软件与硬件 webGL 渲染模式

javascript - Mapbox GL JS - 数据驱动样式 - 查找图层中数据的最小值和最大值或范围

javascript - mapbox-gl js 对 "text-offset"使用步进斜坡

java - Mapbox OfflineRegionObserver 监听器注销

mapbox - 使用 Mapbox-gl-js 按 JSON 属性过滤聚类点

data-visualization - 排除 Mapbox Studio 中指定区域之外的标签

mapbox - 在 Mapbox gl 上绘制矩形

java - 我想将 GeoJson 添加到 mapbox map 快照