Changing SymbolLayer properties on click when using a VectorSource - android

I've been following this guide provided by Mapbox to familiarize myself with SymbolLayers and how to manipulate their properties on the map.
https://blog.mapbox.com/a-guide-to-the-android-symbollayer-api-5daac7b66f2c
The key step I'm having issues with is Step 5 where they update the iconSize property onMapClick. After they add a property to the selected Feature, the guide says to call source.setGeoJson(featureCollection); in order to reset the source of the layer.
The project I'm working with uses a VectorSource as the source of data for the SampleLayer, not a GeoJsonSource like the example uses. The problem is that VectorSource doesn't provide a method like setGeoJson so I'm not able to reset the layer source after I change the property.
What can I do to work around this without having to change all of our source data?
for (Feature feature : featureCollection.getFeatures() {
if (feature.getStringProperty("title").equals(selectedFeature.getStringProperty("title"))) {
feature.getProperties().addProperty("selected", true);
}
}
source.setGeoJson(featureCollection);
The full source of that example can be found here: https://github.com/mapbox/mapbox-android-demo/blob/286f33d848c9fea48de908b144682081961b986b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/SymbolLayerMapillaryActivity.java

For anyone coming across this issue in the future, the only possible approach here would be to remove and add layer again, with the updated source. This is however an ineffective solution, so it would really be better for you to use GeoJson source instead.

Related

Switch GeoJsonSource data in MapBox

I want to replace the data behind an existing source. This is trivial in javascript:
map.getSource('trace').setData(data);
See https://docs.mapbox.com/mapbox-gl-js/example/live-update-feature/
That method does not exist in Android. Once I have set a value, I can't replace it (nothing changes if I do):
GeoJsonSource mySource;
mySource.setGeoJson("some json data");
To delete and readd the source, I'd have to remove the layer using the source first: https://github.com/mapbox/mapbox-gl-native/issues/12526
Since I'm getting a fully functioning Style object from the server, removing, recreating and readding the layer/source at the correct position is tedious to say the least.
Above code actually works, but to reset my layer I used:
mySource.setGeoJson("");
Setting the source to empty String breaks something. Afterwards the GeoJson can not be set to something meaningful again. So to reset data, I'll have to use the visibility attribute of a layer. Replacing meaningful GeoJson with meaningful GeoJson works just fine.
The setGeoJson methods work correctly with any valid Geometry to add data (e.g. Point, MultiPoint).
Then, to clear or initialize the source without "breaking" the layer you can use:
mySource.setGeoJson(FeatureCollection.fromFeatures(new ArrayList<Feature>()));

How to filter markers in Mapbox Sdk

I'm creating an Android app using MapBox. I've already set up a simple map functionality with markers sourced from .json file. Next step is filtering the markers on the map, just like in this gl-js example here:
https://docs.mapbox.com/mapbox-gl-js/example/filter-markers/
I can't find any sdk examples anywhere, and since this is my first app I really can't figure it out on my own. Any help will be appreciated.
You can check out this example https://docs.mapbox.com/android/maps/examples/multiple-expressions-temperature-change/ that features two layers that fetch a min or max temperature from the data source and display it.
The filtering part is done here:
// Only display Maximum Temperature in this layer
maxTempLayer.setFilter(eq(get("element"), literal("All-Time Maximum Temperature")));
loadedMapStyle.addLayer(maxTempLayer);
Filters accept expressions as arguments, and here Expression.eq is used to compare "element" from the GeoJSON data source (referenced with the Expression.get) with the "All-Time Maximum Temperature" value. If it resolves to true, the feature is going to be displayed, otherwise, it's going to be hidden.

Android ArCore Sceneform API. How to change textures in runtime?

The server has more than 3000 models and each of them has several colors of material. I need to load separately models and textures and set textures depending on the user's choice. How to change baseColorMap, normalMap, metallicMap, roughnessMap in runtime?
after
modelRenderable.getMaterial().setTexture("normalMap", normalMap.get());
nothing happens
I'm doing something wrong. There is no information in documentation for that.
thank you for posting this question.
setTexture() appears to not work: Unfortunately this part of our API is still a little rough; it works but is very easy to get wrong. We're working on a sample to illustrate how to modify material parameters (including textures) at runtime and will improve our error reporting in the next release.
Thousands of models w/ multiple permutations how?: The plan here has two parts:
The binaries used by the Android Studio plugin will be made available for use in build scripts on server platforms. This will allow you to do a server-side conversion of your assets to .sfb. We'll be releasing a blog post soon on how to do this.
The .sfa will get the ability to contain loose textures and materials not explicitly associated with geometry, and .sfa's will be able to declare data dependencies on other .sfa's. This will mean that you can author (and deliver) .sfb's that contain textures/materials (but no geometry) and .sfb's that contain geometry (but no textures/materials), and if they're both available at instantiation time it will just work.
use this code`
CompletableFuture<Texture> futureTexture = Texture.builder()
.setSource(this, R.drawable.shoes)
.build();
and replace with
/*.thenAccept(renderable -> andyRenderable = renderable)*/
.thenAcceptBoth(futureTexture, (renderable, texture) -> {
andyRenderable = renderable;
andyRenderable.getMaterial().setTexture("baseColor", texture);
})
would work.

How to set chart parameter in YouTube Data API v3( JAVA / Android)

Hi here is my code to get videos list.
YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet, contentDetails");
listVideosRequest.setKey(apiKey);
I am not able to find a way to set chart parameter( one of the Filter option ). Actually i wanna retrieve videos list of Most popular in my region. Thanks in advance
Try like this.
First check whether you included proper lib or not in your project. Because some times it may not show all methods. for updated library click here.
Once you have updated library then
YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet, contentDetails");
listVideosRequest.setChart("mostPopular");
listVideosRequest.setKey(apiKey);

Need bump map example for libgdx

I'm trying to figure out how to use a bump map. I can add one to a model but nothing happens, probably need to turn on some config option. Please point me to a working example.
I only got this far:
matPlaceholder = new Material(ColorAttribute.createDiffuse(com.badlogic.gdx.graphics.Color.RED), new TextureAttribute(TextureAttribute.Bump, texBump);
You can add it, but the default shader doesn't do Bump Mapping yet.
There are plans of having a composite shader that does that and more. But as far as I know, it isn't ready. You need to write your own shader for that.
There is some good shaders here. Like Normal Mapping. You can give them a try.

Categories

Resources