私は、その場所がリアルタイムで表示される作業リーフレットマップを持っています。緯度と経度の値は毎秒で、毎回変わる値に基づいて地図が表示されます。今、私は最後の10の位置履歴をポリラインに表示したいが、最後の10の位置をポリラインとして表示するには、10の場所の配列が必要です。どのように私は最後の10の場所の歴史を持つ配列を作成することができますか?ここでリーフレットマップへのプロットライン
は私が反応し、リーフレットないとimmutablejsリーフレットを使用しています
import L from 'leaflet';
componentDidMount() {
const { currentValue } = this.props;
const latestValue = currentValue.split(':');
const lat = getNumber(latestValue[0]);
const long = getNumber(latestValue[1]);
this.map = L.map(this.element).setView([lat, long], 15);
// Google Map
L.tileLayer('*****', {
maxZoom: 20,
}).addTo(this.map);
this.marker = L.marker([lat, long], { icon: MarkerIcon });
this.marker.addTo(this.map);
const polyLinePoints = [
new L.LatLng(lat, long),
new L.LatLng(lat, long),
new L.LatLng(lat, long),
new L.LatLng(lat, long),
];
const polyLineOptions = {
color: 'blue',
weight: '5',
opacity: 0.9
};
const polyline = L.polyline(polyLinePoints, polyLineOptions).addTo(this.map);
this.map.fitBounds(polyline.getBounds());
}
componentDidUpdate() {
const { currentValue } = this.props;
const latestValue = currentValue.split(':');
const lat = getNumber(latestValue[0]);
const long = getNumber(latestValue[1]);
console.log('lat', lat, long);
// latlng.push([lat,long]);
const polyLinePoints = [
new L.LatLng(lat, long),
new L.LatLng(lat, long),
new L.LatLng(lat, long),
new L.LatLng(lat, long),
];
const polyLineOptions = {
color: 'blue',
weight: '5',
opacity: 0.9
};
this.marker.remove();
this.marker = L.marker([lat, long], { icon: MarkerIcon });
this.marker.addTo(this.map);
// invalidateSize forces map to recalculate its size
// next, move the center to given coordinate
this.map.invalidateSize(false).setView([lat, long]);
const polyline = L.polyline(polyLinePoints, polyLineOptions).addTo(this.map);
this.map.fitBounds(polyline.getBounds());
}
render() {
const { width, height } = this.props;
return (
<div
ref={(element) => { this.element = element; }}
style={{ width, height }}
></div>
);
}
}
を行っているものです。場所が更新されるたびに後
私はimmutablejsを使用していますので、this.polyLinePoints = List([])は良いと思います。私はこれを試し、これがうまくいくかどうかを言うでしょう。 – pythonBeginner
this.polyLinePoints = List([])を使用すると、新しいポイントを追加して各ポイントを「右の次のポイント」に切り替える構文が少し違って見えるかもしれませんが、最新の10のものが同じでなければならないと思う。 – thinhvo0108
申し訳ありませんが、私は、それぞれのポイントを "右の次のポイント"に切り替えることを理解していませんでした。 immutablejsリストはプッシュをサポートしていますか? – pythonBeginner