all files / mapbox-gl-draw/src/feature_types/ line_string.js

100% Statements 21/21
100% Branches 0/0
100% Functions 6/6
100% Lines 21/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36   72×       17×         16× 16×     17× 17×     97× 97× 97×      
const Feature = require('./feature');
 
const LineString = function(ctx, geojson) {
  Feature.call(this, ctx, geojson);
};
 
LineString.prototype = Object.create(Feature.prototype);
 
LineString.prototype.isValid = function() {
  return this.coordinates.length > 1;
};
 
LineString.prototype.addCoordinate = function(path, lng, lat) {
  this.changed();
  const id = parseInt(path, 10);
  this.coordinates.splice(id, 0, [lng, lat]);
};
 
LineString.prototype.getCoordinate = function(path) {
  const id = parseInt(path, 10);
  return JSON.parse(JSON.stringify(this.coordinates[id]));
};
 
LineString.prototype.removeCoordinate = function(path) {
  this.changed();
  this.coordinates.splice(parseInt(path, 10), 1);
};
 
LineString.prototype.updateCoordinate = function(path, lng, lat) {
  const id = parseInt(path, 10);
  this.coordinates[id] = [lng, lat];
  this.changed();
};
 
module.exports = LineString;