@mapbox/mapbox-gl-draw
Version:
A drawing component for Mapbox GL JS
36 lines (27 loc) • 895 B
JavaScript
import Feature from './feature.js';
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();
};
export default LineString;