Skip to content

Commit

Permalink
Add puck styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Li committed Jan 11, 2022
1 parent 3c2641a commit 7140bdf
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ private void locationComponentSettings(LocationPuck locationPuck) {
locationComponentSettings = new LocationComponentSettings(true, true, Color.BLACK, 1f, "id", "id", locationPuck);
}

private void locationComponent(Context context, MapView mapView) {
LocationComponentPlugin locationComponent = LocationComponentUtils.getLocationComponent(mapView);
locationComponent.setLocationPuck(LocationComponentUtils.createDefault2DPuck(locationComponent, context));
locationComponent.setLocationPuck(LocationComponentUtils.createDefault2DPuck(locationComponent, context, true));
}

private void gesturesSettings(ScrollMode scrollMode, ScreenCoordinate screenCoordinate) {
GesturesSettings gesturesSettings = new GesturesSettings();
gesturesSettings = new GesturesSettings(true);
Expand Down Expand Up @@ -306,9 +312,9 @@ private void mapSurface(Context context, Surface surface, MapInitOptions mapInit
private void locationPuck(Drawable image, List<Float> floatList) {
LocationPuck2D locationPuck2D = new LocationPuck2D();
locationPuck2D = new LocationPuck2D(image);
locationPuck2D = new LocationPuck2D(image, true, image);
locationPuck2D = new LocationPuck2D(image, true, image, image);
locationPuck2D = new LocationPuck2D(image, true, image, image, "scale");
locationPuck2D = new LocationPuck2D(image, image);
locationPuck2D = new LocationPuck2D(image, image, image);
locationPuck2D = new LocationPuck2D(image, image, image, "scale");

LocationPuck3D locationPuck3D = new LocationPuck3D("uri");
locationPuck3D = new LocationPuck3D("uri", floatList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import com.mapbox.maps.plugin.LocationPuck2D
import com.mapbox.maps.plugin.LocationPuck3D
import com.mapbox.maps.plugin.PuckBearingSource
import com.mapbox.maps.plugin.gestures.gestures
import com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener
import com.mapbox.maps.plugin.locationcomponent.location
import com.mapbox.maps.plugin.locationcomponent.*
import com.mapbox.maps.testapp.R
import com.mapbox.maps.testapp.databinding.ActivityLocationComponentBinding
import com.mapbox.maps.testapp.utils.LocationPermissionHelper
Expand Down Expand Up @@ -88,15 +87,17 @@ class LocationComponentActivity : AppCompatActivity() {
}
R.id.action_show_bearing -> {
if (binding.mapView.location.locationPuck is LocationPuck2D) {
(binding.mapView.location.locationPuck as LocationPuck2D).showBearingImage = true
binding.mapView.location.updateSettings {}
binding.mapView.location.apply {
locationPuck = createDefault2DPuck(this@LocationComponentActivity, true)
}
}
return true
}
R.id.action_hide_bearing -> {
if (binding.mapView.location.locationPuck is LocationPuck2D) {
(binding.mapView.location.locationPuck as LocationPuck2D).showBearingImage = false
binding.mapView.location.updateSettings {}
binding.mapView.location.apply {
locationPuck = createDefault2DPuck(this@LocationComponentActivity)
}
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class LocationComponentAnimationActivity : AppCompatActivity() {
this@LocationComponentAnimationActivity,
R.drawable.mapbox_mylocation_icon_bearing,
),
showBearingImage = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

package com.mapbox.maps.plugin.locationcomponent

import android.content.Context
import androidx.core.content.res.ResourcesCompat
import com.mapbox.maps.plugin.LocationPuck2D
import com.mapbox.maps.plugin.Plugin
import com.mapbox.maps.plugin.delegates.MapPluginProviderDelegate

Expand All @@ -10,4 +13,49 @@ import com.mapbox.maps.plugin.delegates.MapPluginProviderDelegate
*/
val MapPluginProviderDelegate.location: LocationComponentPlugin
@JvmName("getLocationComponent")
get() = this.getPlugin(Plugin.MAPBOX_LOCATION_COMPONENT_PLUGIN_ID)!!
get() = this.getPlugin(Plugin.MAPBOX_LOCATION_COMPONENT_PLUGIN_ID)!!

/**
* Create a [LocationPuck2D] instance with or without an arrow bearing image.
* @param context the context of application
* @param withBearing if ture, the location puck will show an arrow bearing image, default is false.
*/
@JvmOverloads
fun LocationComponentPlugin.createDefault2DPuck(
context: Context,
withBearing: Boolean = false
): LocationPuck2D {
if (withBearing) {
return LocationPuck2D(
topImage = ResourcesCompat.getDrawable(context.resources, R.drawable.mapbox_user_icon, null),
bearingImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_bearing_icon,
null
),
shadowImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_stroke_icon,
null
)
)
} else {
return LocationPuck2D(
topImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_icon,
null
),
bearingImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_stroke_icon,
null
),
shadowImage = ResourcesCompat.getDrawable(
context.resources,
R.drawable.mapbox_user_icon_shadow,
null
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,13 @@ internal class LocationIndicatorLayerRenderer(
private fun setupBitmaps() {
puckOptions.topImage?.let { BitmapUtils.getBitmapFromDrawable(it) }
?.let { style?.addImage(TOP_ICON, it) }
if (puckOptions.showBearingImage) {
puckOptions.bearingImage?.let { BitmapUtils.getBitmapFromDrawable(it) }
?.let { style?.addImage(BEARING_ICON, it) }
} else {
style?.removeStyleImage(BEARING_ICON)
}
puckOptions.bearingImage?.let { BitmapUtils.getBitmapFromDrawable(it) }
?.let { style?.addImage(BEARING_ICON, it) }

puckOptions.shadowImage?.let { BitmapUtils.getBitmapFromDrawable(it) }
?.let { style?.addImage(SHADOW_ICON, it) }
layer.topImage(TOP_ICON)
if (puckOptions.showBearingImage) {
layer.bearingImage(BEARING_ICON)
}
layer.bearingImage(BEARING_ICON)
layer.shadowImage(SHADOW_ICON)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ internal class LocationPuckManager(
}
updateCurrentBearing(lastBearing)
locationLayerRenderer.initializeComponents(style)
// locationLayerRenderer.showBearingImage(settings.showBearingImage)
styleScaling(settings)
if (lastLocation != null && settings.enabled) {
show()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

<!-- Name of image in sprite to use as the top of the location indicator. -->
<public name="mapbox_locationComponentLocationPuckLocationPuck2DTopImage" type="attr" />
<!-- Whether the bearing image of location puck is shown. -->
<public name="mapbox_locationComponentLocationPuckLocationPuck2DShowBearingImage" type="attr" />
<!-- Name of image in sprite to use as the middle of the location indicator. -->
<public name="mapbox_locationComponentLocationPuckLocationPuck2DBearingImage" type="attr" />
<!-- Name of image in sprite to use as the background of the location indicator. -->
Expand Down
2 changes: 0 additions & 2 deletions plugin-locationcomponent/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

<!-- Name of image in sprite to use as the top of the location indicator. -->
<attr name="mapbox_locationComponentLocationPuckLocationPuck2DTopImage" format="reference"/>
<!-- Whether the bearing image of location puck is shown. -->
<attr name="mapbox_locationComponentLocationPuckLocationPuck2DShowBearingImage" format="boolean"/>
<!-- Name of image in sprite to use as the middle of the location indicator. -->
<attr name="mapbox_locationComponentLocationPuckLocationPuck2DBearingImage" format="reference"/>
<!-- Name of image in sprite to use as the background of the location indicator. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class LocationIndicatorLayerRendererTest {
any()
)
}
verify(exactly = 0) {
verify(exactly = 1) {
style.addImage(
BEARING_ICON,
any()
Expand All @@ -177,18 +177,5 @@ class LocationIndicatorLayerRendererTest {
}
}

@Test
fun testAddBearingBitmaps() {
every { puckOptions.showBearingImage } returns true
locationLayerRenderer = LocationIndicatorLayerRenderer(puckOptions, layerSourceProvider)
locationLayerRenderer.initializeComponents(style)
verify(exactly = 1) {
style.addImage(
BEARING_ICON,
any()
)
}
}

private fun Point.toLocationList() = listOf(latitude(), longitude(), 0.0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ data class LocationPuck2D @JvmOverloads constructor(
* Name of image in sprite to use as the top of the location indicator.
*/
var topImage: Drawable? = null,
/**
* Whether the bearing image of location puck is shown.
*/
var showBearingImage: Boolean = false,
/**
* Name of image in sprite to use as the middle of the location indicator.
*/
Expand Down

0 comments on commit 7140bdf

Please sign in to comment.