Skip to content

Commit 683fb61

Browse files
authored
chore: new examples for sprite polylines (#170)
1 parent 7150ff2 commit 683fb61

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

snippets/MapsSnippets/MapsSnippets/Shapes.m

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,65 @@ - (void)circles {
171171
// [END maps_ios_shapes_circles_customize]
172172
}
173173

174+
- (void)spritePolyLine {
175+
// [START maps_ios_polyline_sprite]
176+
GMSMutablePath *path = [GMSMutablePath path];
177+
[path addLatitude:-37.81319 longitude:144.96298];
178+
[path addLatitude:-31.95285 longitude:115.85734];
179+
polyline.strokeWidth = 20;
180+
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
181+
182+
UIImage *image = [UIImage imageNamed:@"imageFromBundleOrAsset"];
183+
GMSStrokeStyle *transparentStampStroke = [GMSStrokeStyle transparentStrokeWithStampStyle:[GMSSpriteStyle spriteStyleWithImage:image]];
184+
185+
GMSStyleSpan *span = [GMSStyleSpan spanWithStyle:transparentStampStroke];
186+
polyline.spans = @[span];
187+
polyline.map = _mapView;
188+
// [END maps_ios_polyline_sprite]
189+
}
190+
191+
- (void)texturePolyline {
192+
// [START maps_ios_polyline_texture]
193+
GMSMutablePath *path = [GMSMutablePath path];
194+
[path addLatitude:-37.81319 longitude:144.96298];
195+
[path addLatitude:-31.95285 longitude:115.85734];
196+
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
197+
polyline.strokeWidth = 20;
198+
GMSStrokeStyle *redWithStamp = [GMSStrokeStyle solidColor:[UIColor redColor]];
199+
200+
UIImage *image = [UIImage imageNamed:@"imageFromBundleOrAsset"]; // Image could be from anywhere
201+
redWithStamp.stampStyle = [GMSTextureStyle textureStyleWithImage:image];
202+
203+
GMSStyleSpan *span = [GMSStyleSpan spanWithStyle:redWithStamp];
204+
polyline.spans = @[span];
205+
polyline.map = _mapView;
206+
// [END maps_ios_polyline_texture]
207+
}
208+
209+
- (void)mapCapabilties {
210+
// [START maps_ios_map_capabilities]
211+
GMSMutablePath *path = [GMSMutablePath path];
212+
[path addLatitude:-37.81319 longitude:144.96298];
213+
[path addLatitude:-31.95285 longitude:115.85734];
214+
215+
UIImage *_Nonnull image = [UIImage imageNamed:@"imageFromBundleOrAsset"]; // Image could be from anywhere
216+
217+
NSArray<GMSStyleSpan *> * spans;
218+
if (_mapView.mapCapabilities & GMSMapCapabilityFlagsSpritePolylines) {
219+
GMSSpriteStyle *spriteStyle = [GMSSpriteStyle spriteStyleWithImage:image];
220+
GMSStrokeStyle *stroke = [GMSStrokeStyle transparentStrokeWithStampStyle:spriteStyle];
221+
spans = @[ [GMSStyleSpan spanWithStyle:stroke] ];
222+
} else {
223+
GMSStrokeStyle *stroke = [GMSStrokeStyle solidColor:UIColor.clearColor];
224+
stroke.stampStyle = [GMSTextureStyle textureStyleWithImage:image];
225+
spans = @[ [GMSStyleSpan spanWithStyle:stroke] ];
226+
}
227+
228+
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
229+
polyline.strokeWidth = 20;
230+
polyline.spans = spans;
231+
polyline.map = _mapView;
232+
// [END maps_ios_map_capabilities]
233+
}
234+
174235
@end

snippets/MapsSnippets/MapsSnippets/Swift/Shapes.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,59 @@ class Shapes {
178178
circle.strokeWidth = 5
179179
// [END maps_ios_shapes_circles_customize]
180180
}
181+
182+
func spritePolyline() {
183+
// [START maps_ios_polyline_sprite]
184+
let path = GMSMutablePath()
185+
path.addLatitude(-37.81319, longitude: 144.96298)
186+
path.addLatitude(-31.95285, longitude: 115.85734)
187+
let polyline = GMSPolyline(path: path)
188+
polyline.strokeWidth = 20
189+
let image = UIImage(named: "imageFromBundleOrAsset")! // Image could be from anywhere
190+
let stampStyle = GMSSpriteStyle(image: image)
191+
let transparentStampStroke = GMSStrokeStyle.transparentStroke(withStamp: stampStyle)
192+
let span = GMSStyleSpan(style: transparentStampStroke)
193+
polyline.spans = [span]
194+
polyline.map = mapView
195+
// [END maps_ios_polyline_sprite]
196+
}
197+
198+
func texturePolyline() {
199+
// [START maps_ios_polyline_texture]
200+
let path = GMSMutablePath()
201+
path.addLatitude(-37.81319, longitude: 144.96298)
202+
path.addLatitude(-31.95285, longitude: 115.85734)
203+
let polyline = GMSPolyline(path: path)
204+
polyline.strokeWidth = 20
205+
let redWithStamp = GMSStrokeStyle.solidColor(.red)
206+
let image = UIImage(named: "imageFromBundleOrAsset")! // Image could be from anywhere
207+
redWithStamp.stampStyle = GMSTextureStyle(image: image)
208+
let span = GMSStyleSpan(style: redWithStamp)
209+
polyline.spans = [span]
210+
polyline.map = mapView
211+
// [END maps_ios_polyline_texture]
212+
}
213+
214+
func mapCapabilities() {
215+
// [START maps_ios_map_capabilities]
216+
let path = GMSMutablePath()
217+
path.addLatitude(-37.81319, longitude: 144.96298)
218+
path.addLatitude(-31.95285, longitude: 115.85734)
219+
let polyline = GMSPolyline(path: path)
220+
polyline.strokeWidth = 20
221+
let image = UIImage(named: "imageFromBundleOrAsset")! // Image could be from anywhere
222+
let spans: [GMSStyleSpan]
223+
if (mapView.mapCapabilities.contains(.spritePolylines)) {
224+
let spriteStyle = GMSSpriteStyle(image: image)
225+
let stroke = GMSStrokeStyle.transparentStroke(withStamp: spriteStyle)
226+
spans = [ GMSStyleSpan(style: stroke) ]
227+
} else {
228+
let stroke = GMSStrokeStyle.solidColor(.clear)
229+
stroke.stampStyle = GMSTextureStyle(image: image)
230+
spans = [ GMSStyleSpan(style: stroke) ]
231+
}
232+
polyline.spans = spans
233+
polyline.map = mapView
234+
// [END maps_ios_map_capabilities]
235+
}
181236
}

0 commit comments

Comments
 (0)