react-native-google-maps-plus 1.7.0-dev.2 → 1.7.0-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,16 @@
1
1
  package com.rngooglemapsplus
2
2
 
3
3
  import android.graphics.Bitmap
4
+ import android.graphics.BitmapFactory
4
5
  import android.graphics.Canvas
6
+ import android.graphics.Typeface
5
7
  import android.util.Base64
6
8
  import android.util.LruCache
7
9
  import androidx.core.graphics.createBitmap
8
10
  import com.caverock.androidsvg.SVG
9
11
  import com.caverock.androidsvg.SVGExternalFileResolver
10
12
  import com.facebook.react.uimanager.PixelUtil.dpToPx
13
+ import com.facebook.react.uimanager.ThemedReactContext
11
14
  import com.google.android.gms.maps.model.BitmapDescriptor
12
15
  import com.google.android.gms.maps.model.BitmapDescriptorFactory
13
16
  import com.google.android.gms.maps.model.Marker
@@ -22,10 +25,13 @@ import kotlinx.coroutines.SupervisorJob
22
25
  import kotlinx.coroutines.ensureActive
23
26
  import kotlinx.coroutines.launch
24
27
  import kotlinx.coroutines.withContext
28
+ import java.net.HttpURLConnection
29
+ import java.net.URL
25
30
  import java.net.URLDecoder
26
31
  import kotlin.coroutines.coroutineContext
27
32
 
28
33
  class MapMarkerBuilder(
34
+ val context: ThemedReactContext,
29
35
  private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default),
30
36
  ) {
31
37
  private val iconCache =
@@ -39,6 +45,7 @@ class MapMarkerBuilder(
39
45
  private val jobsById = mutableMapOf<String, Job>()
40
46
 
41
47
  init {
48
+ // / TODO: refactor with androidsvg 1.5 release
42
49
  SVG.registerExternalFileResolver(
43
50
  object : SVGExternalFileResolver() {
44
51
  override fun resolveImage(filename: String?): Bitmap? {
@@ -64,11 +71,70 @@ class MapMarkerBuilder(
64
71
  }
65
72
  }
66
73
 
74
+ filename.startsWith("http://") || filename.startsWith("https://") -> {
75
+ val conn =
76
+ (URL(filename).openConnection() as HttpURLConnection).apply {
77
+ connectTimeout = 5000
78
+ readTimeout = 5000
79
+ requestMethod = "GET"
80
+ instanceFollowRedirects = true
81
+ }
82
+ conn.connect()
83
+
84
+ val contentType = conn.contentType ?: ""
85
+ val result =
86
+ if (contentType.contains("svg") || filename.endsWith(".svg")) {
87
+ val svgText = conn.inputStream.bufferedReader().use { it.readText() }
88
+ val innerSvg = SVG.getFromString(svgText)
89
+ val w = innerSvg.documentWidth.takeIf { it > 0 } ?: 128f
90
+ val h = innerSvg.documentHeight.takeIf { it > 0 } ?: 128f
91
+ val bmp = createBitmap(w.toInt(), h.toInt())
92
+ val canvas = Canvas(bmp)
93
+ innerSvg.renderToCanvas(canvas)
94
+ bmp
95
+ } else {
96
+ conn.inputStream.use { BitmapFactory.decodeStream(it) }
97
+ }
98
+
99
+ conn.disconnect()
100
+ result
101
+ }
102
+
67
103
  else -> null
68
104
  }
69
105
  }.getOrNull()
70
106
  }
71
107
 
108
+ override fun resolveFont(
109
+ fontFamily: String?,
110
+ fontWeight: Int,
111
+ fontStyle: String?,
112
+ ): Typeface? {
113
+ if (fontFamily.isNullOrBlank()) return null
114
+
115
+ return runCatching {
116
+ val assetManager = context.assets
117
+
118
+ val candidates =
119
+ listOf(
120
+ "fonts/$fontFamily.ttf",
121
+ "fonts/$fontFamily.otf",
122
+ )
123
+
124
+ for (path in candidates) {
125
+ try {
126
+ return Typeface.createFromAsset(assetManager, path)
127
+ } catch (_: Throwable) {
128
+ // / ignore
129
+ }
130
+ }
131
+
132
+ Typeface.create(fontFamily, Typeface.NORMAL)
133
+ }.getOrElse {
134
+ Typeface.create(fontFamily, fontWeight)
135
+ }
136
+ }
137
+
72
138
  override fun isFormatSupported(mimeType: String?): Boolean = mimeType?.startsWith("image/") == true
73
139
  },
74
140
  )
@@ -29,7 +29,7 @@ class RNGoogleMapsPlusView(
29
29
  private var locationHandler = LocationHandler(context)
30
30
  private var playServiceHandler = PlayServicesHandler(context)
31
31
 
32
- private val markerBuilder = MapMarkerBuilder()
32
+ private val markerBuilder = MapMarkerBuilder(context)
33
33
  private val polylineBuilder = MapPolylineBuilder()
34
34
  private val polygonBuilder = MapPolygonBuilder()
35
35
  private val circleBuilder = MapCircleBuilder()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-google-maps-plus",
3
- "version": "1.7.0-dev.2",
3
+ "version": "1.7.0-dev.3",
4
4
  "description": "React Native wrapper for Android & iOS Google Maps SDK",
5
5
  "main": "./lib/module/index.js",
6
6
  "module": "./lib/module/index.js",