Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Variable label placement example #1066

Merged
merged 1 commit into from
May 24, 2019
Merged

Variable label placement example #1066

merged 1 commit into from
May 24, 2019

Conversation

osana
Copy link
Contributor

@osana osana commented May 15, 2019

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:

textVariableAnchor: ["top", "bottom", "left", "right"],
textRadialOffse: 0.5
textJustify: auto

ezgif com-optimize

@osana osana requested review from langsmith and chloekraw May 15, 2019 22:17
@osana osana force-pushed the osana-variable-length branch 2 times, most recently from 00d4e45 to 2ba6642 Compare May 15, 2019 22:35
@langsmith langsmith force-pushed the osana-variable-length branch from 2ba6642 to b8c4dcb Compare May 20, 2019 18:09
@langsmith langsmith force-pushed the osana-variable-length branch 4 times, most recently from a503651 to edfe74c Compare May 21, 2019 19:25
@langsmith langsmith requested review from tobrun and LukasPaczos and removed request for chloekraw and langsmith May 21, 2019 19:55
@langsmith langsmith force-pushed the osana-variable-length branch from edfe74c to bc5151a Compare May 21, 2019 20:22
@langsmith langsmith self-assigned this May 21, 2019
@Override
public void onStyleLoaded(@NonNull final Style style) {
VariableLabelPlacementActivity.this.mapboxMap = mapboxMap;
new LoadGeoJson(style,VariableLabelPlacementActivity.this).execute();
Copy link
Member

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

Copy link
Contributor

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):
Screen Shot 2019-05-22 at 4 51 53 PM

So, I used the loadJsonFromAsset() method that's used in some other examples:


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?

Copy link
Member

@tobrun tobrun May 23, 2019

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");

@langsmith langsmith force-pushed the osana-variable-length branch from fff1abe to 069f587 Compare May 22, 2019 23:57
Copy link
Member

@tobrun tobrun left a 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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class can be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, keep forgetting to delete that damn unused class. Still seeing weird behavior, so it's still WIP

ezgif com-resize (1)

Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🚀

@langsmith langsmith force-pushed the osana-variable-length branch from fbf37b8 to b479a5d Compare May 23, 2019 19:50
@langsmith langsmith merged commit 4e484b0 into master May 24, 2019
@langsmith langsmith deleted the osana-variable-length branch May 24, 2019 00:50
@langsmith langsmith mentioned this pull request Jun 13, 2019
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants