maptalks / maptalks/maptalks.js

how to split a LineString into two LineStrings

Open
#1,908 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
HTML
Stars
4.5k
Forks
511
Avg merge
3d 58m
Merged PRs (30d)
1

Description

**maptalks's version and what browser you use?**
----

maptalks v0.37.0
Google Chrome
**Issue description**
----
I need two split a existed LineString, into Two Line Strings from where the user right clicks and choose the split option. I wonder if there is way for it. Any help would be appreciated. Thank you.
this is my function for split:
` this.splitLineString = function (coordinate, target) {
new maptalks.Marker(
coordinate,
{
'symbol': {
'markerType': 'ellipse',
'markerFill': '#ffffff',
'markerLineColor': '#e65100',
'markerLineWidth': 3,
'markerWidth': 5,
'markerHeight': 5
},
}
).addTo(draw_layer);
console.log(target)
}`
and this is the code which makes the LineString:
`if (param.geometry.type === 'LineString' && FreeLineMode === true) {

var GisSymbol = param.target.options.symbol.tag.GisSymbol;

var dg = drawTool.getCurrentGeometry();
if (dg != null) {
line = new maptalks.LineString(
dg.getCoordinates(),
{
tag: {
GisSymbolId: GisSymbol.GisSymbolId,
GisInfoGuid: guid(),
GisInfoId: null,
GisSymbolSeqNum: GisSymbol.GisSymbolSeqNum,
IsNew: true,
Element: GisSymbol,
Label: null
},
symbol: {

'lineColor': 'red',
'lineWidth': 2,
'lineJoin': 'round',
'lineCap': 'round',
//'lineDasharray': lineDasharray,
//'lineOpacity': {
// stops: [[GisSymbol.GisSymbolZoomStart, 0], [GisSymbol.GisSymbolZoomStop, 1]]
//},
'textPlacement': 'line',
'textSize': 12,
'textDy': -20,
'textFaceName': 'sans-serif',
//'textName': "" + element.ItemLength + " m",
'textWeight': 'normal',
'textStyle': 'normal',
'textFill': '#000',
//'textOpacity': { stops: [[GisSymbol.GisSymbolZoomStart, 0], [GisSymbol.GisSymbolZoomStop, 1]] },
'textHaloFill': '#fff',
//'textOpacity': { stops: [[GisSymbol.GisSymbolZoomStart, 0], [GisSymbol.GisSymbolZoomStop, 1]] },
'textWrapCharacter': '\n',
'textLineSpacing': 0,
'textHorizontalAlignment': 'middle',
'textVerticalAlignment': 'middle',
'textAlign': 'center'
},

}
);
draw_line_layer.addGeometry(line);
}

}`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the splitLineString function, the drawTool.getCurrentGeometry call, and the LineString construction shown in the issue. Review the LineString geometry APIs and determine how the right-click coordinate should divide the existing coordinates; done means producing two LineStrings at the selected location. No repository file or test is named.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.