@Test public void calculateCenterPoints() { ArrayList<Feature> featuresList = new ArrayList<>(); ArrayList<Point> pointsListLower1 = new ArrayList<>(); pointsListLower1.add(Point.fromLngLat(5d, 8d)); pointsListLower1.add(Point.fromLngLat(8d, 8d)); pointsListLower1.add(Point.fromLngLat(8d, 5d)); pointsListLower1.add(Point.fromLngLat(5d, 5d)); ArrayList<List<Point>> pointsListUpper1 = new ArrayList<>(); pointsListUpper1.add(pointsListLower1); featuresList.add(Feature.fromGeometry(Polygon.fromLngLats(pointsListUpper1))); featuresList.add(Feature.fromGeometry(Point.fromLngLat(9.1d, 9.1d))); featuresList.add(Feature.fromGeometry(Point.fromLngLat(11.1d, 9.1d))); featuresList.add(Feature.fromGeometry(Point.fromLngLat(11.1d, 2.1d))); featuresList.add(Feature.fromGeometry(Point.fromLngLat(9.1d, 2.1d))); FeatureCollection featureCollection = FeatureCollection.fromFeatures(featuresList); BoundaryLayer.Builder builder = new BoundaryLayer.Builder(featureCollection) .setLabelProperty("name") .setLabelTextSize(20f) .setLabelColorInt(Color.RED) .setBoundaryColor(Color.RED) .setBoundaryWidth(6f); BoundaryLayer boundaryLayer = builder.build(); FeatureCollection centerPointsFeatureCollection = ReflectionHelpers.callInstanceMethod(boundaryLayer , "calculateCenterPoints" , ReflectionHelpers.ClassParameter.from(FeatureCollection.class, featureCollection) ); List<Feature> centerPointFeatures = centerPointsFeatureCollection.features(); assertEquals(5, centerPointFeatures.size()); Point point1 = (Point) centerPointFeatures.get(0).geometry(); Point point2 = (Point) centerPointFeatures.get(1).geometry(); assertPointEquals(Point.fromLngLat(6.5d, 6.5d), point1); assertPointEquals(Point.fromLngLat(9.1d, 9.1d), point2); }
private FeatureCollection calculateCenterPoints(@NonNull FeatureCollection featureCollection) { ArrayList<Feature> centerPoints = new ArrayList<>(); List<Feature> featureList = featureCollection.features(); if (featureList != null) { for (Feature feature : featureList) { Geometry featureGeometry = feature.geometry(); if (featureGeometry != null) { Point featurePoint; if (featureGeometry instanceof Point) { featurePoint = (Point) featureGeometry; } else { featurePoint = getCenter(featureGeometry); } centerPoints.add(Feature.fromGeometry(featurePoint, feature.properties())); } } } return FeatureCollection.fromFeatures(centerPoints); }
BoundaryLayer extends KujakuLayer { private FeatureCollection calculateCenterPoints(@NonNull FeatureCollection featureCollection) { ArrayList<Feature> centerPoints = new ArrayList<>(); List<Feature> featureList = featureCollection.features(); if (featureList != null) { for (Feature feature : featureList) { Geometry featureGeometry = feature.geometry(); if (featureGeometry != null) { Point featurePoint; if (featureGeometry instanceof Point) { featurePoint = (Point) featureGeometry; } else { featurePoint = getCenter(featureGeometry); } centerPoints.add(Feature.fromGeometry(featurePoint, feature.properties())); } } } return FeatureCollection.fromFeatures(centerPoints); } }
BoundaryLayer extends KujakuLayer { private FeatureCollection calculateCenterPoints(@NonNull FeatureCollection featureCollection) { ArrayList<Feature> centerPoints = new ArrayList<>(); List<Feature> featureList = featureCollection.features(); if (featureList != null) { for (Feature feature : featureList) { Geometry featureGeometry = feature.geometry(); if (featureGeometry != null) { Point featurePoint; if (featureGeometry instanceof Point) { featurePoint = (Point) featureGeometry; } else { featurePoint = getCenter(featureGeometry); } centerPoints.add(Feature.fromGeometry(featurePoint, feature.properties())); } } } return FeatureCollection.fromFeatures(centerPoints); } BoundaryLayer(@NonNull KujakuLayer.Builder builder); }
BoundaryLayer extends KujakuLayer { private FeatureCollection calculateCenterPoints(@NonNull FeatureCollection featureCollection) { ArrayList<Feature> centerPoints = new ArrayList<>(); List<Feature> featureList = featureCollection.features(); if (featureList != null) { for (Feature feature : featureList) { Geometry featureGeometry = feature.geometry(); if (featureGeometry != null) { Point featurePoint; if (featureGeometry instanceof Point) { featurePoint = (Point) featureGeometry; } else { featurePoint = getCenter(featureGeometry); } centerPoints.add(Feature.fromGeometry(featurePoint, feature.properties())); } } } return FeatureCollection.fromFeatures(centerPoints); } BoundaryLayer(@NonNull KujakuLayer.Builder builder); void updateLineLayerProperties(@NonNull PropertyValue<?>... properties); @Override void addLayerToMap(@NonNull MapboxMap mapboxMap); @Override void enableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void disableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override @NonNull String[] getLayerIds(); @Override boolean removeLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void updateFeatures(@NonNull FeatureCollection featureCollection); @Override FeatureCollection getFeatureCollection(); }
BoundaryLayer extends KujakuLayer { private FeatureCollection calculateCenterPoints(@NonNull FeatureCollection featureCollection) { ArrayList<Feature> centerPoints = new ArrayList<>(); List<Feature> featureList = featureCollection.features(); if (featureList != null) { for (Feature feature : featureList) { Geometry featureGeometry = feature.geometry(); if (featureGeometry != null) { Point featurePoint; if (featureGeometry instanceof Point) { featurePoint = (Point) featureGeometry; } else { featurePoint = getCenter(featureGeometry); } centerPoints.add(Feature.fromGeometry(featurePoint, feature.properties())); } } } return FeatureCollection.fromFeatures(centerPoints); } BoundaryLayer(@NonNull KujakuLayer.Builder builder); void updateLineLayerProperties(@NonNull PropertyValue<?>... properties); @Override void addLayerToMap(@NonNull MapboxMap mapboxMap); @Override void enableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void disableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override @NonNull String[] getLayerIds(); @Override boolean removeLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void updateFeatures(@NonNull FeatureCollection featureCollection); @Override FeatureCollection getFeatureCollection();  }