Skip to content

Commit

Permalink
updated code for Turfjs update (inside -> booleanWithin)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanNovak committed Jun 5, 2018
1 parent a64fc64 commit 6d1bbf3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 46 deletions.
4 changes: 2 additions & 2 deletions www/app/maps/map/map-draw.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@
});
}
_.each(mappedSpots, function (spot) {
// if the spot is a point, we test using turf.inside
// if the spot is a point, we test using turf.booleanWithin
// if the spot is a polygon or line, we test using turf.intersect

var spotType = spot.geometry.type;

if (spotType === 'Point') {
// is the point inside the drawn polygon?
if (turf.inside(spot, geojsonObj)) {
if (turf.booleanWithin(spot, geojsonObj)) {
//check here whether it is on map
lassoedSpots.push(spot);
}
Expand Down
52 changes: 9 additions & 43 deletions www/app/spot/nesting/nesting-tab.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'HelpersFactory', 'SpotFactory', 'IS_WEB'];

function NestingTabController($ionicModal, $ionicPopup, $log, $rootScope, $scope, $state, FormFactory, HelpersFactory,
SpotFactory, IS_WEB) {
SpotFactory, IS_WEB) {
var vm = this;
var vmParent = $scope.vm;
vmParent.nestTab = vm;
Expand Down Expand Up @@ -46,8 +46,8 @@
vmParent.saveSpot().finally(function () {
vmParent.spotChanged = false;
loadTab({
'current': {'name': 'app.spotTab.' + thisTabName},
'params': {'spotId': args.spotId}
'current': { 'name': 'app.spotTab.' + thisTabName },
'params': { 'spotId': args.spotId }
});
});
}
Expand Down Expand Up @@ -108,23 +108,9 @@
if ((!thisSpot.properties.image_basemap && !spot.properties.image_basemap) ||
(thisSpot.properties.image_basemap && spot.properties.image_basemap &&
thisSpot.properties.image_basemap === spot.properties.image_basemap)) {
// If Spot is a point and is inside thisSpot then Spot is a child
if (_.propertyOf(spot.geometry)('type') === 'Point' &&
(_.propertyOf(thisSpot.geometry)('type') === 'Polygon' ||
_.propertyOf(thisSpot.geometry)('type') === 'MutiPolygon')) {
if (turf.inside(spot, thisSpot)) childrenSpots.push(spot);
}
// If Spot is not a point and all of its points are inside thisSpot then Spot is a child
else if (_.propertyOf(thisSpot.geometry)('type') === 'Polygon' || _.propertyOf(thisSpot.geometry)(
'type') === 'MutiPolygon') {
var points = turf.explode(spot);
if (points.features) {
var pointsInside = [];
_.each(points.features, function (point) {
if (turf.inside(point, thisSpot)) pointsInside.push(point);
});
if (points.features.length === pointsInside.length) childrenSpots.push(spot);
}
if (_.propertyOf(thisSpot.geometry)('type') && (_.propertyOf(thisSpot.geometry)('type') === 'Polygon' || _.propertyOf(thisSpot.geometry)(
'type') === 'MutiPolygon')) {
if (turf.booleanWithin(spot, thisSpot)) childrenSpots.push(spot);
}
}
});
Expand Down Expand Up @@ -159,29 +145,9 @@
if ((!thisSpot.properties.image_basemap && !spot.properties.image_basemap) ||
(thisSpot.properties.image_basemap && spot.properties.image_basemap &&
thisSpot.properties.image_basemap === spot.properties.image_basemap)) {
if (_.propertyOf(thisSpot.geometry)('type')) {
if (_.propertyOf(thisSpot.geometry)('type') === 'Point') {
// If thisSpot is a point and the point is inside a polygon Spot then that polygon Spot is a parent
if (_.propertyOf(spot.geometry)('type') === 'Polygon' || _.propertyOf(spot.geometry)(
'type') === 'MutiPolygon') {
if (turf.inside(thisSpot, spot)) parentSpots.push(spot);
}
}
else {
// If thisSpot is a line or polygon and all of its points are inside a feature then
// that feature is a parent of this Spot
var points = turf.explode(thisSpot);
if (points.features) {
if (_.propertyOf(spot.geometry)('type') === 'Polygon' || _.propertyOf(spot.geometry)(
'type') === 'MutiPolygon') {
var pointsInside = [];
_.each(points.features, function (point) {
if (turf.inside(point, spot)) pointsInside.push(point);
});
if (points.features.length === pointsInside.length) parentSpots.push(spot);
}
}
}
if (_.propertyOf(spot.geometry)('type') && (_.propertyOf(spot.geometry)('type') === 'Polygon' || _.propertyOf(spot.geometry)(
'type') === 'MutiPolygon')) {
if (turf.booleanWithin(thisSpot, spot)) parentSpots.push(spot);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion www/app/spot/spot/spot.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
// Buffer the polygon so Spots are included within the polygon, not just as vertices
if (!_.has(activeNest[0].properties, 'image_basemap')) {
var unit = 'meters';
newSpot = turf.buffer(newSpot, 5, unit);
newSpot = turf.buffer(newSpot, 5, {'units': 'meters'});
}
else {
// Need to JSTS to buffer if pixel geometry
Expand Down

0 comments on commit 6d1bbf3

Please sign in to comment.