I want to add GeoJson to mapbox mapsnapshot - java

I have been trying to find an efficient way to show multiple views of a mapbox map, and I have landed on the mapbox snapshotter. However I have had little luck when trying to add a geojson string of coordinates to the snapshot.
I used the below code:
int width = myContext.getResources().getDisplayMetrics().widthPixels;
int height = (int) convertDpToPixel(200f, myContext);
MapSnapshotter.Options snapShopOptions = new MapSnapshotter.Options(width, height);
LatLngBounds bounds = new LatLngBounds.Builder()
.include(post.getPath().get(0))
.include(post.getPath().get(post.getPath().size() - 1))
.build();
snapShopOptions.withRegion(bounds);
snapShopOptions.withStyle(myContext.getString(R.string.outdoor_style));
mapSnapshotter = new MapSnapshotter(myContext, snapShopOptions);
mapSnapshotter.setStyleJson(String.valueOf(new Style.Builder()
.fromUri("mapbox://styles/mapbox/outdoors-v11")));
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
#Override
public void onSnapshotReady(MapSnapshot snapshot) {
Bitmap bitmapImage = snapshot.getBitmap();
Glide.with(myContext).load(bitmapImage).into(holder.mapSnapShot);
}
});
I have tried initializing a MapboxMap object and adding the geojson to that feature and then using the .getProjection(), but it still does not show the route.
Can anyone help me solve this issue??

I ended up contacting Mapbox support and as of now the feature is not supported. Their exact quote was "Mapbox's MapSnapshotter does not support your use case, but it will once runtime styling is supported by the snapshotter."
Support then pointed me to this post Android Convert current screen to bitmap.
Hopefully if anyone was struggling similarly to me this will help save some time!

Related

How to implement Environmental HDR Lighting Estimation in Sceneform?

I´m trying to implement lighting estimation with new Google's API Environmental HDR. I'm following the instructions in developer guide, but I don't know how to implement the app-specific code.
I have configure the session like this:
config.setLightEstimationMode(Config.LightEstimationMode.ENVIRONMENTAL_HDR);
session.configure(config);
And put this code in my update call
private void onSceneUpdate(FrameTime frameTime) {
if (fragment instanceof ArFragment && loadedRenderable) {
if ( frame == null )
return;
LightEstimate lightEstimate = frame.getLightEstimate();
// note - currently only out param.
float[] intensity = lightEstimate.getEnvironmentalHdrMainLightIntensity();
float[] direction = lightEstimate.getEnvironmentalHdrMainLightDirection();
//app.setDirectionalLightValues(intensity, direction);
float[] harmonics = lightEstimate.getEnvironmentalHdrAmbientSphericalHarmonics();
//app.setAmbientSphericalHarmonicsLightValues(harmonics); // app-specific code.
// Get HDR environmental lighting as a cubemap in linear color space.
Image[] lightmaps = lightEstimate.acquireEnvironmentalHdrCubeMap();
for (int i = 0; i < lightmaps.length /*should be 6*/; ++i) {
//app.UploadToTexture(i, lightmaps[i]);
}
}
}
}
I can't figure out what to do with the parameters provided by those methods
I just want to light the 3D model with the same light conditions as the scene. Can anyone help me to achieve this? Or provide any example?

Keep Size Image with Ground Overlay in Google Map

I'm new in Android and I'm building an app. My problem is that when I want to put my own image in google map app using Ground Overlay.
But When I put my images, I can't keep the size, it very small and when I zoom it is the real size. What I would like to have it's when I zoom it keep the same size.
For example in Booking App, The "H" image is always at the same size (Airbnb had the same also).
Here is my code:
#Override
public void onMapReady(GoogleMap map) {
// Register a listener to respond to clicks on GroundOverlays.
map.setOnGroundOverlayClickListener(this);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11));
mImages.clear();
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922));
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_prudential_sunny));
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.logo_franprix));
//Resources res = getResources();
//Drawable drawable = res.getDrawable(R.drawable.ic_logo_franprix);
// Add a small, rotated overlay that is clickable by default
// (set by the initial state of the checkbox.)
mGroundOverlayRotated = map.addGroundOverlay(new GroundOverlayOptions().image(mImages.get(2)).anchor(0, 1)
.position(new LatLng(48.886517, 2.37105), 300f,300f));
I hope that you could help me, thank you very much.

Android ImageView scale and zoom replace image

I'm trying to build an simple image-zoom-replace functionality based on the Image-Zoom-Library "PhotoView":
https://github.com/chrisbanes/PhotoView
I just want to load a small image into a imageView and zoom/scale it. This code works perfectly:
ImageView galleryPictureNew = (ImageView)findViewById(R.id.galleryImage);
PhotoViewAttacher mAttacher = new PhotoViewAttacher(view);
mAttacher.update();
The problem is, i want to replace the small image with a large (hd-image) if i zoom in.
There is function called "setOnScaleChangeListener" like this:
mAttacher.setOnScaleChangeListener(new PhotoViewAttacher.OnScaleChangeListener() {
#Override
public void onScaleChange(float scaleFactor, float focusX, float focusY) {
//REPLACE IMAGE
}
});
This code above works, too BUT i want to "jump" to the last "position" and "zooming-level"?!
Does anyone has a solution for it?
Or maybe someone has an alternative library for this problem?
Do i have to save the last "position-state"?

Android :How to animate the speedometer needle

I implemented the speedometer in my project by referring the code as found in the below link.
I need to animate the speedometer needle till i get the result from server, and once i got the result , i need to set the needle to proper value based on some calculation.
I am not understanding how to do it.
Please help me with some solution.
https://github.com/ntoskrnl/SpeedometerView/blob/master/CardioMoodSpeedometerView/SpeedometerView/src/main/java/com/cardiomood/android/speedometer/SpeedometerView.java
private SpeedometerView speedometer;
// Customize SpeedometerView
speedometer = (SpeedometerView) v.findViewById(R.id.speedometer);
// Add label converter
speedometer.setLabelConverter(new SpeedometerView.LabelConverter() {
#Override
public String getLabelFor(double progress, double maxProgress) {
return String.valueOf((int) Math.round(progress));
}
});
// configure value range and ticks
speedometer.setMaxSpeed(300);
speedometer.setMajorTickStep(30);
speedometer.setMinorTicks(2);
// Configure value range colors
speedometer.addColoredRange(30, 140, Color.GREEN);
speedometer.addColoredRange(140, 180, Color.YELLOW);
speedometer.addColoredRange(180, 400, Color.RED);
Check the readme. Here you will find above code. And i think you need to look for how to change the needle.
And then call the public method SetSpeed(double speed) on the speedometer object.
A simple look through the code in your link provides the answer.

LibGDX - find out if a given screen resolution is supported on the current device

So I'm writing some tools for my program to deal with basic configurations, reading settings from a data file, and then making those settings the active configuration. I'm also building in an error checking mechanism to make sure that settings are formatted correctly and have valid values.
I want to check to see what the current devices supported resolutions are, and I want to compare that to the resolution specified in the data file. Is there an easy way to do this in libGDX that I'm missing? I know that LWJGL has a function that will give you an array of the supported resolutions, but I don't want to reinvent the wheel.
I'm looking for something like:
boolean isValidResolutionForDevice(int width, int height)
Am I going to have to write this myself? Or does this exist already? It seems to me to be such a useful function that it must have been written into the libraries somewhere.
There actually is a way to do this. The main com.badlogic.gdx.Application interface has a getGraphics() method, and the com.badlogic.gdx.Graphics class returned from that has getDisplayModes() method, which returns DisplayMode[]. DisplayMode basically looks like this (comments and constructor removed):
public class DisplayMode {
/** the width in physical pixels **/
public final int width;
/** the height in physical pixles **/
public final int height;
/** the refresh rate in Hertz **/
public final int refreshRate;
/** the number of bits per pixel, may exclude alpha **/
public final int bitsPerPixel;
}
And then you can scan through these to see if the resolution in question is supported or not.
The only bit of annoying news is because getGraphics() is on the Application object, it doesn't seem like you can query for the available graphics modes until after the Application object (e.g. LwjglApplication) has been created. So perhaps you pick an arbitrary resolution (e.g. 1024x768), start the game, then immediately switch to a supported resolution if the original wasn't actually supported (and optionally let the user pick in a settings menu).
I came across the method I believe you're referring to, org.lwjgl.opengl.Display.getAvailableDisplayModes(), and...honestly I'd just use this one for your use case. You'd pretty much just be iterating over it with a simple conditional inside. Not exactly reinventing anything.
Unfortunately, there is no ready solution in libgdx, I solved it like this:
private Map<Integer, Integer> supportedReolutions;
private String graphicFolder;
supportedReolutions = new HashMap<Integer, Integer>();
supportedReolutions.put(1024, 768);
supportedReolutions.put(1080, 1920);
supportedReolutions.put(1200, 1920);
supportedReolutions.put(2048, 1536);
supportedReolutions.put(480, 800);
supportedReolutions.put(640, 1136);
graphicFolder = "1080x1920";
/**
* Chose the folder with best graphic for current device
*/
private void setCurrentResolutionFolder() {
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
if (supportedReolutions.containsKey(width)) {
if (supportedReolutions.get(width) == height) {
graphicFolder = String.valueOf(width) + "x"
+ String.valueOf(height);
}
}
}

Categories