-
Notifications
You must be signed in to change notification settings - Fork 13
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
Drawing boundaries feature #306
Conversation
- Add MapBox annotations plugins - Drawing Manager encapsulating the Circle/Line/Fill Manager - Smart listeners
Refactor KujakuLayer TODO : - Include KujakuLayer OnClick & OnLongClick in the drawing Manager - Add Unit tests
Refactor DrawingManager and KujakuMapview to encapsulate APIs
Update the Manifest.xml
Fix build sample app
Create ShadowCircleLayer class
Isolate KujakuLayer private function from KujakuMapView class
…henPassedFalse' fails now (not locally)
buildToolsVersion = "28.0.3" | ||
compileSdkVersion = 27 | ||
compileSdkVersion = 28 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test to make sure the app does not break due to https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p and https://developer.android.com/about/versions/pie/android-9.0-changes-28#tls-enabled?
You can also confirm this on the code.
Confirm and test the following also:
- https://developer.android.com/about/versions/pie/android-9.0-changes-all#fant-required Which affects the activity that is started by the
TrackingService
from the background
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm that everything is working fine
|
||
Feature feature = Feature.fromGeometry(polygon); | ||
FeatureCollection collection = FeatureCollection.fromFeature(feature); | ||
FillBoundaryLayer layer = new FillBoundaryLayer.Builder(collection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So can we reuse the same FillBoundaryLayer
. Seems that this creates multiple FillBoundaryLayers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure, we can create one if it is a new draw, and update the existing one if it is an edition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
kujakuMapView.addLayer(layer); | ||
} | ||
this.currentLayer = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is still evident on the updated code. I am guessing it's because of nullifying this layer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what issue is still present ? If we use the drawing mamanger by clicking the start drawing button, we want to draw a new Layer. That is why we create a new one here.
Please advise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the aim of the method, then it's OK
@Override | ||
public void onClick(View view) { | ||
// start Drawing from scratch | ||
if (! drawingManager.isDrawingEnabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for null drawingManager
in case the map was openned without internet connection. The style will not load and the DrawingManager
will not be created
@Override | ||
public void onCircleClick(@NonNull Circle circle) { | ||
Toast.makeText(DrawingBoundariesActivity.this, | ||
String.format("Circle clicked"),Toast.LENGTH_SHORT).show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this call to String.format
and add the strings to strings.xml
@Override | ||
public void onCircleNotClick(@NonNull LatLng latLng) { | ||
Toast.makeText(DrawingBoundariesActivity.this, | ||
String.format("Circle NOT clicked"),Toast.LENGTH_SHORT).show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this call to String.format
and add the strings to strings.xml
@Override | ||
public void onCircleLongClick(@NonNull Circle circle) { | ||
Toast.makeText(DrawingBoundariesActivity.this, | ||
String.format("Circle long clicked"),Toast.LENGTH_SHORT).show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this call to String.format
and add the strings to strings.xml
@Override | ||
public void onCircleNotLongClick(@NonNull LatLng point) { | ||
Toast.makeText(DrawingBoundariesActivity.this, | ||
String.format("Circle NOT long clicked"),Toast.LENGTH_SHORT).show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this call to String.format
and add the strings to strings.xml
@@ -817,6 +702,9 @@ protected VisibleRegion getCurrentBounds() { | |||
private void enableFeatureClickListenerEmitter(@NonNull MapboxMap mapboxMap) { | |||
mapboxMap.removeOnMapClickListener(this); | |||
mapboxMap.addOnMapClickListener(this); | |||
|
|||
mapboxMap.removeOnMapLongClickListener(this); | |||
mapboxMap.addOnMapLongClickListener(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why the remove
and add
ClickListener
follow one another. Do you have an idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure too i took the example with the removeOnMapClickListener above
return true; | ||
} | ||
|
||
Geometry geometry = kujakuLayer.getFeatureCollection().features().get(0).geometry(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can add a check to make sure features()
is not null. The IDE is complaining that there might be an NPE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
features()
has been annotated as returning a nullable
value. So calling get(0)
on a null will introduce an NPE. Check that features is not null and reuse the validated variable to get feature at index 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see above, I check if features is not null and if the size >= 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, then the IDE has not way of figuring that out since you did not use store it in a variable and use the null-checked
variable. This is OK
* @param kujakuLayer | ||
* @return | ||
*/ | ||
public boolean startDrawingKujakuLayer(@Nullable KujakuLayer kujakuLayer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should the general KujakuLayer
specifically?
Is this supposed to work with all KujakuLayer
s or BoundaryLayer
or FillBoundaryLayer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, Do you want to restrict to FillBoundaryLayers only ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should restrict the drawing, right? I am not sure what it is supposed to work with but we also have BaseLayer
which is a KujakuLayer
. That layer basically has raster. I guess some KujakuLayers might not have feature collections and would return null
when getFeatureCollection
is called. Probably restrict it to what you would want it to be used on. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i agree. I will update the code to restrict to the FillBoundaryLayer only
} | ||
} | ||
|
||
circleManager.update(circle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that you update the circle here. Should you also update the previousCircle
and nextCircle
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the next and previous circle are deleted if they are not null above
return true; | ||
} | ||
|
||
Geometry geometry = kujakuLayer.getFeatureCollection().features().get(0).geometry(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
features()
has been annotated as returning a nullable
value. So calling get(0)
on a null will introduce an NPE. Check that features is not null and reuse the validated variable to get feature at index 0
* @param kujakuLayer | ||
* @return | ||
*/ | ||
public boolean startDrawingKujakuLayer(@Nullable KujakuLayer kujakuLayer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should restrict the drawing, right? I am not sure what it is supposed to work with but we also have BaseLayer
which is a KujakuLayer
. That layer basically has raster. I guess some KujakuLayers might not have feature collections and would return null
when getFeatureCollection
is called. Probably restrict it to what you would want it to be used on. What do you think?
Rename startDrawingKujakuLayer to startDrawing that return the Polygon
No description provided.