gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:31:52 27 4
gpt4 key购买 nike

我想实现这样的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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com