LocationIndexOfLine.js 1019 B

1234567891011121314151617181920212223242526272829
  1. import LocationIndexOfPoint from './LocationIndexOfPoint'
  2. export default class LocationIndexOfLine {
  3. constructor() {
  4. LocationIndexOfLine.constructor_.apply(this, arguments)
  5. }
  6. static constructor_() {
  7. this._linearGeom = null
  8. const linearGeom = arguments[0]
  9. this._linearGeom = linearGeom
  10. }
  11. static indicesOf(linearGeom, subLine) {
  12. const locater = new LocationIndexOfLine(linearGeom)
  13. return locater.indicesOf(subLine)
  14. }
  15. indicesOf(subLine) {
  16. const startPt = subLine.getGeometryN(0).getCoordinateN(0)
  17. const lastLine = subLine.getGeometryN(subLine.getNumGeometries() - 1)
  18. const endPt = lastLine.getCoordinateN(lastLine.getNumPoints() - 1)
  19. const locPt = new LocationIndexOfPoint(this._linearGeom)
  20. const subLineLoc = new Array(2).fill(null)
  21. subLineLoc[0] = locPt.indexOf(startPt)
  22. if (subLine.getLength() === 0.0)
  23. subLineLoc[1] = subLineLoc[0].copy()
  24. else
  25. subLineLoc[1] = locPt.indexOfAfter(endPt, subLineLoc[0])
  26. return subLineLoc
  27. }
  28. }