-
Notifications
You must be signed in to change notification settings - Fork 493
Conversation
00d4e45
to
2ba6642
Compare
2ba6642
to
b8c4dcb
Compare
a503651
to
edfe74c
Compare
edfe74c
to
bc5151a
Compare
@Override | ||
public void onStyleLoaded(@NonNull final Style style) { | ||
VariableLabelPlacementActivity.this.mapboxMap = mapboxMap; | ||
new LoadGeoJson(style,VariableLabelPlacementActivity.this).execute(); |
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.
We are currently trying to load a local geojson file and aren't manipulating its contet. We can remove a lot of this boilerplate code if we rely on the loading map resources through assets. Us asset://poi_places.geojson
as url for the second parameter of the geojsonsource constructor.
The json loader can be removed and the whole asynctask setup
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.
Got rid of the AsyncTask
and onDataLoaded()
.
Doing this didn't work for me (lol):
So, I used the loadJsonFromAsset()
method that's used in some other examples:
Line 71 in fff1abe
loadJsonFromAsset("poi_places.geojson"))) |
Lines 95 to 109 in fff1abe
private String loadJsonFromAsset(String filename) { | |
// Using this method to load in GeoJSON files from the assets folder. | |
try { | |
InputStream is = getAssets().open(filename); | |
int size = is.available(); | |
byte[] buffer = new byte[size]; | |
is.read(buffer); | |
is.close(); | |
return new String(buffer, "UTF-8"); | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
return null; | |
} | |
} |
Example's working the same as seen in the GIF in OP.
Did I misinterpret your instructions? Is there some even smoother way to pull from the assets folder?
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.
My bad, didn't double check the constructors. The issue with this setup is that you are trying to load that URI as an geojson string.
I tried using the URL constructor but that failed as that URI is not a valid URL.
-> mapbox/mapbox-gl-native#14743
Was able to make it work as:
source = new GeoJsonSource(MARKER_SOURCE);
source.setUrl("asset://something.geojson");
fff1abe
to
069f587
Compare
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.
nit to remove an unused class, looks good otherwise
* T data that is loaded | ||
* @param <T> data to be loaded | ||
*/ | ||
public class JsonLoader<T> extends AsyncTask<Void, Void, T> { |
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.
class can be removed
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.
that issue is mapbox/mapbox-gl-native#14715, feel free to ignore this bug
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.
Awesome 🚀
fbf37b8
to
b479a5d
Compare
This PR adds an example of variable label placement using PropertyFactory.textVariableAnchor().
The renderer attempts placing the label at the positions in this list in the provided order of the array at collision detection time. If the symbol was successfully placed in a previous round, the renderer attempts that anchor position first before moving on to the rest of the list.
In this example the following values were used: