Loading...
Searching...
No Matches
LocationWindowMapObjectsExample.swift
Go to the documentation of this file.
1import Foundation
2import UIKit
3import NavigineSDK
4
5/**
6 * LocationWindowMapObjects usage example for Swift
7 * Demonstrates specific methods: addCircleMapObject, removeCircleMapObject, addIconMapObject,
8 * removeIconMapObject, addPolygonMapObject, addPolylineMapObject, removePolylineMapObject,
9 * addDottedPolylineMapObject, removeDottedPolylineMapObject, addModelMapObject, removeModelMapObject, removeAllMapObjects
10 */
11class LocationWindowMapObjectsExample {
12 private var locationWindow: NCLocationWindow?
13 private var circleMapObject: NCCircleMapObject?
14 private var iconMapObject: NCIconMapObject?
15 private var modelMapObject: NCModelMapObject?
16 private var polygonMapObject: NCPolygonMapObject?
17 private var polylineMapObject: NCPolylineMapObject?
18 private var dottedPolylineMapObject: NCDottedPolylineMapObject?
19 private var clusterMapObjectController: NCClusterMapObjectController?
20 private var clusterMapObjectControllerListener: DemoClusterMapObjectControllerListener?
21
22 init() {
23 demonstrateLocationWindowMapObjectsMethods()
24 }
25
26 /**
27 * Demonstrate LocationWindowMapObjects methods
28 */
29 private func demonstrateLocationWindowMapObjectsMethods() {
30 print("=== LocationWindowMapObjects Example ===")
31
32 // Initialize LocationWindow (in real app, this would be provided by the framework)
33 // locationWindow = getLocationWindow()
34
35 demonstrateLocationScopedGeometryRecords()
36
37 demonstrateCircleMapObjects()
38 demonstrateIconMapObjects()
39 demonstrateClusterMapObjects()
40 demonstrateModelMapObjects()
41 demonstratePolygonMapObjects()
42 demonstratePolylineMapObjects()
43 demonstrateDottedPolylineMapObjects()
44 demonstrateRemoveAllMapObjects()
45
46 cleanup()
47 }
48
49 /**
50 * Metrics geometry scoped to a location / sublocation (@see NCLocationPolygon, NCLocationPolyline).
51 */
52 private func demonstrateLocationScopedGeometryRecords() {
53 print("--- LocationPolygon / LocationPolyline records ---")
54
55 // [swift_LocationPolygon_record]
56 let ring = [
57 NCGlobalPoint(latitude: 55.751, longitude: 37.617),
58 NCGlobalPoint(latitude: 55.752, longitude: 37.618),
59 NCGlobalPoint(latitude: 55.751, longitude: 37.619),
60 ]
61 let locationPolygon = NCLocationPolygon(points: ring, sublocationId: 7)
62 print("LocationPolygon: sublocation \‍(locationPolygon.sublocationId ?? -1), vertices \‍(locationPolygon.points.count)")
63 // [swift_LocationPolygon_record]
64
65 // [swift_LocationPolyline_record]
66 let linePts = [
67 NCGlobalPoint(latitude: 55.751, longitude: 37.617),
68 NCGlobalPoint(latitude: 55.753, longitude: 37.620),
69 ]
70 let locationPolyline = NCLocationPolyline(points: linePts, sublocationId: 7)
71 print("LocationPolyline points \‍(locationPolyline.points.count)")
72 // [swift_LocationPolyline_record]
73 }
74
75 /**
76 * Demonstrate circle map objects
77 */
78 private func demonstrateCircleMapObjects() {
79 print("--- Circle Map Objects ---")
80
81 guard let locationWindow = locationWindow else {
82 print("LocationWindow not available yet")
83 return
84 }
85
86 // [swift_CircleMapObject_constructor]
87 // Create circle map object
88 let center = NCGlobalPoint(latitude: 10.0, longitude: 20.0)
89 circleMapObject = locationWindow.addCircleMapObject()
90 print("Created circle map object with center (\‍(center.latitude), \‍(center.longitude)) and radius 5.0")
91 // [swift_CircleMapObject_constructor]
92
93 // [swift_CircleMapObject_getRadius]
94 // Access circle radius
95 let radius = circleMapObject!.getRadius()
96 print("Circle radius: \‍(radius)")
97 // [swift_CircleMapObject_getRadius]
98
99 // [swift_LocationWindow_addCircleMapObject]
100 // Add circle map object
101 circleMapObject = locationWindow.addCircleMapObject()
102 print("Added circle map object")
103 // [swift_LocationWindow_addCircleMapObject]
104
105 if let circleMapObject = circleMapObject {
106 // [swift_CircleMapObject_setPosition]
107 // Set circle position
108 let centerPoint = NCGlobalPoint(latitude: 100.0, longitude: 200.0)
109 let success = circleMapObject.setPosition(centerPoint, sublocationId: 7)
110 print("Set circle position to (\‍(centerPoint.latitude), \‍(centerPoint.longitude)): \‍(success)")
111 // [swift_CircleMapObject_setPosition]
112
113 // [swift_CircleMapObject_setPositionAnimated]
114 // Set circle position with animation
115 let animatedPoint = NCGlobalPoint(latitude: 150.0, longitude: 250.0)
116 let animatedSuccess = circleMapObject.setPositionAnimated(animatedPoint, duration: 2.0, animationType: .linear)
117 print("Set circle position with animation to (\‍(animatedPoint.latitude), \‍(animatedPoint.longitude)): \‍(animatedSuccess)")
118 // [swift_CircleMapObject_setPositionAnimated]
119
120 // [swift_CircleMapObject_setRadius]
121 // Set circle radius
122 let radiusSuccess = circleMapObject.setRadius(10.0)
123 print("Set circle radius to 10.0 meters: \‍(radiusSuccess)")
124 // [swift_CircleMapObject_setRadius]
125
126 // [swift_CircleMapObject_setCollisionEnabled]
127 // Enable collision detection
128 let collisionSuccess = circleMapObject.setCollisionEnabled(true)
129 print("Enabled collision detection for circle: \‍(collisionSuccess)")
130 // [swift_CircleMapObject_setCollisionEnabled]
131
132 // [swift_CircleMapObject_setBuffer]
133 // Set collision buffer
134 let bufferSuccess = circleMapObject.setBuffer(width: 5.0, height: 5.0)
135 print("Set collision buffer to 5x5 pixels: \‍(bufferSuccess)")
136 // [swift_CircleMapObject_setBuffer]
137
138 // [swift_CircleMapObject_setOffset]
139 // Set position offset
140 let offsetSuccess = circleMapObject.setOffset(x: 2.0, longitude: 3.0)
141 print("Set position offset to (2.0, 3.0) pixels: \‍(offsetSuccess)")
142 // [swift_CircleMapObject_setOffset]
143
144 // [swift_CircleMapObject_setOutlineColor]
145 // Set outline color
146 let outlineColorSuccess = circleMapObject.setOutlineColor(UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0))
147 print("Set circle outline color to blue: \‍(outlineColorSuccess)")
148 // [swift_CircleMapObject_setOutlineColor]
149
150 // [swift_CircleMapObject_setOutlineAlpha]
151 // Set outline alpha
152 let outlineAlphaSuccess = circleMapObject.setOutlineAlpha(0.5)
153 print("Set circle outline alpha to 0.5: \‍(outlineAlphaSuccess)")
154 // [swift_CircleMapObject_setOutlineAlpha]
155
156 // [swift_CircleMapObject_setOutlineRadius]
157 // Set outline radius
158 let outlineRadiusSuccess = circleMapObject.setOutlineRadius(2.0)
159 print("Set circle outline radius to 2.0: \‍(outlineRadiusSuccess)")
160 // [swift_CircleMapObject_setOutlineRadius]
161
162 // [swift_CircleMapObject_setColor]
163 // Set circle color
164 let colorSuccess = circleMapObject.setColor(UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8))
165 print("Set circle color to red with 80% opacity: \‍(colorSuccess)")
166 // [swift_CircleMapObject_setColor]
167
168 // [swift_CircleMapObject_setPriority]
169 // Set rendering priority
170 let prioritySuccess = circleMapObject.setPriority(1)
171 print("Set rendering priority to 1: \‍(prioritySuccess)")
172 // [swift_CircleMapObject_setPriority]
173
174 // [swift_MapObject_setVisible]
175 // Set visibility
176 let visibleSuccess = circleMapObject.setVisible(true)
177 print("Set circle visibility to true: \‍(visibleSuccess)")
178 // [swift_MapObject_setVisible]
179
180 // [swift_CircleMapObject_getMapObjectType]
181 // Get map object type
182 let objectType = circleMapObject.mapObjectType
183 print("Circle map object type: \‍(objectType)")
184 // [swift_CircleMapObject_getMapObjectType]
185
186 // [swift_MapObject_setAlpha]
187 // Set alpha transparency
188 let alphaSuccess = circleMapObject.setAlpha(0.7)
189 print("Set circle alpha to 0.7: \‍(alphaSuccess)")
190 // [swift_MapObject_setAlpha]
191
192 // [swift_MapObject_setInteractive]
193 // Set interactive mode
194 let interactiveSuccess = circleMapObject.setInteractive(true)
195 print("Set circle interactive to true: \‍(interactiveSuccess)")
196 // [swift_MapObject_setInteractive]
197
198 // [swift_MapObject_setTitle]
199 // Set title
200 let titleSuccess = circleMapObject.setTitle("Circle Object")
201 print("Set circle title to 'Circle Object': \‍(titleSuccess)")
202 // [swift_MapObject_setTitle]
203
204 // [swift_TitleStyle_record]
205 let titleStyle = NCTitleStyle()
206 titleStyle.fontSize = 14
207 titleStyle.color = "#3366CC"
208 titleStyle.outlineColor = "#FFFFFF"
209 titleStyle.anchor = .top
210 titleStyle.visible = true
211 // [swift_TitleStyle_record]
212
213 // [swift_MapObject_setTitleWithStyle]
214 // Set title with style
215 let titleStyleSuccess = circleMapObject.setTitleWithStyle("Styled Circle", style: titleStyle)
216 print("Set circle title with style: \‍(titleStyleSuccess)")
217 // [swift_MapObject_setTitleWithStyle]
218
219 // [swift_MapObject_setData]
220 // Set custom data
221 let customData = ["key": "value", "number": "42"]
222 let dataSuccess = circleMapObject.setData(customData)
223 print("Set circle custom data: \‍(dataSuccess)")
224 // [swift_MapObject_setData]
225
226 // [swift_MapObject_getId]
227 // Get object ID
228 let objectId = circleMapObject.id
229 print("Circle object ID: \‍(objectId)")
230 // [swift_MapObject_getId]
231
232 // [swift_MapObject_getType]
233 // Get object type
234 let objectTypeString = circleMapObject.type
235 print("Circle object type: \‍(objectTypeString)")
236 // [swift_MapObject_getType]
237
238 // [swift_MapObject_getData]
239 // Get custom data
240 let retrievedData = circleMapObject.data
241 print("Circle custom data: \‍(retrievedData)")
242 // [swift_MapObject_getData]
243 }
244
245 // [swift_LocationWindow_removeCircleMapObject]
246 // Remove circle map object
247 if let circleMapObject = circleMapObject {
248 let removed = locationWindow.removeCircleMapObject(circleMapObject)
249 print("Removed circle map object: \‍(removed)")
250 self.circleMapObject = nil
251 }
252 // [swift_LocationWindow_removeCircleMapObject]
253
254 // Test multiple circle objects
255 var circles: [NCCircleMapObject] = []
256 for i in 0..<3 {
257 if let circle = locationWindow.addCircleMapObject() {
258 circle.setPosition(NCGlobalPoint(latitude: 50.0 * Double(i), longitude: 100.0 * Double(i)), sublocationId: 7)
259 circle.setColor(UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.6))
260 circle.setRadius(5.0 + Double(i) * 2.0)
261 circles.append(circle)
262 print("Created circle \‍(i) at (\‍(50.0 * Double(i)), \‍(100.0 * Double(i))) with radius \‍(5.0 + Double(i) * 2.0)")
263 }
264 }
265
266 for i in circles.indices {
267 locationWindow.removeCircleMapObject(circles[i])
268 print("Removed circle \‍(i)")
269 }
270 }
271
272 /**
273 * Demonstrate icon map objects
274 */
275 private func demonstrateIconMapObjects() {
276 print("--- Icon Map Objects ---")
277
278 guard let locationWindow = locationWindow else {
279 print("LocationWindow not available yet")
280 return
281 }
282
283 // [swift_IconMapObject_constructor]
284 // Create icon map object
285 let position = NCGlobalPoint(latitude: 30.0, longitude: 40.0)
286 iconMapObject = locationWindow.addIconMapObject()
287 print("Created icon map object at (\‍(position.latitude), \‍(position.longitude))")
288 // [swift_IconMapObject_constructor]
289
290 // [swift_LocationWindow_addIconMapObject]
291 // Add icon map object
292 iconMapObject = locationWindow.addIconMapObject()
293 print("Added icon map object")
294 // [swift_LocationWindow_addIconMapObject]
295
296 if let iconMapObject = iconMapObject {
297 // [swift_IconMapObject_setPosition]
298 // Set icon position
299 let position = NCGlobalPoint(latitude: 30.0, longitude: 40.0)
300 let success = iconMapObject.setPosition(position, sublocationId: 7)
301 print("Set icon position to (\‍(position.latitude), \‍(position.longitude)): \‍(success)")
302 // [swift_IconMapObject_setPosition]
303
304 // [swift_IconMapObject_setPositionAnimated]
305 // Set icon position with animation
306 let animatedPosition = NCGlobalPoint(latitude: 35.0, longitude: 45.0)
307 let animatedSuccess = iconMapObject.setPositionAnimated(animatedPosition, duration: 1.5, animationType: .cubic)
308 print("Set icon position with animation to (\‍(animatedPosition.latitude), \‍(animatedPosition.longitude)): \‍(animatedSuccess)")
309 // [swift_IconMapObject_setPositionAnimated]
310
311 // [swift_IconMapObject_setBitmap]
312 if let iconImage = UIImage(contentsOfFile: "/path/to/icon.png") {
313 let bitmapSuccess = iconMapObject.setBitmap(iconImage)
314 print("Set icon bitmap (UIImage): \‍(bitmapSuccess)")
315 }
316 // [swift_IconMapObject_setBitmap]
317
318 // [swift_IconMapObject_setFlat]
319 // Set icon flat mode
320 let flatSuccess = iconMapObject.setFlat(true)
321 print("Set icon flat mode to true: \‍(flatSuccess)")
322 // [swift_IconMapObject_setFlat]
323
324 // [swift_IconMapObject_setSize]
325 // Set icon size
326 let size = NCSize(width: 32.0, height: 32.0)
327 let sizeSuccess = iconMapObject.setSize(size)
328 print("Set icon size to (\‍(size.width), \‍(size.height)): \‍(sizeSuccess)")
329 // [swift_IconMapObject_setSize]
330
331 // [swift_IconMapObject_setAngle]
332 // Set icon rotation angle (radians)
333 let angleSuccess = iconMapObject.setAngle(Float.pi / 4)
334 print("Set icon rotation angle to π/4: \‍(angleSuccess)")
335 // [swift_IconMapObject_setAngle]
336
337 // [swift_IconMapObject_setAngleAnimated]
338 // Set icon rotation with animation (radians)
339 let angleAnimatedSuccess = iconMapObject.setAngleAnimated(Float.pi / 2, duration: 2.0, animationType: .sine)
340 print("Set icon rotation with animation to π/2: \‍(angleAnimatedSuccess)")
341 // [swift_IconMapObject_setAngleAnimated]
342
343 // [swift_IconMapObject_setCollisionEnabled]
344 // Enable collision detection
345 let collisionSuccess = iconMapObject.setCollisionEnabled(true)
346 print("Enabled collision detection for icon: \‍(collisionSuccess)")
347 // [swift_IconMapObject_setCollisionEnabled]
348
349 // [swift_IconMapObject_setBuffer]
350 // Set collision buffer
351 let bufferSuccess = iconMapObject.setBuffer(width: 10.0, height: 10.0)
352 print("Set collision buffer to 10x10 pixels: \‍(bufferSuccess)")
353 // [swift_IconMapObject_setBuffer]
354
355 // [swift_IconMapObject_setOffset]
356 // Set position offset
357 let offsetSuccess = iconMapObject.setOffset(x: 0.0, longitude: -16.0)
358 print("Set position offset to (0.0, -16.0) pixels: \‍(offsetSuccess)")
359 // [swift_IconMapObject_setOffset]
360
361 // [swift_IconMapObject_setPriority]
362 // Set rendering priority
363 let prioritySuccess = iconMapObject.setPriority(2)
364 print("Set rendering priority to 2: \‍(prioritySuccess)")
365 // [swift_IconMapObject_setPriority]
366
367 // [swift_IconMapObject_setVisible]
368 // Set visibility
369 let visibleSuccess = iconMapObject.setVisible(true)
370 print("Set icon visibility to true: \‍(visibleSuccess)")
371 // [swift_IconMapObject_setVisible]
372
373 // [swift_IconMapObject_getMapObjectType]
374 // Get map object type
375 let objectType = iconMapObject.mapObjectType
376 print("Icon map object type: \‍(objectType)")
377 // [swift_IconMapObject_getMapObjectType]
378
379 // [swift_MapObject_setAlpha_1]
380 // Set alpha transparency
381 let alphaSuccess = iconMapObject.setAlpha(0.8)
382 print("Set icon alpha to 0.8: \‍(alphaSuccess)")
383 // [swift_MapObject_setAlpha_1]
384
385 // [swift_MapObject_setInteractive_1]
386 // Set interactive mode
387 let interactiveSuccess = iconMapObject.setInteractive(true)
388 print("Set icon interactive to true: \‍(interactiveSuccess)")
389 // [swift_MapObject_setInteractive_1]
390
391 // [swift_MapObject_setTitle_1]
392 // Set title
393 let titleSuccess = iconMapObject.setTitle("Icon Object")
394 print("Set icon title to 'Icon Object': \‍(titleSuccess)")
395 // [swift_MapObject_setTitle_1]
396
397 // [swift_MapObject_setData_1]
398 // Set custom data
399 let customData = ["key": "value", "number": "42"]
400 let dataSuccess = iconMapObject.setData(customData)
401 print("Set icon custom data: \‍(dataSuccess)")
402 // [swift_MapObject_setData_1]
403
404 // [swift_MapObject_getId_1]
405 // Get object ID
406 let objectId = iconMapObject.id
407 print("Icon object ID: \‍(objectId)")
408 // [swift_MapObject_getId_1]
409
410 // [swift_MapObject_getType_1]
411 // Get object type
412 let objectTypeString = iconMapObject.type
413 print("Icon object type: \‍(objectTypeString)")
414 // [swift_MapObject_getType_1]
415
416 // [swift_MapObject_getData_1]
417 // Get custom data
418 let retrievedData = iconMapObject.data
419 print("Icon custom data: \‍(retrievedData)")
420 // [swift_MapObject_getData_1]
421 }
422
423 // [swift_LocationWindow_removeIconMapObject]
424 // Remove icon map object
425 if let iconMapObject = iconMapObject {
426 let removed = locationWindow.removeIconMapObject(iconMapObject)
427 print("Removed icon map object: \‍(removed)")
428 self.iconMapObject = nil
429 }
430 // [swift_LocationWindow_removeIconMapObject]
431
432 // Test multiple icon objects
433 var icons: [NCIconMapObject] = []
434 for i in 0..<3 {
435 if let icon = locationWindow.addIconMapObject() {
436 icon.setPosition(NCGlobalPoint(latitude: 60.0 * Double(i), longitude: 120.0 * Double(i)), sublocationId: 7)
437 if let img = UIImage(contentsOfFile: "/path/to/icon.png") {
438 _ = icon.setBitmap(img)
439 }
440 icon.setSize(NCSize(width: 24.0, height: 24.0))
441 icons.append(icon)
442 print("Created icon \‍(i) at (\‍(60.0 * Double(i)), \‍(120.0 * Double(i)))")
443 }
444 }
445
446 for i in icons.indices {
447 locationWindow.removeIconMapObject(icons[i])
448 print("Removed icon \‍(i)")
449 }
450 }
451
452 /**
453 * 3D model map objects (OBJ + texture via ModelProvider / NCModelProviderFactory).
454 */
455 private func demonstrateModelMapObjects() {
456 print("--- Model Map Objects ---")
457
458 guard let locationWindow = locationWindow else {
459 print("LocationWindow not available yet")
460 return
461 }
462
463 // [swift_LocationWindow_addModelMapObject]
464 modelMapObject = locationWindow.addModelMapObject()
465 print("Added model map object: \‍(modelMapObject != nil)")
466 // [swift_LocationWindow_addModelMapObject]
467
468 guard let m = modelMapObject else { return }
469
470 // [swift_ModelMapObject_setPosition]
471 let posOk = m.setPosition(NCGlobalPoint(latitude: 12.0, longitude: 34.0), sublocationId: 7)
472 print("Model setPosition: \‍(posOk)")
473 // [swift_ModelMapObject_setPosition]
474
475 // [swift_ModelMapObject_setPositionAnimated]
476 let posAnimOk = m.setPositionAnimated(
477 NCGlobalPoint(latitude: 15.0, longitude: 40.0),
478 duration: 0.5,
479 animationType: .sine
480 )
481 print("Model setPositionAnimated: \‍(posAnimOk)")
482 // [swift_ModelMapObject_setPositionAnimated]
483
484 // [swift_ModelMapObject_setModel]
485 if let texture = UIImage(contentsOfFile: "/path/to/model_texture.png") {
486 let provider = NCModelProviderFactory.fromFile("/path/to/model.obj", texture: texture)
487 let modelOk = m.setModel(provider)
488 print("Model setModel: \‍(modelOk)")
489 }
490 // [swift_ModelMapObject_setModel]
491
492 // [swift_ModelMapObject_setSize]
493 let sizeOk = m.setSize(width: 64.0, height: 64.0)
494 print("Model setSize: \‍(sizeOk)")
495 // [swift_ModelMapObject_setSize]
496
497 // [swift_ModelMapObject_setCollisionEnabled]
498 let collOk = m.setCollisionEnabled(true)
499 print("Model setCollisionEnabled: \‍(collOk)")
500 // [swift_ModelMapObject_setCollisionEnabled]
501
502 // [swift_ModelMapObject_setAngle]
503 let angleOk = m.setAngle(Float.pi / 4)
504 print("Model setAngle: \‍(angleOk)")
505 // [swift_ModelMapObject_setAngle]
506
507 // [swift_ModelMapObject_setAngleAnimated]
508 let angleAnimOk = m.setAngleAnimated(Float.pi / 2, duration: 0.5, animationType: .quint)
509 print("Model setAngleAnimated: \‍(angleAnimOk)")
510 // [swift_ModelMapObject_setAngleAnimated]
511
512 // [swift_ModelMapObject_setBuffer]
513 let bufOk = m.setBuffer(width: 4.0, height: 4.0)
514 print("Model setBuffer: \‍(bufOk)")
515 // [swift_ModelMapObject_setBuffer]
516
517 // [swift_ModelMapObject_setPriority]
518 let priOk = m.setPriority(10.0)
519 print("Model setPrioritlongitude: \‍(priOk)")
520 // [swift_ModelMapObject_setPriority]
521
522 // [swift_LocationWindow_removeModelMapObject]
523 let removed = locationWindow.removeModelMapObject(m)
524 print("Removed model map object: \‍(removed)")
525 modelMapObject = nil
526 // [swift_LocationWindow_removeModelMapObject]
527 }
528
529 /**
530 * Demonstrate polygon map objects
531 */
532 private func demonstratePolygonMapObjects() {
533 print("--- Polygon Map Objects ---")
534
535 guard let locationWindow = locationWindow else {
536 print("LocationWindow not available yet")
537 return
538 }
539
540 // [swift_LocationWindow_addPolygonMapObject]
541 // Add polygon map object
542 polygonMapObject = locationWindow.addPolygonMapObject()
543 print("Added polygon map object")
544 // [swift_LocationWindow_addPolygonMapObject]
545
546 if let polygonMapObject = polygonMapObject {
547 // [swift_PolygonMapObject_setPolygon]
548 // Set polygon geometry
549 let points = [
550 NCGlobalPoint(latitude: 50.0, longitude: 60.0),
551 NCGlobalPoint(latitude: 55.0, longitude: 65.0),
552 NCGlobalPoint(latitude: 60.0, longitude: 60.0),
553 NCGlobalPoint(latitude: 55.0, longitude: 55.0),
554 ]
555 let polygon = NCLocationPolygon(points: points, sublocationId: 0)
556 let success = polygonMapObject.setPolygon(polygon)
557 print("Set polygon with \‍(points.count) points: \‍(success)")
558 // [swift_PolygonMapObject_setPolygon]
559
560 // [swift_PolygonMapObject_setColor]
561 // Set polygon color
562 let colorSuccess = polygonMapObject.setColor(UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.7))
563 print("Set polygon color to green with 70% opacity: \‍(colorSuccess)")
564 // [swift_PolygonMapObject_setColor]
565
566 // [swift_PolygonMapObject_setOrder]
567 // Set polygon rendering order
568 let orderSuccess = polygonMapObject.setOrder(2)
569 print("Set polygon rendering order to 2: \‍(orderSuccess)")
570 // [swift_PolygonMapObject_setOrder]
571
572 // [swift_PolygonMapObject_setOutlineColor]
573 // Set polygon outline color
574 let outlineColorSuccess = polygonMapObject.setOutlineColor(UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0))
575 print("Set polygon outline color to blue: \‍(outlineColorSuccess)")
576 // [swift_PolygonMapObject_setOutlineColor]
577
578 // [swift_PolygonMapObject_setOutlineWidth]
579 // Set polygon outline width
580 let outlineWidthSuccess = polygonMapObject.setOutlineWidth(2.0)
581 print("Set polygon outline width to 2.0 pixels: \‍(outlineWidthSuccess)")
582 // [swift_PolygonMapObject_setOutlineWidth]
583
584 // [swift_PolygonMapObject_setOutlineAlpha]
585 // Set polygon outline alpha
586 let outlineAlphaSuccess = polygonMapObject.setOutlineAlpha(0.8)
587 print("Set polygon outline alpha to 0.8: \‍(outlineAlphaSuccess)")
588 // [swift_PolygonMapObject_setOutlineAlpha]
589
590 // [swift_PolygonMapObject_setOutlineOrder]
591 // Set polygon outline order
592 let outlineOrderSuccess = polygonMapObject.setOutlineOrder(1)
593 print("Set polygon outline order to 1: \‍(outlineOrderSuccess)")
594 // [swift_PolygonMapObject_setOutlineOrder]
595
596 // [swift_PolygonMapObject_setVisible]
597 // Set visibility
598 let visibleSuccess = polygonMapObject.setVisible(true)
599 print("Set polygon visibility to true: \‍(visibleSuccess)")
600 // [swift_PolygonMapObject_setVisible]
601
602 // [swift_PolygonMapObject_getMapObjectType]
603 // Get map object type
604 let objectType = polygonMapObject.mapObjectType
605 print("Polygon map object type: \‍(objectType)")
606 // [swift_PolygonMapObject_getMapObjectType]
607
608 // [swift_MapObject_setAlpha_2]
609 // Set alpha transparency
610 let alphaSuccess = polygonMapObject.setAlpha(0.6)
611 print("Set polygon alpha to 0.6: \‍(alphaSuccess)")
612 // [swift_MapObject_setAlpha_2]
613
614 // [swift_MapObject_setInteractive_2]
615 // Set interactive mode
616 let interactiveSuccess = polygonMapObject.setInteractive(true)
617 print("Set polygon interactive to true: \‍(interactiveSuccess)")
618 // [swift_MapObject_setInteractive_2]
619
620 // [swift_MapObject_setTitle_2]
621 // Set title
622 let titleSuccess = polygonMapObject.setTitle("Polygon Object")
623 print("Set polygon title to 'Polygon Object': \‍(titleSuccess)")
624 // [swift_MapObject_setTitle_2]
625
626 // [swift_MapObject_setData_2]
627 // Set custom data
628 let customData = ["key": "value", "number": "42"]
629 let dataSuccess = polygonMapObject.setData(customData)
630 print("Set polygon custom data: \‍(dataSuccess)")
631 // [swift_MapObject_setData_2]
632
633 // [swift_MapObject_getId_2]
634 // Get object ID
635 let objectId = polygonMapObject.id
636 print("Polygon object ID: \‍(objectId)")
637 // [swift_MapObject_getId_2]
638
639 // [swift_MapObject_getType_2]
640 // Get object type
641 let objectTypeString = polygonMapObject.type
642 print("Polygon object type: \‍(objectTypeString)")
643 // [swift_MapObject_getType_2]
644
645 // [swift_MapObject_getData_2]
646 // Get custom data
647 let retrievedData = polygonMapObject.data
648 print("Polygon custom data: \‍(retrievedData)")
649 // [swift_MapObject_getData_2]
650 }
651
652 // [swift_LocationWindow_removePolygonMapObject]
653 // Remove polygon map object
654 if let polygonMapObject = polygonMapObject {
655 let removed = locationWindow.removePolygonMapObject(polygonMapObject)
656 print("Removed polygon map object: \‍(removed)")
657 self.polygonMapObject = nil
658 }
659 // [swift_LocationWindow_removePolygonMapObject]
660
661 // Test multiple polygon objects
662 var polygons: [NCPolygonMapObject] = []
663 for i in 0..<3 {
664 if let polygon = locationWindow.addPolygonMapObject() {
665 let points = [
666 NCGlobalPoint(latitude: 300.0 + Double(i) * 50, longitude: 400.0 + Double(i) * 50),
667 NCGlobalPoint(latitude: 350.0 + Double(i) * 50, longitude: 450.0 + Double(i) * 50),
668 NCGlobalPoint(latitude: 400.0 + Double(i) * 50, longitude: 400.0 + Double(i) * 50),
669 NCGlobalPoint(latitude: 350.0 + Double(i) * 50, longitude: 350.0 + Double(i) * 50),
670 ]
671 let polygonGeometry = NCLocationPolygon(points: points, sublocationId: 0)
672 polygon.setPolygon(polygonGeometry)
673 polygon.setColor(UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.5))
674 polygons.append(polygon)
675 print("Created polygon \‍(i) with \‍(points.count) points")
676 }
677 }
678
679 for i in polygons.indices {
680 locationWindow.removePolygonMapObject(polygons[i])
681 print("Removed polygon \‍(i)")
682 }
683 }
684
685 /**
686 * Demonstrate polyline map objects
687 */
688 private func demonstratePolylineMapObjects() {
689 print("--- Polyline Map Objects ---")
690
691 guard let locationWindow = locationWindow else {
692 print("LocationWindow not available yet")
693 return
694 }
695
696 // [swift_PolylineMapObject_constructor]
697 // Create polyline map object
698 let points = [
699 NCGlobalPoint(latitude: 100.0, longitude: 110.0),
700 NCGlobalPoint(latitude: 105.0, longitude: 115.0),
701 NCGlobalPoint(latitude: 110.0, longitude: 120.0),
702 NCGlobalPoint(latitude: 115.0, longitude: 125.0),
703 ]
704 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
705 polylineMapObject = locationWindow.addPolylineMapObject()
706 print("Created polyline map object with \‍(points.count) points")
707 // [swift_PolylineMapObject_constructor]
708
709 // [swift_PolylineMapObject_getPolyline]
710 // Access polyline
711 let polylineShape = polylineMapObject!.getPolyLine()
712 print("Polyline has \‍(polylineShape.polyline.points.count) points")
713 // [swift_PolylineMapObject_getPolyline]
714
715 // [swift_LocationWindow_addPolylineMapObject]
716 // Add polyline map object
717 polylineMapObject = locationWindow.addPolylineMapObject()
718 print("Added polyline map object")
719 // [swift_LocationWindow_addPolylineMapObject]
720
721 if let polylineMapObject = polylineMapObject {
722 // [swift_PolylineMapObject_setPolyLine]
723 // Set polyline geometry
724 let points = [
725 NCGlobalPoint(latitude: 100.0, longitude: 110.0),
726 NCGlobalPoint(latitude: 105.0, longitude: 115.0),
727 NCGlobalPoint(latitude: 110.0, longitude: 120.0),
728 NCGlobalPoint(latitude: 115.0, longitude: 125.0),
729 ]
730 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
731 let success = polylineMapObject.setPolyLine(polyline)
732 print("Set polyline with \‍(points.count) points: \‍(success)")
733 // [swift_PolylineMapObject_setPolyLine]
734
735 // [swift_PolylineMapObject_setWidth]
736 // Set polyline width
737 let widthSuccess = polylineMapObject.setWidth(3.0)
738 print("Set polyline width to 3.0 pixels: \‍(widthSuccess)")
739 // [swift_PolylineMapObject_setWidth]
740
741 // [swift_PolylineMapObject_setColor]
742 // Set polyline color
743 let colorSuccess = polylineMapObject.setColor(UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.8))
744 print("Set polyline color to green with 80% opacity: \‍(colorSuccess)")
745 // [swift_PolylineMapObject_setColor]
746
747 // [swift_PolylineMapObject_setOrder]
748 // Set polyline rendering order
749 let orderSuccess = polylineMapObject.setOrder(1)
750 print("Set polyline rendering order to 1: \‍(orderSuccess)")
751 // [swift_PolylineMapObject_setOrder]
752
753 // [swift_PolylineMapObject_setCapType]
754 // Set polyline cap type
755 let capTypeSuccess = polylineMapObject.setCapType(.round)
756 print("Set polyline cap type to ROUND: \‍(capTypeSuccess)")
757 // [swift_PolylineMapObject_setCapType]
758
759 // [swift_PolylineMapObject_setJoinType]
760 // Set polyline join type
761 let joinTypeSuccess = polylineMapObject.setJoinType(.round)
762 print("Set polyline join type to ROUND: \‍(joinTypeSuccess)")
763 // [swift_PolylineMapObject_setJoinType]
764
765 // [swift_PolylineMapObject_setMiterLimit]
766 // Set polyline miter limit
767 let miterLimitSuccess = polylineMapObject.setMiterLimit(2.0)
768 print("Set polyline miter limit to 2.0: \‍(miterLimitSuccess)")
769 // [swift_PolylineMapObject_setMiterLimit]
770
771 // [swift_PolylineMapObject_setOutlineWidth]
772 // Set polyline outline width
773 let outlineWidthSuccess = polylineMapObject.setOutlineWidth(1.0)
774 print("Set polyline outline width to 1.0 pixels: \‍(outlineWidthSuccess)")
775 // [swift_PolylineMapObject_setOutlineWidth]
776
777 // [swift_PolylineMapObject_setOutlineColor]
778 // Set polyline outline color
779 let outlineColorSuccess = polylineMapObject.setOutlineColor(UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0))
780 print("Set polyline outline color to black: \‍(outlineColorSuccess)")
781 // [swift_PolylineMapObject_setOutlineColor]
782
783 // [swift_PolylineMapObject_setOutlineAlpha]
784 // Set polyline outline alpha
785 let outlineAlphaSuccess = polylineMapObject.setOutlineAlpha(0.5)
786 print("Set polyline outline alpha to 0.5: \‍(outlineAlphaSuccess)")
787 // [swift_PolylineMapObject_setOutlineAlpha]
788
789 // [swift_PolylineMapObject_setOutlineOrder]
790 // Set polyline outline rendering order
791 let outlineOrderSuccess = polylineMapObject.setOutlineOrder(0)
792 print("Set polyline outline rendering order to 0: \‍(outlineOrderSuccess)")
793 // [swift_PolylineMapObject_setOutlineOrder]
794
795 // [swift_PolylineMapObject_setOutlineCapType]
796 // Set polyline outline cap type
797 let outlineCapTypeSuccess = polylineMapObject.setOutlineCapType(.square)
798 print("Set polyline outline cap type to SQUARE: \‍(outlineCapTypeSuccess)")
799 // [swift_PolylineMapObject_setOutlineCapType]
800
801 // [swift_PolylineMapObject_setOutlineJoinType]
802 // Set polyline outline join type
803 let outlineJoinTypeSuccess = polylineMapObject.setOutlineJoinType(.miter)
804 print("Set polyline outline join type to MITER: \‍(outlineJoinTypeSuccess)")
805 // [swift_PolylineMapObject_setOutlineJoinType]
806
807 // [swift_PolylineMapObject_setOutlineMiterLimit]
808 // Set polyline outline miter limit
809 let outlineMiterLimitSuccess = polylineMapObject.setOutlineMiterLimit(3.0)
810 print("Set polyline outline miter limit to 3.0: \‍(outlineMiterLimitSuccess)")
811 // [swift_PolylineMapObject_setOutlineMiterLimit]
812
813 // [swift_PolylineMapObject_setVisible]
814 // Set visibility
815 let visibleSuccess = polylineMapObject.setVisible(true)
816 print("Set polyline visibility to true: \‍(visibleSuccess)")
817 // [swift_PolylineMapObject_setVisible]
818
819 // [swift_PolylineMapObject_getMapObjectType]
820 // Get map object type
821 let objectType = polylineMapObject.mapObjectType
822 print("Polyline map object type: \‍(objectType)")
823 // [swift_PolylineMapObject_getMapObjectType]
824
825 // [swift_MapObject_setAlpha_3]
826 // Set alpha transparency
827 let alphaSuccess = polylineMapObject.setAlpha(0.7)
828 print("Set polyline alpha to 0.7: \‍(alphaSuccess)")
829 // [swift_MapObject_setAlpha_3]
830
831 // [swift_MapObject_setInteractive_3]
832 // Set interactive mode
833 let interactiveSuccess = polylineMapObject.setInteractive(true)
834 print("Set polyline interactive to true: \‍(interactiveSuccess)")
835 // [swift_MapObject_setInteractive_3]
836
837 // [swift_MapObject_setTitle_3]
838 // Set title
839 let titleSuccess = polylineMapObject.setTitle("Polyline Object")
840 print("Set polyline title to 'Polyline Object': \‍(titleSuccess)")
841 // [swift_MapObject_setTitle_3]
842
843 // [swift_MapObject_setData_3]
844 // Set custom data
845 let customData = ["key": "value", "number": "42"]
846 let dataSuccess = polylineMapObject.setData(customData)
847 print("Set polyline custom data: \‍(dataSuccess)")
848 // [swift_MapObject_setData_3]
849
850 // [swift_MapObject_getId_3]
851 // Get object ID
852 let objectId = polylineMapObject.id
853 print("Polyline object ID: \‍(objectId)")
854 // [swift_MapObject_getId_3]
855
856 // [swift_MapObject_getType_3]
857 // Get object type
858 let objectTypeString = polylineMapObject.type
859 print("Polyline object type: \‍(objectTypeString)")
860 // [swift_MapObject_getType_3]
861
862 // [swift_MapObject_getData_3]
863 // Get custom data
864 let retrievedData = polylineMapObject.data
865 print("Polyline custom data: \‍(retrievedData)")
866 // [swift_MapObject_getData_3]
867 }
868
869 // [swift_LocationWindow_removePolylineMapObject]
870 // Remove polyline map object
871 if let polylineMapObject = polylineMapObject {
872 let removed = locationWindow.removePolylineMapObject(polylineMapObject)
873 print("Removed polyline map object: \‍(removed)")
874 self.polylineMapObject = nil
875 }
876 // [swift_LocationWindow_removePolylineMapObject]
877
878 // Test multiple polyline objects
879 var polylines: [NCPolylineMapObject] = []
880 for i in 0..<3 {
881 if let polyline = locationWindow.addPolylineMapObject() {
882 let points = [
883 NCGlobalPoint(latitude: 120.0 + Double(i) * 30, longitude: 130.0 + Double(i) * 30),
884 NCGlobalPoint(latitude: 125.0 + Double(i) * 30, longitude: 135.0 + Double(i) * 30),
885 NCGlobalPoint(latitude: 130.0 + Double(i) * 30, longitude: 140.0 + Double(i) * 30),
886 ]
887 let polylineGeometry = NCLocationPolyline(points: points, sublocationId: 0)
888 polyline.setPolyLine(polylineGeometry)
889 polyline.setColor(UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6))
890 polyline.setWidth(2.0)
891 polylines.append(polyline)
892 print("Created polyline \‍(i) with \‍(points.count) points")
893 }
894 }
895
896 for i in polylines.indices {
897 locationWindow.removePolylineMapObject(polylines[i])
898 print("Removed polyline \‍(i)")
899 }
900 }
901
902 /**
903 * Demonstrate dotted polyline map objects
904 */
905 private func demonstrateDottedPolylineMapObjects() {
906 print("--- Dotted Polyline Map Objects ---")
907
908 guard let locationWindow = locationWindow else {
909 print("LocationWindow not available yet")
910 return
911 }
912
913 // [swift_DottedPolylineMapObject_constructor]
914 // Create dotted polyline map object
915 let points = [
916 NCGlobalPoint(latitude: 160.0, longitude: 170.0),
917 NCGlobalPoint(latitude: 165.0, longitude: 175.0),
918 NCGlobalPoint(latitude: 170.0, longitude: 180.0),
919 NCGlobalPoint(latitude: 175.0, longitude: 185.0),
920 ]
921 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
922 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
923 print("Created dotted polyline map object with \‍(points.count) points")
924 // [swift_DottedPolylineMapObject_constructor]
925
926 // [swift_DottedPolylineMapObject_getPolyline]
927 // Access dotted polyline
928 let dottedPolylineShape = dottedPolylineMapObject!.getPolyLine()
929 print("Dotted polyline has \‍(dottedPolylineShape.polyline.points.count) points")
930 // [swift_DottedPolylineMapObject_getPolyline]
931
932 // [swift_LocationWindow_addDottedPolylineMapObject]
933 // Add dotted polyline map object
934 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
935 print("Added dotted polyline map object")
936 // [swift_LocationWindow_addDottedPolylineMapObject]
937
938 if let dottedPolylineMapObject = dottedPolylineMapObject {
939 // [swift_DottedPolylineMapObject_setPolyline]
940 // Set dotted polyline geometry
941 let points = [
942 NCGlobalPoint(latitude: 160.0, longitude: 170.0),
943 NCGlobalPoint(latitude: 165.0, longitude: 175.0),
944 NCGlobalPoint(latitude: 170.0, longitude: 180.0),
945 NCGlobalPoint(latitude: 175.0, longitude: 185.0),
946 ]
947 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
948 let success = dottedPolylineMapObject.setPolyline(polyline)
949 print("Set dotted polyline with \‍(points.count) points: \‍(success)")
950 // [swift_DottedPolylineMapObject_setPolyline]
951
952 // [swift_DottedPolylineMapObject_setColor]
953 // Set dotted polyline color
954 let colorSuccess = dottedPolylineMapObject.setColor(UIColor(red: 0.5, green: 0.0, blue: 1.0, alpha: 0.8))
955 print("Set dotted polyline color to purple with 80% opacity: \‍(colorSuccess)")
956 // [swift_DottedPolylineMapObject_setColor]
957
958 // [swift_DottedPolylineMapObject_setWidth]
959 // Set dotted polyline width
960 let widthSuccess = dottedPolylineMapObject.setWidth(3.0)
961 print("Set dotted polyline width to 3.0 pixels: \‍(widthSuccess)")
962 // [swift_DottedPolylineMapObject_setWidth]
963
964 // [swift_DottedPolylineMapObject_setOrder]
965 // Set dotted polyline rendering order
966 let orderSuccess = dottedPolylineMapObject.setOrder(2)
967 print("Set dotted polyline rendering order to 2: \‍(orderSuccess)")
968 // [swift_DottedPolylineMapObject_setOrder]
969
970 // [swift_DottedPolylineMapObject_setCollisionEnabled]
971 // Enable collision detection
972 let dottedCollisionSuccess = dottedPolylineMapObject.setCollisionEnabled(true)
973 print("Enabled collision detection for dotted polyline: \‍(dottedCollisionSuccess)")
974 // [swift_DottedPolylineMapObject_setCollisionEnabled]
975
976 // [swift_DottedPolylineMapObject_setPlacement]
977 // Set placement type
978 let dottedPlacementSuccess = dottedPolylineMapObject.setPlacement(.center)
979 print("Set dotted polyline placement to CENTER: \‍(dottedPlacementSuccess)")
980 // [swift_DottedPolylineMapObject_setPlacement]
981
982 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
983 // Set placement min ratio
984 let dottedMinRatioSuccess = dottedPolylineMapObject.setPlacementMinRatio(0.5)
985 print("Set dotted polyline placement min ratio to 0.5: \‍(dottedMinRatioSuccess)")
986 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
987
988 // [swift_DottedPolylineMapObject_setPlacementSpacing]
989 // Set placement spacing
990 let dottedSpacingSuccess = dottedPolylineMapObject.setPlacementSpacing(10.0)
991 print("Set dotted polyline placement spacing to 10.0: \‍(dottedSpacingSuccess)")
992 // [swift_DottedPolylineMapObject_setPlacementSpacing]
993
994 // [swift_DottedPolylineMapObject_setPriority]
995 // Set rendering priority
996 let dottedPrioritySuccess = dottedPolylineMapObject.setPriority(1)
997 print("Set dotted polyline rendering priority to 1: \‍(dottedPrioritySuccess)")
998 // [swift_DottedPolylineMapObject_setPriority]
999
1000 // [swift_DottedPolylineMapObject_setRepeatDistance]
1001 // Set repeat distance
1002 let dottedRepeatDistanceSuccess = dottedPolylineMapObject.setRepeatDistance(20.0)
1003 print("Set dotted polyline repeat distance to 20.0: \‍(dottedRepeatDistanceSuccess)")
1004 // [swift_DottedPolylineMapObject_setRepeatDistance]
1005
1006 // [swift_DottedPolylineMapObject_setRepeatGroup]
1007 // Set repeat group
1008 let dottedRepeatGroupSuccess = dottedPolylineMapObject.setRepeatGroup(1)
1009 print("Set dotted polyline repeat group to 1: \‍(dottedRepeatGroupSuccess)")
1010 // [swift_DottedPolylineMapObject_setRepeatGroup]
1011
1012 // [swift_DottedPolylineMapObject_setSize]
1013 // Set size
1014 let dottedSize = NCSize(width: 16.0, height: 16.0)
1015 let dottedSizeSuccess = dottedPolylineMapObject.setSize(dottedSize)
1016 print("Set dotted polyline size to (\‍(dottedSize.width), \‍(dottedSize.height)): \‍(dottedSizeSuccess)")
1017 // [swift_DottedPolylineMapObject_setSize]
1018
1019 // [swift_DottedPolylineMapObject_setVisible]
1020 // Set visibility
1021 let visibleSuccess = dottedPolylineMapObject.setVisible(true)
1022 print("Set dotted polyline visibility to true: \‍(visibleSuccess)")
1023 // [swift_DottedPolylineMapObject_setVisible]
1024
1025 // [swift_DottedPolylineMapObject_getMapObjectType]
1026 // Get map object type
1027 let objectType = dottedPolylineMapObject.mapObjectType
1028 print("Dotted polyline map object type: \‍(objectType)")
1029 // [swift_DottedPolylineMapObject_getMapObjectType]
1030
1031 // [swift_MapObject_setAlpha_4]
1032 // Set alpha transparency
1033 let alphaSuccess = dottedPolylineMapObject.setAlpha(0.8)
1034 print("Set dotted polyline alpha to 0.8: \‍(alphaSuccess)")
1035 // [swift_MapObject_setAlpha_4]
1036
1037 // [swift_MapObject_setInteractive_4]
1038 // Set interactive mode
1039 let interactiveSuccess = dottedPolylineMapObject.setInteractive(true)
1040 print("Set dotted polyline interactive to true: \‍(interactiveSuccess)")
1041 // [swift_MapObject_setInteractive_4]
1042
1043 // [swift_MapObject_setTitle_4]
1044 // Set title
1045 let titleSuccess = dottedPolylineMapObject.setTitle("Dotted Polyline Object")
1046 print("Set dotted polyline title to 'Dotted Polyline Object': \‍(titleSuccess)")
1047 // [swift_MapObject_setTitle_4]
1048
1049 // [swift_MapObject_setData_4]
1050 // Set custom data
1051 let customData = ["key": "value", "number": "42"]
1052 let dataSuccess = dottedPolylineMapObject.setData(customData)
1053 print("Set dotted polyline custom data: \‍(dataSuccess)")
1054 // [swift_MapObject_setData_4]
1055
1056 // [swift_MapObject_getId_4]
1057 // Get object ID
1058 let objectId = dottedPolylineMapObject.id
1059 print("Dotted polyline object ID: \‍(objectId)")
1060 // [swift_MapObject_getId_4]
1061
1062 // [swift_MapObject_getType_4]
1063 // Get object type
1064 let objectTypeString = dottedPolylineMapObject.type
1065 print("Dotted polyline object type: \‍(objectTypeString)")
1066 // [swift_MapObject_getType_4]
1067
1068 // [swift_MapObject_getData_4]
1069 // Get custom data
1070 let retrievedData = dottedPolylineMapObject.data
1071 print("Dotted polyline custom data: \‍(retrievedData)")
1072 // [swift_MapObject_getData_4]
1073 }
1074
1075 // [swift_LocationWindow_removeDottedPolylineMapObject]
1076 // Remove dotted polyline map object
1077 if let dottedPolylineMapObject = dottedPolylineMapObject {
1078 let removed = locationWindow.removeDottedPolylineMapObject(dottedPolylineMapObject)
1079 print("Removed dotted polyline map object: \‍(removed)")
1080 self.dottedPolylineMapObject = nil
1081 }
1082 // [swift_LocationWindow_removeDottedPolylineMapObject]
1083
1084 // Test multiple dotted polyline objects
1085 var dottedPolylines: [NCDottedPolylineMapObject] = []
1086 for i in 0..<3 {
1087 if let dottedPolyline = locationWindow.addDottedPolylineMapObject() {
1088 let points = [
1089 NCGlobalPoint(latitude: 180.0 + Double(i) * 30, longitude: 190.0 + Double(i) * 30),
1090 NCGlobalPoint(latitude: 185.0 + Double(i) * 30, longitude: 195.0 + Double(i) * 30),
1091 NCGlobalPoint(latitude: 190.0 + Double(i) * 30, longitude: 200.0 + Double(i) * 30),
1092 ]
1093 let polylineGeometry = NCLocationPolyline(points: points, sublocationId: 0)
1094 dottedPolyline.setPolyline(polylineGeometry)
1095 dottedPolylines.append(dottedPolyline)
1096 print("Created dotted polyline \‍(i) with \‍(points.count) points")
1097 }
1098 }
1099
1100 for i in dottedPolylines.indices {
1101 locationWindow.removeDottedPolylineMapObject(dottedPolylines[i])
1102 print("Removed dotted polyline \‍(i)")
1103 }
1104 }
1105
1106 /**
1107 * Demonstrate icon clustering via ClusterMapObjectController.
1108 */
1109 private func demonstrateClusterMapObjects() {
1110 print("--- Cluster map objects ---")
1111
1112 guard let locationWindow = locationWindow else {
1113 print("LocationWindow not available")
1114 return
1115 }
1116
1117 // [swift_LocationWindow_addClusterMapObjectController]
1118 clusterMapObjectController = locationWindow.addClusterMapObjectController()
1119 print("Added cluster map object controller")
1120 // [swift_LocationWindow_addClusterMapObjectController]
1121
1122 guard let controller = clusterMapObjectController else { return }
1123
1124 let clusterIcon1 = locationWindow.addIconMapObject()
1125 let clusterIcon2 = locationWindow.addIconMapObject()
1126 clusterIcon1?.setPosition(NCGlobalPoint(latitude: 100.0, longitude: 100.0), sublocationId: 7)
1127 clusterIcon2?.setPosition(NCGlobalPoint(latitude: 105.0, longitude: 102.0), sublocationId: 7)
1128
1129 // [swift_ClusterMapObjectController_addIconMapObject]
1130 let added1 = controller.add(clusterIcon1)
1131 let added2 = controller.add(clusterIcon2)
1132 print("Registered icons for clustering: \‍(added1), \‍(added2)")
1133 // [swift_ClusterMapObjectController_addIconMapObject]
1134
1135 // [swift_ClusterMapObjectController_setEnabled]
1136 controller.setEnabled(true)
1137 print("Clustering enabled")
1138 // [swift_ClusterMapObjectController_setEnabled]
1139
1140 // [swift_ClusterMapObjectController_isEnabled]
1141 let clusteringEnabled = controller.isEnabled()
1142 print("Clustering is enabled: \‍(clusteringEnabled)")
1143 // [swift_ClusterMapObjectController_isEnabled]
1144
1145 // [swift_ClusterMapObjectController_setRadius]
1146 controller.setRadius(40.0)
1147 print("Set cluster radius to 40 px")
1148 // [swift_ClusterMapObjectController_setRadius]
1149
1150 // [swift_ClusterMapObjectController_getRadius]
1151 let clusterRadius = controller.getRadius()
1152 print("Cluster radius: \‍(clusterRadius)")
1153 // [swift_ClusterMapObjectController_getRadius]
1154
1155 // [swift_ClusterMapObjectController_setInteractive]
1156 let interactiveSuccess = controller.setInteractive(true)
1157 print("Set cluster markers interactive: \‍(interactiveSuccess)")
1158 // [swift_ClusterMapObjectController_setInteractive]
1159
1160 // [swift_ClusterMapObjectController_setClusterSize]
1161 let sizeSuccess = controller.setClusterSize(32.0, height: 32.0)
1162 print("Set default cluster icon size: \‍(sizeSuccess)")
1163 // [swift_ClusterMapObjectController_setClusterSize]
1164
1165 let listener = DemoClusterMapObjectControllerListener()
1166 clusterMapObjectControllerListener = listener
1167
1168 // [swift_ClusterMapObjectController_addListener]
1169 controller.add(listener)
1170 print("Added cluster map object controller listener")
1171 // [swift_ClusterMapObjectController_addListener]
1172
1173 // [swift_ClusterMapObjectController_getClusters]
1174 let clusters = controller.getClusters()
1175 print("Visible clusters: \‍(clusters.count)")
1176 // [swift_ClusterMapObjectController_getClusters]
1177
1178 if let cluster = clusters.first {
1179 // [swift_ClusterMapObject_setBitmap]
1180 if let clusterImage = UIImage(contentsOfFile: "/path/to/cluster.png") {
1181 let bitmapSuccess = cluster.setBitmap(clusterImage)
1182 print("Set cluster bitmap (UIImage): \‍(bitmapSuccess)")
1183 }
1184 // [swift_ClusterMapObject_setBitmap]
1185 }
1186
1187 // [swift_ClusterMapObjectController_removeListener]
1188 controller.remove(listener)
1189 print("Removed cluster map object controller listener")
1190 // [swift_ClusterMapObjectController_removeListener]
1191
1192 if let clusterIcon1 = clusterIcon1 {
1193 // [swift_ClusterMapObjectController_removeIconMapObject]
1194 let removed = controller.remove(clusterIcon1)
1195 print("Removed icon from cluster controller: \‍(removed)")
1196 // [swift_ClusterMapObjectController_removeIconMapObject]
1197 locationWindow.removeIconMapObject(clusterIcon1)
1198 }
1199 if let clusterIcon2 = clusterIcon2 {
1200 locationWindow.removeIconMapObject(clusterIcon2)
1201 }
1202
1203 // [swift_ClusterMapObjectController_clear]
1204 controller.clear()
1205 print("Cleared cluster controller")
1206 // [swift_ClusterMapObjectController_clear]
1207
1208 // [swift_LocationWindow_removeClusterMapObjectController]
1209 let controllerRemoved = locationWindow.removeClusterMapObjectController(controller)
1210 print("Removed cluster map object controller: \‍(controllerRemoved)")
1211 // [swift_LocationWindow_removeClusterMapObjectController]
1212
1213 clusterMapObjectController = nil
1214 clusterMapObjectControllerListener = nil
1215 }
1216
1217 /**
1218 * Demonstrate remove all map objects
1219 */
1220 private func demonstrateRemoveAllMapObjects() {
1221 print("--- Remove All Map Objects ---")
1222
1223 guard let locationWindow = locationWindow else {
1224 print("LocationWindow not available yet")
1225 return
1226 }
1227
1228 print("Current map objects count: \‍(getMapObjectsCount())")
1229
1230 // [swift_LocationWindow_removeAllMapObjects]
1231 // Remove all map objects
1232 locationWindow.removeAllMapObjects()
1233 print("Removed all map objects")
1234 // [swift_LocationWindow_removeAllMapObjects]
1235
1236 print("Map objects count after removal: \‍(getMapObjectsCount())")
1237 }
1238
1239 /**
1240 * Get current map objects count
1241 */
1242 private func getMapObjectsCount() -> Int {
1243 var count = 0
1244 if circleMapObject != nil { count += 1 }
1245 if iconMapObject != nil { count += 1 }
1246 if polygonMapObject != nil { count += 1 }
1247 if polylineMapObject != nil { count += 1 }
1248 if dottedPolylineMapObject != nil { count += 1 }
1249 return count
1250 }
1251
1252 /**
1253 * Cleanup resources
1254 */
1255 private func cleanup() {
1256 print("--- Cleanup ---")
1257
1258 if let locationWindow = locationWindow {
1259 locationWindow.removeAllMapObjects()
1260 print("Cleaned up all map objects")
1261 }
1262
1263 circleMapObject = nil
1264 iconMapObject = nil
1265 modelMapObject = nil
1266 polygonMapObject = nil
1267 polylineMapObject = nil
1268 dottedPolylineMapObject = nil
1269 print("Cleared map objects references")
1270 }
1271}
1272
1273class DemoClusterMapObjectControllerListener: NSObject, NCClusterMapObjectControllerListener {
1274 private let clusterChangeListener = DemoClusterMapObjectListener()
1275 private weak var activeCluster: NCClusterMapObject?
1276
1277 // [swift_ClusterMapObjectControllerListener_onClusterCreated]
1278 func onClusterCreated(_ controller: NCClusterMapObjectController?, cluster: NCClusterMapObject?) {
1279 guard let cluster else { return }
1280 // [swift_ClusterMapObject_addListener]
1281 cluster.add(clusterChangeListener)
1282 print("Added cluster change listener, initial count: \‍(cluster.count)")
1283 // [swift_ClusterMapObject_addListener]
1284 activeCluster = cluster
1285 }
1286 // [swift_ClusterMapObjectControllerListener_onClusterCreated]
1287
1288 // [swift_ClusterMapObjectControllerListener_onClusterDestroyed]
1289 func onClusterDestroyed(_ controller: NCClusterMapObjectController?, clusterId: Int32) {
1290 if let cluster = activeCluster, cluster.id == clusterId {
1291 // [swift_ClusterMapObject_removeListener]
1292 cluster.remove(clusterChangeListener)
1293 print("Removed cluster change listener")
1294 // [swift_ClusterMapObject_removeListener]
1295 activeCluster = nil
1296 }
1297 print("Cluster destroyed, id: \‍(clusterId)")
1298 }
1299 // [swift_ClusterMapObjectControllerListener_onClusterDestroyed]
1300}
1301
1302class DemoClusterMapObjectListener: NSObject, NCClusterMapObjectListener {
1303
1304 // [swift_ClusterMapObjectListener_onClusterChanged]
1305 func onClusterChanged(_ cluster: NCClusterMapObject) {
1306 let memberCount = cluster.count
1307 print("Cluster changed, member count: \‍(memberCount)")
1308 }
1309 // [swift_ClusterMapObjectListener_onClusterChanged]
1310}
1311
1312// Main function to run the example
1313let example = LocationWindowMapObjectsExample()