@lugg/maps 1.0.0-beta.16 → 1.0.0-beta.17

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.
@@ -148,13 +148,25 @@ static const NSUInteger kMaxGradientSpans = 512;
148
148
  }
149
149
 
150
150
  GMSMutablePath *path = [GMSMutablePath path];
151
- for (CLLocation *location in self.coordinates) {
152
- [path addCoordinate:location.coordinate];
151
+ CLLocationCoordinate2D lastCoord = self.coordinates.firstObject.coordinate;
152
+ [path addCoordinate:lastCoord];
153
+ for (NSUInteger i = 1; i < self.coordinates.count; i++) {
154
+ CLLocationCoordinate2D coord = self.coordinates[i].coordinate;
155
+ if (coord.latitude == lastCoord.latitude && coord.longitude == lastCoord.longitude) {
156
+ continue;
157
+ }
158
+ [path addCoordinate:coord];
159
+ lastCoord = coord;
153
160
  }
161
+
162
+ // Clear stale spans before swapping the path so Google Maps never rebuilds
163
+ // span models against a path with fewer segments (GMSModelStyleBuilder
164
+ // couldNotInstantiate -> EXC_BAD_ACCESS). Reassign spans once the new path is set.
165
+ _polyline.spans = nil;
154
166
  _polyline.path = path;
155
167
 
156
- if (self.strokeColors.count > 1) {
157
- _polyline.spans = [self createGradientSpans];
168
+ if (path.count > 1 && self.strokeColors.count > 1) {
169
+ _polyline.spans = [self createGradientSpansForSegmentCount:path.count - 1];
158
170
  } else {
159
171
  _polyline.strokeColor = self.strokeColors.firstObject ?: [UIColor blackColor];
160
172
  }
@@ -222,35 +234,44 @@ static const NSUInteger kMaxGradientSpans = 512;
222
234
  }
223
235
 
224
236
  if (headDist <= tailDist) {
237
+ _polyline.spans = nil;
225
238
  _polyline.path = [GMSMutablePath path];
226
239
  return;
227
240
  }
228
241
 
229
- CGFloat visibleLength = headDist - tailDist;
230
242
  NSUInteger startIndex = [self indexForDistance:tailDist];
231
243
  NSUInteger endIndex = [self indexForDistance:headDist];
232
244
 
233
245
  GMSMutablePath *path = [GMSMutablePath path];
234
- NSMutableArray<GMSStyleSpan *> *spans = [NSMutableArray array];
235
246
 
236
- CLLocationCoordinate2D startCoord = [self coordinateAtDistance:tailDist];
237
- [path addCoordinate:startCoord];
247
+ CLLocationCoordinate2D lastCoord = [self coordinateAtDistance:tailDist];
248
+ [path addCoordinate:lastCoord];
238
249
 
239
250
  for (NSUInteger i = startIndex + 1; i <= endIndex; i++) {
240
- [path addCoordinate:self.coordinates[i].coordinate];
251
+ CLLocationCoordinate2D coord = self.coordinates[i].coordinate;
252
+ if (coord.latitude == lastCoord.latitude && coord.longitude == lastCoord.longitude) {
253
+ continue;
254
+ }
255
+ [path addCoordinate:coord];
256
+ lastCoord = coord;
241
257
  }
242
258
 
243
259
  CLLocationCoordinate2D endCoord = [self coordinateAtDistance:headDist];
244
- CLLocationCoordinate2D lastAdded =
245
- (endIndex < self.coordinates.count) ? self.coordinates[endIndex].coordinate : endCoord;
246
- if (endCoord.latitude != lastAdded.latitude || endCoord.longitude != lastAdded.longitude) {
260
+ if (endCoord.latitude != lastCoord.latitude || endCoord.longitude != lastCoord.longitude) {
247
261
  [path addCoordinate:endCoord];
248
262
  }
249
263
 
250
264
  NSUInteger pathCount = path.count;
251
- NSUInteger segmentCount = pathCount - 1;
265
+ NSUInteger segmentCount = (pathCount > 1) ? pathCount - 1 : 0;
266
+
267
+ if (segmentCount == 0) {
268
+ _polyline.spans = nil;
269
+ _polyline.path = path;
270
+ return;
271
+ }
252
272
 
253
273
  if (self.strokeColors.count <= 1) {
274
+ _polyline.spans = nil;
254
275
  _polyline.path = path;
255
276
  _polyline.strokeColor = self.strokeColors.firstObject ?: [UIColor blackColor];
256
277
  return;
@@ -259,6 +280,7 @@ static const NSUInteger kMaxGradientSpans = 512;
259
280
  NSUInteger spanCount = MIN(segmentCount, kMaxAnimationSpans);
260
281
  double segmentsPerSpan = (double)segmentCount / spanCount;
261
282
 
283
+ NSMutableArray<GMSStyleSpan *> *spans = [NSMutableArray array];
262
284
  for (NSUInteger i = 0; i < spanCount; i++) {
263
285
  CGFloat gradientPos = ((CGFloat)i + 0.5) / spanCount;
264
286
  UIColor *color = [self colorAtGradientPosition:gradientPos];
@@ -266,13 +288,16 @@ static const NSUInteger kMaxGradientSpans = 512;
266
288
  [spans addObject:[GMSStyleSpan spanWithStyle:style segments:segmentsPerSpan]];
267
289
  }
268
290
 
291
+ // Clear stale spans before swapping the path so Google Maps never rebuilds
292
+ // span models against a path with fewer segments (GMSModelStyleBuilder
293
+ // couldNotInstantiate -> EXC_BAD_ACCESS). Reassign spans once the new path is set.
294
+ _polyline.spans = nil;
269
295
  _polyline.path = path;
270
296
  _polyline.spans = spans;
271
297
  }
272
298
 
273
- - (NSArray<GMSStyleSpan *> *)createGradientSpans {
299
+ - (NSArray<GMSStyleSpan *> *)createGradientSpansForSegmentCount:(NSUInteger)segmentCount {
274
300
  NSMutableArray<GMSStyleSpan *> *spans = [NSMutableArray array];
275
- NSUInteger segmentCount = self.coordinates.count - 1;
276
301
  NSUInteger spanCount = MIN(segmentCount, kMaxGradientSpans);
277
302
  double segmentsPerSpan = (double)segmentCount / spanCount;
278
303
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lugg/maps",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "Universal maps for React Native.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",