question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slowness when creating LineString

See original GitHub issue

Problem Description:

  • As the center of the map changes, I set the coordinate of the new center to the LineString component. But LineString changes very slowly.

This is video url for problem : https://vimeo.com/724430478


My Code:

import React, { useRef, useState } from 'react';
import { Pressable, View } from 'react-native';

//Third Party
import MapboxGL from '@rnmapbox/maps';

//Styles
import styles from './style';
import Icon from '@components/Icon';

MapboxGL.setAccessToken('NOT_REQUIRED');

const Maps = () => {
	const [points, setPoints] = useState([]);
	const [mapCenter, setMapCenter] = useState([]);

	const camRef = useRef(null);
	const mapRef = useRef(null);

	const RouteLine = () => {
		return (
			<MapboxGL.ShapeSource
				id="routeLine"
				shape={{
					type: 'FeatureCollection',
					features: [
						{
							type: 'Feature',
							properties: {},
							geometry: {
								type: 'LineString',
								coordinates: points,
							},
						},
					],
				}}>
				<MapboxGL.LineLayer
					id="lines"
					style={{
						lineColor: 'blue',
					}}
				/>
			</MapboxGL.ShapeSource>
		);
	};
	const LastLine = () => {
		return (
			<MapboxGL.ShapeSource
				id="LastLineShape"
				shape={{
					type: 'FeatureCollection',
					features: [
						{
							type: 'Feature',
							properties: {},
							geometry: {
								type: 'LineString',
								coordinates: [points?.[points?.length - 1] || [], mapCenter],
							},
						},
					],
				}}>
				<MapboxGL.LineLayer
					id="preLines"
					style={{
						lineColor: 'blue',
						lineDasharray: [10, 5],
					}}
				/>
			</MapboxGL.ShapeSource>
		);
	};

	const setNewPoint = async () => {
		const point = await mapRef?.current?.getCenter();
		setPoints(x => [...x, point]);
	};
	const changeMapRagion = val => {
		setMapCenter(val?.geometry?.coordinates);
	};

	return (
		<View style={styles.container}>
			<MapboxGL.MapView
				ref={mapRef}
				style={styles.map}
				logoEnabled={false}
				attributionEnabled={false}
				onRegionIsChanging={changeMapRagion}
				// onRegionDidChange={changeMapRagion}
				styleURL={'https://***.json'}>
				<MapboxGL.Camera ref={camRef} centerCoordinate={[35, 39]} zoomLevel={3.5} animationDuration={1200} />
				<RouteLine />
				{points?.length > 0 && <LastLine />}
			</MapboxGL.MapView>
			<View style={styles.target}>
				<Icon name="target : materialcomm" size={40} />
			</View>
			<Pressable style={styles.plusPointPress} onPress={setNewPoint} hitSlop={8}>
				<Icon name="plus : feather" size={40} color="#fff" />
			</Pressable>
		</View>
	);
};

export default Maps;

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jjrisecommented, Jul 30, 2022

react-native-maps. Would prefer this library and mapbox in general, but had some road blocks that held things up.

0reactions
sharathprabhalcommented, Jul 30, 2022

not sure if you had any luck with this? but I had a similar issue that I messed with for weeks that ultimately led me switching to a different mapping library. I was trying to build a linestring from a recorded route, and FPS would drop to <5 in only a few minutes. I can do the same in this new library for hours without any issues.

What lib did you switch to?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ST_Difference on linestrings and polygons slow and fails
I am trying to create a new table of linestrings with their existing attribution that are "different" to some polygons and am struggling...
Read more >
Improve performance of LineString creation, that currently is ...
I don't think your approach is that bad - creating a large number of shapely LineStrings from 1e6 points is just slow.
Read more >
QST: clip runs so slow · Issue #2593 · geopandas ... - GitHub
I am trying to clip linestrings from polygons. Both input data are quite large e.g. Polygons 86 million and linestring 1 million. I...
Read more >
LINESTRING | CockroachDB Docs
A LINESTRING is a collection of Points that are "strung together" into one geometric object. A LineString can be used to represent an...
Read more >
The Shapely User Manual — Shapely 2.0.0 documentation
Creates polygons from a source of lines, returning the polygons and leftover geometries. The source may be a MultiLineString, a sequence of LineString...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found