So currently I am making two symbol layers and GeoJsonSource for two types of symbol in my code - one set of symbols are active and another set is inactive symbols. I am doing this because I have two sets of symbols, therefore, I have made two GeoJsonSource.
val source_Active = GeoJsonSource("GeoJsonSourceActive", FeatureCollection.fromFeatures(listoflnglat_active),GeoJsonOptions().withCluster(true).withClusterMaxZoom(16).withClusterRadius(40))
val source_Passive = GeoJsonSource("GeoJsonSourcePassive", FeatureCollection.fromFeatures(listoflnglat_passive),GeoJsonOptions().withCluster(true).withClusterMaxZoom(16).withClusterRadius(40))
style.addSource(source_Active)
style.addSource(source_Passive)
val symbolLayerActive = SymbolLayer("Active","GeoJsonSourceActive")
val symbolLayerPassive = SymbolLayer("Passive","GeoJsonSourcePassive")
symbolLayerActive.withProperties(PropertyFactory.iconImage("marker-icon-active"))
symbolLayerPassive.withProperties(PropertyFactory.iconImage("marker-icon-passive"))
style.addLayer(symbolLayerActive)
style.addLayer(symbolLayerPassive)
Can I do it in a single layer because I want to perform clustering and I want that all icons cluster into one single icon after a certain level of zoom out
Related
I have a json animation that I'm using with LottieAnimation, but my feature needs that I change a text and an image inside the animation in runtime.
The animation is a ranking like a podium. Then animated winner text and image are loaded from the backend. So I need to set these values.
Right now I know that TextDelegate can handle the Text problem, but it only works with View, as the old way to do it. It needs the View in constructor. I don't find a way to do this with Compose. And about the image, I have no glues.
Can someone help me?
Depending on your json file structure, you have two ways of settings an image
Place used images inside src/main/assets/lottieImages. Names should be the same as mentioned in your json file, in my case it's img_0.png.
val composition by rememberLottieComposition(
LottieCompositionSpec.RawRes(R.raw.we_accept),
imageAssetsFolder = "lottieImages"
)
Set a bitmap to key path, like I'm taking it from the resources, using dynamic properties
val bitmap = remember {
BitmapFactory.decodeResource(context.resources, R.drawable.my_image)
}
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.IMAGE, bitmap, "weaccept.jpg"),
)
LottieAnimation(
composition,
dynamicProperties = dynamicProperties
)
I'm using this json as a sample animation.
As for the text, Lottie TextDelegate does not seem to be ported to compose, I suggest you create a feature request on github.
for my app i read in multiple values from Bluetooth connected sensors. One fragment allows you to edit the sensors and another fragment shows all values in a tableView.
On a third settings fragment, i want to be able to change the decimal places the values on all fragments appear.
i know to change the decimal format i use the following code.
var form = DecimalFormat("#,###.##") // number format
and to add this format to the values do the following
form.format(temperature)
currently i have a radio group, with each radio button set to change the how many decimal places in the variable form.
how do i make this change appear across all fragments not just the setting fragments? will i need a shared view model?
Shared ViewModel is good fit for this problem, simply create a ViewModel with form property and in every fragment get an instance of ViewModel associated with activity as
private val viewModel: SharedViewModel by activityViewModels()
Now you can update the form property on radio change as
radioGroup.setOnCheckedChangeListener { group, checkedId ->
val format = when(checkedId){
R.id.radio_two -> TWO_DECIMAL_PLACES
R.id.radio_three -> THREE_DECIMAL_PLACES
else -> DEFAULT_FORMAT
}
viewModel.form = DecimalFormat(format)
}
After this simply use value of this property before showing data
I was reading the documentation for polygons and polylines
What is not clear to me is how could I keep a state associated with a polygon?
E.g. if I want to do an action on click that depends on whether the polygon was already clicked on or not how could I know that?
Could I use e.g. tag to add arbitrary info including if the polygon is in click/state?
you can use setTag() with custom object which include click state and other data like
CustomDefinedObject data = new CustomDefinedObject ();// your defined object
data.isClicked=true
data.otherProperty=false
polyline.setTag(data);
and to retrieve info
CustomDefinedObject retrievedData = (CustomDefinedObject)polyline.getTag(data);
I'm using the SymbolManager to display two symbols on the map. Here is an example:
The dark symbol is because of the fact that I'm testing the project on the Emulator, but the Line goes under the symbol, as it should be. The problem comes with the other symbol (finish flag). After I'm ready with the drawing of the line, the following code block is called:
symbolManager = new SymbolManager(mapView,mMapboxMap,style);
symbolManager.setIconAllowOverlap(true);
symbolManager.setIconIgnorePlacement(true);
SymbolOptions symbolOptionsFinishFlag = new SymbolOptions()
.withIconImage(IMAGE_FINISH_FLAG)
.withIconSize(2.0f)
.withLatLng(newLatLngs.get(newLatLngs.size()-1));
symbolManager.create(symbolOptionsFinishFlag);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.includes(newLatLngs);
LatLngBounds bounds = builder.build();
final CameraUpdate cu = new CameraUpdateFactory().newLatLngBounds(bounds,300);
mMapboxMap.easeCamera(cu,5000);
I checked some examples in the Mapbox site and it seems to be correct. However, the Symbol is under the Line, how can I bring on top of it?
If you are using a LineLayer, when adding it to the map use style.addLayerBelow(lineLayer, symbolManager.layerId)
This answer is about how to do this in Mapbox SDK v9. All AnnotationManager subclasses have a constructor which allows you to mention which layerId this should be below.
For example, in LineManager, we have this constructor
LineManager(MapView mapView, MapboxMap mapboxMap, Style style, java.lang.String belowLayerId)
Another method which will be needed here is the getLayerId method in the AnnotationManager class which returns the id used by a certain layer.
getLayerId
public java.lang.String getLayerId()
Returns a layer ID that annotations created by this manager are laid out on. This reference can be used together with Style#addLayerAbove(Layer, String) or Style#addLayerBelow(Layer, String) to improve other layers positioning in relation to this manager.
Returns:
underlying layer's ID
So say there are 3 elements on the map, a circle, a line and a symbol and we need to show the circle at the bottom, then the line above and finally the symbol at the top most.
So we will create our AnnotationManagers in this way -
val symbolManager = SymbolManager(mapView, map, map.style!!)
val lineManager = LineManager(mapView, map, map.style!!, symbolManager.layerId)
val fillManager = FillManager(mapView, map, map.style!!, lineManager.layerId)
What we're doing here is that while creating the lineManager object, we pass the layerId of the symbolManager which ensures that the Lines created using LineManager are always below the Symbols created using the SymbolManager. And the same for FillManager being below the lineManager object.
Although SymbolManagers can be useful means for providing an abstraction over the methods needed to add symbols to a map, you may get some more flexibility by working with native SymbolLayers directly. This example shows how to add symbol layer icons to a map, and this example shows how to specify layer ordering when new layers are added. So, by adding two symbol layers for your start and finish icons, and a line layer for the line between them, you could use style.addLayerBelow(finishFlagLayer, "name_of_line_layer").
I've been searching for an answer for this but since i couldn't find any, i'll post the question.
I have a plot drawn, with a list below showing some data, one of the parameters of each row is drawn in the plot.
I'm trying to change the color of the point when the user clicks in one of the views of the list, to reflect in the plot that the row matches the point, but i haven't been able to replicate it.
There is any way to get an specific point of the graph, to change its color?
Thanks in advance.
I don't know if what you are trying to do is possible but you can try to add a serie to your plot containing the point that you want to highlight when user clicks. When a new click is done you just need to remove the added serie and add a new one containing the new point.
The added serie must have a different style so you can see the "changed color" and must be the last added serie so it will be in forground.
Hope it helps
Edit
What you can do to adapt it to your use case is to extend a XYPlot class, create a SeriesType highlightedPoint property and add a method like (not tested) :
public void highlightPoint(Number x, Number y, FormatterType formatter){
// if there is already a highlighted point we remove it (we want to highlight just one point)
if(highlightedPoint != null) {
removeSeries(highlightedPoint);
highlightedPoint = null;
}
// we need to highlight the new point, which means adding a serie on top of the others
highlightedPoint = new SimpleXYSeries("Highlighted Point");
highlightedPoint.addFirst(x,y);
addSeries(highlightedPoint, formatter);
}
You just need to call this method on your plot instance each time user clicks on your list.