-
Notifications
You must be signed in to change notification settings - Fork 44
Add: animate marker #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,13 @@ import kotlinx.coroutines.* | |||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.channels.Channel | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.InputStream | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.URL | ||||||||||||||||||||||||||||||||||||||||||||||
| import android.animation.ValueAnimator | ||||||||||||||||||||||||||||||||||||||||||||||
| import android.animation.AnimatorListenerAdapter | ||||||||||||||||||||||||||||||||||||||||||||||
| import android.animation.Animator | ||||||||||||||||||||||||||||||||||||||||||||||
| import com.google.android.gms.maps.model.LatLng | ||||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.CoroutineScope | ||||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.Dispatchers | ||||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.launch | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| class CapacitorGoogleMap( | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -244,6 +251,47 @@ class CapacitorGoogleMap( | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| fun animateMarker(markerId: String,lat: Double,lng: Double,duration: Long, callback: (Result<Unit>) -> Unit | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| googleMap ?: throw GoogleMapNotAvailable() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| CoroutineScope(Dispatchers.Main).launch { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| val wrapper = markers[markerId] ?: throw MarkerNotFoundError() | ||||||||||||||||||||||||||||||||||||||||||||||
| val marker = wrapper.googleMapMarker | ||||||||||||||||||||||||||||||||||||||||||||||
| ?: throw GoogleMapsError("GoogleMap Marker not available") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| val startPos = marker.position | ||||||||||||||||||||||||||||||||||||||||||||||
| val endPos = LatLng(lat, lng) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ValueAnimator.ofFloat(0f, 1f).apply { | ||||||||||||||||||||||||||||||||||||||||||||||
| this.duration = duration | ||||||||||||||||||||||||||||||||||||||||||||||
| addUpdateListener { anim -> | ||||||||||||||||||||||||||||||||||||||||||||||
| val fraction = anim.animatedValue as Float | ||||||||||||||||||||||||||||||||||||||||||||||
| val newLat = startPos.latitude + | ||||||||||||||||||||||||||||||||||||||||||||||
| fraction * (endPos.latitude - startPos.latitude) | ||||||||||||||||||||||||||||||||||||||||||||||
| val newLng = startPos.longitude + | ||||||||||||||||||||||||||||||||||||||||||||||
| fraction * (endPos.longitude - startPos.longitude) | ||||||||||||||||||||||||||||||||||||||||||||||
| marker.position = LatLng(newLat, newLng) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| addListener(object : AnimatorListenerAdapter() { | ||||||||||||||||||||||||||||||||||||||||||||||
| override fun onAnimationEnd(animation: Animator) { | ||||||||||||||||||||||||||||||||||||||||||||||
| callback(Result.success(Unit)) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+271
to
+281
|
||||||||||||||||||||||||||||||||||||||||||||||
| val fraction = anim.animatedValue as Float | |
| val newLat = startPos.latitude + | |
| fraction * (endPos.latitude - startPos.latitude) | |
| val newLng = startPos.longitude + | |
| fraction * (endPos.longitude - startPos.longitude) | |
| marker.position = LatLng(newLat, newLng) | |
| } | |
| addListener(object : AnimatorListenerAdapter() { | |
| override fun onAnimationEnd(animation: Animator) { | |
| callback(Result.success(Unit)) | |
| } | |
| val fraction = anim.animatedValue as Float | |
| val newLat = startPos.latitude + | |
| fraction * (endPos.latitude - startPos.latitude) | |
| val newLng = startPos.longitude + | |
| fraction * (endPos.longitude - startPos.longitude) | |
| marker.position = LatLng(newLat, newLng) | |
| } | |
| addListener(object : AnimatorListenerAdapter() { | |
| override fun onAnimationEnd(animation: Animator) { | |
| callback(Result.success(Unit)) | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import Foundation | |||||
| import GoogleMaps | ||||||
| import Capacitor | ||||||
| import GoogleMapsUtils | ||||||
| import QuartzCore | ||||||
|
|
||||||
| public struct LatLng: Codable { | ||||||
| let lat: Double | ||||||
|
|
@@ -240,6 +241,21 @@ public class Map { | |||||
| return markerHash | ||||||
| } | ||||||
|
|
||||||
| func animateMarker( markerId: Int, to target: LatLng, duration: Double) throws { | ||||||
|
||||||
| func animateMarker( markerId: Int, to target: LatLng, duration: Double) throws { | |
| func animateMarker(markerId: Int, to target: LatLng, duration: Double) throws { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import type { Plugin } from '@capacitor/core'; | |||||
| import { registerPlugin } from '@capacitor/core'; | ||||||
|
|
||||||
| import type { | ||||||
| AnimateMarkerOptions, | ||||||
| CameraConfig, | ||||||
| Circle, | ||||||
| GoogleMapConfig, | ||||||
|
|
@@ -73,6 +74,14 @@ export interface AddMarkerArgs { | |||||
| marker: Marker; | ||||||
| } | ||||||
|
|
||||||
| export interface AnimateMarkerArgs { | ||||||
| id: string; | ||||||
| markerId: string; | ||||||
| lat: number; | ||||||
| lng: number; | ||||||
| duration?: number; | ||||||
| } | ||||||
|
|
||||||
| export interface AddPolygonsArgs { | ||||||
| id: string; | ||||||
| polygons: Polygon[]; | ||||||
|
|
@@ -174,6 +183,7 @@ export interface CapacitorGoogleMapsPlugin extends Plugin { | |||||
| enableTouch(args: { id: string }): Promise<void>; | ||||||
| disableTouch(args: { id: string }): Promise<void>; | ||||||
| addMarker(args: AddMarkerArgs): Promise<{ id: string }>; | ||||||
| animateMarker(options: AnimateMarkerOptions): Promise<void>; | ||||||
|
||||||
| animateMarker(options: AnimateMarkerOptions): Promise<void>; | |
| animateMarker(options: AnimateMarkerArgs): Promise<void>; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,7 @@ export interface GoogleMapInterface { | |||||
| ): Promise<void>; | ||||||
| disableClustering(): Promise<void>; | ||||||
| addMarker(marker: Marker): Promise<string>; | ||||||
| animateMarker(markerId: string,lat: number,lng: number,duration?: number): Promise<void>; | ||||||
|
||||||
| animateMarker(markerId: string,lat: number,lng: number,duration?: number): Promise<void>; | |
| animateMarker(markerId: string, lat: number, lng: number, duration?: number): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces after commas in the parameter list. Should have spaces after 'String,', 'Double,', 'Double,', and 'Long,'.