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