CartoDB / mobile-sdk

CARTO Mobile SDK core project
https://carto.com/docs/carto-engine/mobile-sdk/
BSD 3-Clause "New" or "Revised" License
184 stars 65 forks source link

Placing position of Marker with image #519

Closed binu8051 closed 1 year ago

binu8051 commented 2 years ago

Hi i am using a Marker with an image carto with the marker image 1, bottom sharp point is placed on the mappos and looks ok but with image 2 i want to place the center of the image to the mappos since its a Boat image and the center of the boat will be at that location. is there any way for it?

My code

Bitmap markerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.boat);
Bitmap canvasBitmap = markerBitmap.copy(Bitmap.Config.ARGB_8888, true);
styleBuilder = new MarkerStyleBuilder();
styleBuilder.setBitmap(BitmapUtils.createBitmapFromAndroidBitmap(canvasBitmap));
styleBuilder.setHideIfOverlapped(false);
styleBuilder.setScalingMode(BillboardScaling.BILLBOARD_SCALING_CONST_SCREEN_SIZE);
styleBuilder.setOrientationMode(BillboardOrientation.BILLBOARD_ORIENTATION_GROUND);

style0 = styleBuilder.buildStyle();
aisicon = new Marker(markerLocation, style0);
aisicon.setRotation(bearTdo);
aisDataSource.add(aisicon);

Thanks

mtehver commented 1 year ago

If I understand correctly, you need to set 'anchor point' of your marker to the center of your bitmap. You can do it with something like this:

styleBuilder.setAnchorPointX(0.0f);
styleBuilder.setAnchorPointY(0.0f);
binu8051 commented 1 year ago

That works, thanks