Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change requirements paths #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/modes/CircleMode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const MapboxDraw = require('@mapbox/mapbox-gl-draw');
const MapboxDraw = require('@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw');
const Constants = require('@mapbox/mapbox-gl-draw/src/constants');
const doubleClickZoom = require('@mapbox/mapbox-gl-draw/src/lib/double_click_zoom');
const doubleClickZoom = require('@mapbox/mapbox-gl-draw/src/lib/double_click_zoom').default;
const circle = require('@turf/circle').default;

const CircleMode = {...MapboxDraw.modes.draw_polygon};
Expand All @@ -15,7 +15,7 @@ CircleMode.onSetup = function(opts) {
},
geometry: {
type: Constants.geojsonTypes.POLYGON,
coordinates: [[]]
coordinates: []
}
});

Expand Down Expand Up @@ -48,4 +48,4 @@ CircleMode.clickAnywhere = function(state, e) {
return this.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [state.polygon.id] });
};

module.exports = CircleMode;
module.exports = CircleMode;
24 changes: 12 additions & 12 deletions lib/modes/DirectModeOverride.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const DirectModeOverride = MapboxDraw.modes.direct_select;
DirectModeOverride.dragFeature = function(state, e, delta) {
moveFeatures(this.getSelected(), delta);
this.getSelected()
.filter(feature => feature.properties.isCircle)
.map(circle => circle.properties.center)
.forEach(center => {
center[0] += delta.lng;
center[1] += delta.lat;
});
.filter(feature => feature.properties.isCircle)
.map(circle => circle.properties.center)
.forEach(center => {
center[0] += delta.lng;
center[1] += delta.lat;
});
state.dragMoveLocation = e.lngLat;
};

Expand Down Expand Up @@ -55,11 +55,11 @@ DirectModeOverride.toDisplayFeatures = function (state, geojson, push) {
geojson.properties.active = Constants.activeStates.ACTIVE;
push(geojson);
const supplementaryPoints = geojson.properties.user_isCircle ? createSupplementaryPointsForCircle(geojson)
: createSupplementaryPoints(geojson, {
map: this.map,
midpoints: true,
selectedPaths: state.selectedCoordPaths
});
: createSupplementaryPoints(geojson, {
map: this.map,
midpoints: true,
selectedPaths: state.selectedCoordPaths
});
supplementaryPoints.forEach(push);
} else {
geojson.properties.active = Constants.activeStates.INACTIVE;
Expand All @@ -69,4 +69,4 @@ DirectModeOverride.toDisplayFeatures = function (state, geojson, push) {

}

module.exports = DirectModeOverride;
module.exports = DirectModeOverride;
12 changes: 6 additions & 6 deletions lib/modes/DragCircleMode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const MapboxDraw = require('@mapbox/mapbox-gl-draw');
const Constants = require('@mapbox/mapbox-gl-draw/src/constants');
const doubleClickZoom = require('@mapbox/mapbox-gl-draw/src/lib/double_click_zoom');
const doubleClickZoom = require('@mapbox/mapbox-gl-draw/src/lib/double_click_zoom').default;
const dragPan = require('../utils/drag_pan');
const circle = require('@turf/circle').default;
const distance = require('@turf/distance').default;
Expand All @@ -17,7 +17,7 @@ DragCircleMode.onSetup = function(opts) {
},
geometry: {
type: Constants.geojsonTypes.POLYGON,
coordinates: [[]]
coordinates: []
}
});

Expand Down Expand Up @@ -49,9 +49,9 @@ DragCircleMode.onDrag = DragCircleMode.onMouseMove = function (state, e) {
const center = state.polygon.properties.center;
if (center.length > 0) {
const distanceInKm = distance(
turfHelpers.point(center),
turfHelpers.point([e.lngLat.lng, e.lngLat.lat]),
{ units : 'kilometers'});
turfHelpers.point(center),
turfHelpers.point([e.lngLat.lng, e.lngLat.lat]),
{ units : 'kilometers'});
const circleFeature = circle(center, distanceInKm);
state.polygon.incomingCoords(circleFeature.geometry.coordinates);
state.polygon.properties.radiusInKm = distanceInKm;
Expand All @@ -74,4 +74,4 @@ DragCircleMode.toDisplayFeatures = function(state, geojson, display) {
return display(geojson);
};

module.exports = DragCircleMode;
module.exports = DragCircleMode;
52 changes: 26 additions & 26 deletions lib/modes/SimpleSelectModeOverride.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
const MapboxDraw = require('@mapbox/mapbox-gl-draw');
const createSupplementaryPoints = require('@mapbox/mapbox-gl-draw/src/lib/create_supplementary_points');
const moveFeatures = require('@mapbox/mapbox-gl-draw/src/lib/move_features');
const moveFeatures = require('@mapbox/mapbox-gl-draw/src/lib/move_features').default;
const Constants = require('@mapbox/mapbox-gl-draw/src/constants');
const createSupplementaryPointsForCircle = require('../utils/create_supplementary_points_circle');


const SimpleSelectModeOverride = MapboxDraw.modes.simple_select;

SimpleSelectModeOverride.dragMove = function(state, e) {
// Dragging when drag move is enabled
state.dragMoving = true;
e.originalEvent.stopPropagation();

const delta = {
lng: e.lngLat.lng - state.dragMoveLocation.lng,
lat: e.lngLat.lat - state.dragMoveLocation.lat
};

moveFeatures(this.getSelected(), delta);

this.getSelected()
.filter(feature => feature.properties.isCircle)
.map(circle => circle.properties.center)
.forEach(center => {
center[0] += delta.lng;
center[1] += delta.lat;
});

state.dragMoveLocation = e.lngLat;
// Dragging when drag move is enabled
state.dragMoving = true;
e.originalEvent.stopPropagation();

const delta = {
lng: e.lngLat.lng - state.dragMoveLocation.lng,
lat: e.lngLat.lat - state.dragMoveLocation.lat
};

moveFeatures(this.getSelected(), delta);

this.getSelected()
.filter(feature => feature.properties.isCircle)
.map(circle => circle.properties.center)
.forEach(center => {
center[0] += delta.lng;
center[1] += delta.lat;
});

state.dragMoveLocation = e.lngLat;
};

SimpleSelectModeOverride.toDisplayFeatures = function(state, geojson, display) {
geojson.properties.active = (this.isSelected(geojson.properties.id)) ?
Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
display(geojson);
this.fireActionable();
if (geojson.properties.active !== Constants.activeStates.ACTIVE ||
geojson.geometry.type === Constants.geojsonTypes.POINT) return;
geojson.geometry.type === Constants.geojsonTypes.POINT) return;
const supplementaryPoints = geojson.properties.user_isCircle ?
createSupplementaryPointsForCircle(geojson) : createSupplementaryPoints(geojson);
createSupplementaryPointsForCircle(geojson) : createSupplementaryPoints(geojson);
supplementaryPoints.forEach(display);
};
module.exports = SimpleSelectModeOverride;

module.exports = SimpleSelectModeOverride;
4 changes: 2 additions & 2 deletions lib/utils/create_supplementary_points_circle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const createVertex = require('@mapbox/mapbox-gl-draw/src/lib/create_vertex');
const createVertex = require('@mapbox/mapbox-gl-draw/src/lib/create_vertex').default;

function createSupplementaryPointsForCircle(geojson) {
const { properties, geometry } = geojson;
Expand All @@ -13,4 +13,4 @@ function createSupplementaryPointsForCircle(geojson) {
return supplementaryPoints;
}

module.exports = createSupplementaryPointsForCircle;
module.exports = createSupplementaryPointsForCircle;