I use a single layer. This is the place where the layer is created: Code: //Start new trackline here //Create fresh temp line array vLineArray = []; //Write first coordinate of new track segment to line array vLineArray.push(coordinate); //Save that to global array vTrackLinePoints = vLineArray; sTrackLine = "lineTrack" + iPausePositionsIndex.toString(); //We have to create a track line here. map.addSourceLine(sTrackLine, vTrackLinePoints) map.addLayer("layerTrack" + iPausePositionsIndex.toString(), { "type": "line", "source": sTrackLine }) map.setLayoutProperty("layerTrack" + iPausePositionsIndex.toString(), "line-join", "round"); map.setLayoutProperty("layerTrack" + iPausePositionsIndex.toString(), "line-cap", "round"); map.setPaintProperty("layerTrack" + iPausePositionsIndex.toString(), "line-color", "red"); map.setPaintProperty("layerTrack" + iPausePositionsIndex.toString(), "line-width", 2.0); Then every new coordinate is pushed to the array vTrackLinePoints. And then I use Code: updateSourceLine to redraw the track line: Code: //Create temp line array and set current points array to it. Must use a JS array here necause QML arrays don't allow for push! vLineArray = vTrackLinePoints; //Write first coordinate to line array vLineArray.push(coordinate); //Save that to global array vTrackLinePoints = vLineArray; map.updateSourceLine(sTrackLine, vTrackLinePoints);
//Start new trackline here //Create fresh temp line array vLineArray = []; //Write first coordinate of new track segment to line array vLineArray.push(coordinate); //Save that to global array vTrackLinePoints = vLineArray; sTrackLine = "lineTrack" + iPausePositionsIndex.toString(); //We have to create a track line here. map.addSourceLine(sTrackLine, vTrackLinePoints) map.addLayer("layerTrack" + iPausePositionsIndex.toString(), { "type": "line", "source": sTrackLine }) map.setLayoutProperty("layerTrack" + iPausePositionsIndex.toString(), "line-join", "round"); map.setLayoutProperty("layerTrack" + iPausePositionsIndex.toString(), "line-cap", "round"); map.setPaintProperty("layerTrack" + iPausePositionsIndex.toString(), "line-color", "red"); map.setPaintProperty("layerTrack" + iPausePositionsIndex.toString(), "line-width", 2.0);
updateSourceLine
//Create temp line array and set current points array to it. Must use a JS array here necause QML arrays don't allow for push! vLineArray = vTrackLinePoints; //Write first coordinate to line array vLineArray.push(coordinate); //Save that to global array vTrackLinePoints = vLineArray; map.updateSourceLine(sTrackLine, vTrackLinePoints);