Loading...
Searching...
No Matches
LocationWindowMapObjectsExample.swift
Go to the documentation of this file.
1import Foundation
2import NavigineSDK
3
4/**
5 * LocationWindowMapObjects usage example for Swift
6 * Demonstrates specific methods: addCircleMapObject, removeCircleMapObject, addIconMapObject,
7 * removeIconMapObject, addPolygonMapObject, addPolylineMapObject, removePolylineMapObject,
8 * addDottedPolylineMapObject, removeDottedPolylineMapObject, removeAllMapObjects
9 */
10class LocationWindowMapObjectsExample {
11 private var locationWindow: NCLocationWindow?
12 private var circleMapObject: NCCircleMapObject?
13 private var iconMapObject: NCIconMapObject?
14 private var polygonMapObject: NCPolygonMapObject?
15 private var polylineMapObject: NCPolylineMapObject?
16 private var dottedPolylineMapObject: NCDottedPolylineMapObject?
17
18 init() {
19 demonstrateLocationWindowMapObjectsMethods()
20 }
21
22 /**
23 * Demonstrate LocationWindowMapObjects methods
24 */
25 private func demonstrateLocationWindowMapObjectsMethods() {
26 print("=== LocationWindowMapObjects Example ===")
27
28 // Initialize LocationWindow (in real app, this would be provided by the framework)
29 // locationWindow = getLocationWindow()
30
31 demonstrateCircleMapObjects()
32 demonstrateIconMapObjects()
33 demonstratePolygonMapObjects()
34 demonstratePolylineMapObjects()
35 demonstrateDottedPolylineMapObjects()
36 demonstrateRemoveAllMapObjects()
37
38 cleanup()
39 }
40
41 /**
42 * Demonstrate circle map objects
43 */
44 private func demonstrateCircleMapObjects() {
45 print("--- Circle Map Objects ---")
46
47 guard let locationWindow = locationWindow else {
48 print("LocationWindow not available yet")
49 return
50 }
51
52 // [swift_CircleMapObject_constructor]
53 // Create circle map object
54 let center = NCLocationPoint(x: 10.0, y: 20.0)
55 circleMapObject = locationWindow.addCircleMapObject()
56 print("Created circle map object with center (\‍(center.x), \‍(center.y)) and radius 5.0")
57 // [swift_CircleMapObject_constructor]
58
59 // [swift_CircleMapObject_getCenter]
60 // Access circle center
61 let circleCenter = circleMapObject!.getPosition()
62 print("Circle center: (\‍(circleCenter.x), \‍(circleCenter.y))")
63 // [swift_CircleMapObject_getCenter]
64
65 // [swift_CircleMapObject_getRadius]
66 // Access circle radius
67 let radius = circleMapObject!.getRadius()
68 print("Circle radius: \‍(radius)")
69 // [swift_CircleMapObject_getRadius]
70
71 // [swift_LocationWindow_addCircleMapObject]
72 // Add circle map object
73 circleMapObject = locationWindow.addCircleMapObject()
74 print("Added circle map object")
75 // [swift_LocationWindow_addCircleMapObject]
76
77 if let circleMapObject = circleMapObject {
78 // [swift_CircleMapObject_setPosition]
79 // Set circle position
80 let centerPoint = NCLocationPoint(x: 100.0, y: 200.0)
81 let success = circleMapObject.setPosition(centerPoint)
82 print("Set circle position to (\‍(centerPoint.x), \‍(centerPoint.y)): \‍(success)")
83 // [swift_CircleMapObject_setPosition]
84
85 // [swift_CircleMapObject_setPositionAnimated]
86 // Set circle position with animation
87 let animatedPoint = NCLocationPoint(x: 150.0, y: 250.0)
88 let animatedSuccess = circleMapObject.setPositionAnimated(animatedPoint, duration: 2.0, animationType: .linear)
89 print("Set circle position with animation to (\‍(animatedPoint.x), \‍(animatedPoint.y)): \‍(animatedSuccess)")
90 // [swift_CircleMapObject_setPositionAnimated]
91
92 // [swift_CircleMapObject_setRadius]
93 // Set circle radius
94 let radiusSuccess = circleMapObject.setRadius(10.0)
95 print("Set circle radius to 10.0 meters: \‍(radiusSuccess)")
96 // [swift_CircleMapObject_setRadius]
97
98 // [swift_CircleMapObject_setCollisionEnabled]
99 // Enable collision detection
100 let collisionSuccess = circleMapObject.setCollisionEnabled(true)
101 print("Enabled collision detection for circle: \‍(collisionSuccess)")
102 // [swift_CircleMapObject_setCollisionEnabled]
103
104 // [swift_CircleMapObject_setBuffer]
105 // Set collision buffer
106 let bufferSuccess = circleMapObject.setBuffer(width: 5.0, height: 5.0)
107 print("Set collision buffer to 5x5 pixels: \‍(bufferSuccess)")
108 // [swift_CircleMapObject_setBuffer]
109
110 // [swift_CircleMapObject_setOffset]
111 // Set position offset
112 let offsetSuccess = circleMapObject.setOffset(x: 2.0, y: 3.0)
113 print("Set position offset to (2.0, 3.0) pixels: \‍(offsetSuccess)")
114 // [swift_CircleMapObject_setOffset]
115
116 // [swift_CircleMapObject_setOutlineColor]
117 // Set outline color
118 let outlineColorSuccess = circleMapObject.setOutlineColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
119 print("Set circle outline color to blue: \‍(outlineColorSuccess)")
120 // [swift_CircleMapObject_setOutlineColor]
121
122 // [swift_CircleMapObject_setOutlineAlpha]
123 // Set outline alpha
124 let outlineAlphaSuccess = circleMapObject.setOutlineAlpha(0.5)
125 print("Set circle outline alpha to 0.5: \‍(outlineAlphaSuccess)")
126 // [swift_CircleMapObject_setOutlineAlpha]
127
128 // [swift_CircleMapObject_setOutlineRadius]
129 // Set outline radius
130 let outlineRadiusSuccess = circleMapObject.setOutlineRadius(2.0)
131 print("Set circle outline radius to 2.0: \‍(outlineRadiusSuccess)")
132 // [swift_CircleMapObject_setOutlineRadius]
133
134 // [swift_CircleMapObject_setColor]
135 // Set circle color
136 let colorSuccess = circleMapObject.setColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8)
137 print("Set circle color to red with 80% opacity: \‍(colorSuccess)")
138 // [swift_CircleMapObject_setColor]
139
140 // [swift_CircleMapObject_setPriority]
141 // Set rendering priority
142 let prioritySuccess = circleMapObject.setPriority(1)
143 print("Set rendering priority to 1: \‍(prioritySuccess)")
144 // [swift_CircleMapObject_setPriority]
145
146 // [swift_MapObject_setVisible]
147 // Set visibility
148 let visibleSuccess = circleMapObject.setVisible(true)
149 print("Set circle visibility to true: \‍(visibleSuccess)")
150 // [swift_MapObject_setVisible]
151
152 // [swift_CircleMapObject_getMapObjectType]
153 // Get map object type
154 let objectType = circleMapObject.mapObjectType
155 print("Circle map object type: \‍(objectType)")
156 // [swift_CircleMapObject_getMapObjectType]
157
158 // [swift_MapObject_setAlpha]
159 // Set alpha transparency
160 let alphaSuccess = circleMapObject.setAlpha(0.7)
161 print("Set circle alpha to 0.7: \‍(alphaSuccess)")
162 // [swift_MapObject_setAlpha]
163
164 // [swift_MapObject_setInteractive]
165 // Set interactive mode
166 let interactiveSuccess = circleMapObject.setInteractive(true)
167 print("Set circle interactive to true: \‍(interactiveSuccess)")
168 // [swift_MapObject_setInteractive]
169
170 // [swift_MapObject_setTitle]
171 // Set title
172 let titleSuccess = circleMapObject.setTitle("Circle Object")
173 print("Set circle title to 'Circle Object': \‍(titleSuccess)")
174 // [swift_MapObject_setTitle]
175
176 // [swift_MapObject_setData]
177 // Set custom data
178 let customData = ["key": "value", "number": "42"]
179 let dataSuccess = circleMapObject.setData(customData)
180 print("Set circle custom data: \‍(dataSuccess)")
181 // [swift_MapObject_setData]
182
183 // [swift_MapObject_getId]
184 // Get object ID
185 let objectId = circleMapObject.id
186 print("Circle object ID: \‍(objectId)")
187 // [swift_MapObject_getId]
188
189 // [swift_MapObject_getType]
190 // Get object type
191 let objectTypeString = circleMapObject.type
192 print("Circle object type: \‍(objectTypeString)")
193 // [swift_MapObject_getType]
194
195 // [swift_MapObject_getData]
196 // Get custom data
197 let retrievedData = circleMapObject.data
198 print("Circle custom data: \‍(retrievedData)")
199 // [swift_MapObject_getData]
200 }
201
202 // [swift_LocationWindow_removeCircleMapObject]
203 // Remove circle map object
204 if let circleMapObject = circleMapObject {
205 let removed = locationWindow.removeCircleMapObject(circleMapObject)
206 print("Removed circle map object: \‍(removed)")
207 self.circleMapObject = nil
208 }
209 // [swift_LocationWindow_removeCircleMapObject]
210
211 // Test multiple circle objects
212 var circles: [NCCircleMapObject] = []
213 for i in 0..<3 {
214 if let circle = locationWindow.addCircleMapObject() {
215 circle.setPosition(NCLocationPoint(x: 50.0 * Double(i), y: 100.0 * Double(i)))
216 circle.setColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.6)
217 circle.setRadius(5.0 + Double(i) * 2.0)
218 circles.append(circle)
219 print("Created circle \‍(i) at (\‍(50.0 * Double(i)), \‍(100.0 * Double(i))) with radius \‍(5.0 + Double(i) * 2.0)")
220 }
221 }
222
223 for i in circles.indices {
224 locationWindow.removeCircleMapObject(circles[i])
225 print("Removed circle \‍(i)")
226 }
227 }
228
229 /**
230 * Demonstrate icon map objects
231 */
232 private func demonstrateIconMapObjects() {
233 print("--- Icon Map Objects ---")
234
235 guard let locationWindow = locationWindow else {
236 print("LocationWindow not available yet")
237 return
238 }
239
240 // [swift_IconMapObject_constructor]
241 // Create icon map object
242 let position = NCLocationPoint(x: 30.0, y: 40.0)
243 iconMapObject = locationWindow.addIconMapObject()
244 print("Created icon map object at (\‍(position.x), \‍(position.y))")
245 // [swift_IconMapObject_constructor]
246
247 // [swift_IconMapObject_getPosition]
248 // Access icon position
249 let iconPosition = iconMapObject!.getPosition()
250 print("Icon position: (\‍(iconPosition.x), \‍(iconPosition.y))")
251 // [swift_IconMapObject_getPosition]
252
253 // [swift_LocationWindow_addIconMapObject]
254 // Add icon map object
255 iconMapObject = locationWindow.addIconMapObject()
256 print("Added icon map object")
257 // [swift_LocationWindow_addIconMapObject]
258
259 if let iconMapObject = iconMapObject {
260 // [swift_IconMapObject_setPosition]
261 // Set icon position
262 let position = NCLocationPoint(x: 30.0, y: 40.0)
263 let success = iconMapObject.setPosition(position)
264 print("Set icon position to (\‍(position.x), \‍(position.y)): \‍(success)")
265 // [swift_IconMapObject_setPosition]
266
267 // [swift_IconMapObject_setPositionAnimated]
268 // Set icon position with animation
269 let animatedPosition = NCLocationPoint(x: 35.0, y: 45.0)
270 let animatedSuccess = iconMapObject.setPositionAnimated(animatedPosition, duration: 1.5, animationType: .cubic)
271 print("Set icon position with animation to (\‍(animatedPosition.x), \‍(animatedPosition.y)): \‍(animatedSuccess)")
272 // [swift_IconMapObject_setPositionAnimated]
273
274 // [swift_IconMapObject_setIcon]
275 // Set icon image
276 let iconSuccess = iconMapObject.setIcon("path/to/icon.png")
277 print("Set icon image: \‍(iconSuccess)")
278 // [swift_IconMapObject_setIcon]
279
280 // [swift_IconMapObject_setBitmap]
281 // Set icon bitmap
282 let bitmapSuccess = iconMapObject.setBitmap("path/to/bitmap.png")
283 print("Set icon bitmap: \‍(bitmapSuccess)")
284 // [swift_IconMapObject_setBitmap]
285
286 // [swift_IconMapObject_setFlat]
287 // Set icon flat mode
288 let flatSuccess = iconMapObject.setFlat(true)
289 print("Set icon flat mode to true: \‍(flatSuccess)")
290 // [swift_IconMapObject_setFlat]
291
292 // [swift_IconMapObject_setSize]
293 // Set icon size
294 let size = NCSize(width: 32.0, height: 32.0)
295 let sizeSuccess = iconMapObject.setSize(size)
296 print("Set icon size to (\‍(size.width), \‍(size.height)): \‍(sizeSuccess)")
297 // [swift_IconMapObject_setSize]
298
299 // [swift_IconMapObject_setAngle]
300 // Set icon rotation angle
301 let angleSuccess = iconMapObject.setAngle(45.0)
302 print("Set icon rotation angle to 45 degrees: \‍(angleSuccess)")
303 // [swift_IconMapObject_setAngle]
304
305 // [swift_IconMapObject_setAngleAnimated]
306 // Set icon rotation with animation
307 let angleAnimatedSuccess = iconMapObject.setAngleAnimated(90.0, duration: 2.0, animationType: .sine)
308 print("Set icon rotation with animation to 90 degrees: \‍(angleAnimatedSuccess)")
309 // [swift_IconMapObject_setAngleAnimated]
310
311 // [swift_IconMapObject_setCollisionEnabled]
312 // Enable collision detection
313 let collisionSuccess = iconMapObject.setCollisionEnabled(true)
314 print("Enabled collision detection for icon: \‍(collisionSuccess)")
315 // [swift_IconMapObject_setCollisionEnabled]
316
317 // [swift_IconMapObject_setBuffer]
318 // Set collision buffer
319 let bufferSuccess = iconMapObject.setBuffer(width: 10.0, height: 10.0)
320 print("Set collision buffer to 10x10 pixels: \‍(bufferSuccess)")
321 // [swift_IconMapObject_setBuffer]
322
323 // [swift_IconMapObject_setPlacement]
324 // Set icon placement
325 let placementSuccess = iconMapObject.setPlacement(.center)
326 print("Set icon placement to CENTER: \‍(placementSuccess)")
327 // [swift_IconMapObject_setPlacement]
328
329 // [swift_IconMapObject_setOffset]
330 // Set position offset
331 let offsetSuccess = iconMapObject.setOffset(x: 0.0, y: -16.0)
332 print("Set position offset to (0.0, -16.0) pixels: \‍(offsetSuccess)")
333 // [swift_IconMapObject_setOffset]
334
335 // [swift_IconMapObject_setPriority]
336 // Set rendering priority
337 let prioritySuccess = iconMapObject.setPriority(2)
338 print("Set rendering priority to 2: \‍(prioritySuccess)")
339 // [swift_IconMapObject_setPriority]
340
341 // [swift_IconMapObject_setVisible]
342 // Set visibility
343 let visibleSuccess = iconMapObject.setVisible(true)
344 print("Set icon visibility to true: \‍(visibleSuccess)")
345 // [swift_IconMapObject_setVisible]
346
347 // [swift_IconMapObject_getMapObjectType]
348 // Get map object type
349 let objectType = iconMapObject.mapObjectType
350 print("Icon map object type: \‍(objectType)")
351 // [swift_IconMapObject_getMapObjectType]
352
353 // [swift_MapObject_setAlpha_1]
354 // Set alpha transparency
355 let alphaSuccess = iconMapObject.setAlpha(0.8)
356 print("Set icon alpha to 0.8: \‍(alphaSuccess)")
357 // [swift_MapObject_setAlpha_1]
358
359 // [swift_MapObject_setInteractive_1]
360 // Set interactive mode
361 let interactiveSuccess = iconMapObject.setInteractive(true)
362 print("Set icon interactive to true: \‍(interactiveSuccess)")
363 // [swift_MapObject_setInteractive_1]
364
365 // [swift_MapObject_setTitle_1]
366 // Set title
367 let titleSuccess = iconMapObject.setTitle("Icon Object")
368 print("Set icon title to 'Icon Object': \‍(titleSuccess)")
369 // [swift_MapObject_setTitle_1]
370
371 // [swift_MapObject_setData_1]
372 // Set custom data
373 let customData = ["key": "value", "number": "42"]
374 let dataSuccess = iconMapObject.setData(customData)
375 print("Set icon custom data: \‍(dataSuccess)")
376 // [swift_MapObject_setData_1]
377
378 // [swift_MapObject_getId_1]
379 // Get object ID
380 let objectId = iconMapObject.id
381 print("Icon object ID: \‍(objectId)")
382 // [swift_MapObject_getId_1]
383
384 // [swift_MapObject_getType_1]
385 // Get object type
386 let objectTypeString = iconMapObject.type
387 print("Icon object type: \‍(objectTypeString)")
388 // [swift_MapObject_getType_1]
389
390 // [swift_MapObject_getData_1]
391 // Get custom data
392 let retrievedData = iconMapObject.data
393 print("Icon custom data: \‍(retrievedData)")
394 // [swift_MapObject_getData_1]
395 }
396
397 // [swift_LocationWindow_removeIconMapObject]
398 // Remove icon map object
399 if let iconMapObject = iconMapObject {
400 let removed = locationWindow.removeIconMapObject(iconMapObject)
401 print("Removed icon map object: \‍(removed)")
402 self.iconMapObject = nil
403 }
404 // [swift_LocationWindow_removeIconMapObject]
405
406 // Test multiple icon objects
407 var icons: [NCIconMapObject] = []
408 for i in 0..<3 {
409 if let icon = locationWindow.addIconMapObject() {
410 icon.setPosition(NCLocationPoint(x: 60.0 * Double(i), y: 120.0 * Double(i)))
411 icon.setIcon("path/to/icon\‍(i).png")
412 icon.setSize(NCSize(width: 24.0, height: 24.0))
413 icons.append(icon)
414 print("Created icon \‍(i) at (\‍(60.0 * Double(i)), \‍(120.0 * Double(i)))")
415 }
416 }
417
418 for i in icons.indices {
419 locationWindow.removeIconMapObject(icons[i])
420 print("Removed icon \‍(i)")
421 }
422 }
423
424 /**
425 * Demonstrate polygon map objects
426 */
427 private func demonstratePolygonMapObjects() {
428 print("--- Polygon Map Objects ---")
429
430 guard let locationWindow = locationWindow else {
431 print("LocationWindow not available yet")
432 return
433 }
434
435 // [swift_LocationWindow_addPolygonMapObject]
436 // Add polygon map object
437 polygonMapObject = locationWindow.addPolygonMapObject()
438 print("Added polygon map object")
439 // [swift_LocationWindow_addPolygonMapObject]
440
441 if let polygonMapObject = polygonMapObject {
442 // [swift_PolygonMapObject_setPolygon]
443 // Set polygon geometry
444 let points = [
445 NCLocationPoint(x: 50.0, y: 60.0),
446 NCLocationPoint(x: 55.0, y: 65.0),
447 NCLocationPoint(x: 60.0, y: 60.0),
448 NCLocationPoint(x: 55.0, y: 55.0)
449 ]
450 let polygon = NCLocationPolygon(points: points)
451 let success = polygonMapObject.setPolygon(polygon)
452 print("Set polygon with \‍(points.count) points: \‍(success)")
453 // [swift_PolygonMapObject_setPolygon]
454
455 // [swift_PolygonMapObject_setColor]
456 // Set polygon color
457 let colorSuccess = polygonMapObject.setColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.7)
458 print("Set polygon color to green with 70% opacity: \‍(colorSuccess)")
459 // [swift_PolygonMapObject_setColor]
460
461 // [swift_PolygonMapObject_setOrder]
462 // Set polygon rendering order
463 let orderSuccess = polygonMapObject.setOrder(2)
464 print("Set polygon rendering order to 2: \‍(orderSuccess)")
465 // [swift_PolygonMapObject_setOrder]
466
467 // [swift_PolygonMapObject_setOutlineColor]
468 // Set polygon outline color
469 let outlineColorSuccess = polygonMapObject.setOutlineColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
470 print("Set polygon outline color to blue: \‍(outlineColorSuccess)")
471 // [swift_PolygonMapObject_setOutlineColor]
472
473 // [swift_PolygonMapObject_setOutlineWidth]
474 // Set polygon outline width
475 let outlineWidthSuccess = polygonMapObject.setOutlineWidth(2.0)
476 print("Set polygon outline width to 2.0 pixels: \‍(outlineWidthSuccess)")
477 // [swift_PolygonMapObject_setOutlineWidth]
478
479 // [swift_PolygonMapObject_setOutlineAlpha]
480 // Set polygon outline alpha
481 let outlineAlphaSuccess = polygonMapObject.setOutlineAlpha(0.8)
482 print("Set polygon outline alpha to 0.8: \‍(outlineAlphaSuccess)")
483 // [swift_PolygonMapObject_setOutlineAlpha]
484
485 // [swift_PolygonMapObject_setOutlineOrder]
486 // Set polygon outline order
487 let outlineOrderSuccess = polygonMapObject.setOutlineOrder(1)
488 print("Set polygon outline order to 1: \‍(outlineOrderSuccess)")
489 // [swift_PolygonMapObject_setOutlineOrder]
490
491 // [swift_PolygonMapObject_setVisible]
492 // Set visibility
493 let visibleSuccess = polygonMapObject.setVisible(true)
494 print("Set polygon visibility to true: \‍(visibleSuccess)")
495 // [swift_PolygonMapObject_setVisible]
496
497 // [swift_PolygonMapObject_getMapObjectType]
498 // Get map object type
499 let objectType = polygonMapObject.mapObjectType
500 print("Polygon map object type: \‍(objectType)")
501 // [swift_PolygonMapObject_getMapObjectType]
502
503 // [swift_MapObject_setAlpha_2]
504 // Set alpha transparency
505 let alphaSuccess = polygonMapObject.setAlpha(0.6)
506 print("Set polygon alpha to 0.6: \‍(alphaSuccess)")
507 // [swift_MapObject_setAlpha_2]
508
509 // [swift_MapObject_setInteractive_2]
510 // Set interactive mode
511 let interactiveSuccess = polygonMapObject.setInteractive(true)
512 print("Set polygon interactive to true: \‍(interactiveSuccess)")
513 // [swift_MapObject_setInteractive_2]
514
515 // [swift_MapObject_setTitle_2]
516 // Set title
517 let titleSuccess = polygonMapObject.setTitle("Polygon Object")
518 print("Set polygon title to 'Polygon Object': \‍(titleSuccess)")
519 // [swift_MapObject_setTitle_2]
520
521 // [swift_MapObject_setData_2]
522 // Set custom data
523 let customData = ["key": "value", "number": "42"]
524 let dataSuccess = polygonMapObject.setData(customData)
525 print("Set polygon custom data: \‍(dataSuccess)")
526 // [swift_MapObject_setData_2]
527
528 // [swift_MapObject_getId_2]
529 // Get object ID
530 let objectId = polygonMapObject.id
531 print("Polygon object ID: \‍(objectId)")
532 // [swift_MapObject_getId_2]
533
534 // [swift_MapObject_getType_2]
535 // Get object type
536 let objectTypeString = polygonMapObject.type
537 print("Polygon object type: \‍(objectTypeString)")
538 // [swift_MapObject_getType_2]
539
540 // [swift_MapObject_getData_2]
541 // Get custom data
542 let retrievedData = polygonMapObject.data
543 print("Polygon custom data: \‍(retrievedData)")
544 // [swift_MapObject_getData_2]
545 }
546
547 // [swift_LocationWindow_removePolygonMapObject]
548 // Remove polygon map object
549 if let polygonMapObject = polygonMapObject {
550 let removed = locationWindow.removePolygonMapObject(polygonMapObject)
551 print("Removed polygon map object: \‍(removed)")
552 self.polygonMapObject = nil
553 }
554 // [swift_LocationWindow_removePolygonMapObject]
555
556 // Test multiple polygon objects
557 var polygons: [NCPolygonMapObject] = []
558 for i in 0..<3 {
559 if let polygon = locationWindow.addPolygonMapObject() {
560 let points = [
561 NCLocationPoint(x: 300.0 + Double(i) * 50, y: 400.0 + Double(i) * 50),
562 NCLocationPoint(x: 350.0 + Double(i) * 50, y: 450.0 + Double(i) * 50),
563 NCLocationPoint(x: 400.0 + Double(i) * 50, y: 400.0 + Double(i) * 50),
564 NCLocationPoint(x: 350.0 + Double(i) * 50, y: 350.0 + Double(i) * 50)
565 ]
566 let polygonGeometry = NCLocationPolygon(points: points)
567 polygon.setPolygon(polygonGeometry)
568 polygon.setColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.5)
569 polygons.append(polygon)
570 print("Created polygon \‍(i) with \‍(points.count) points")
571 }
572 }
573
574 for i in polygons.indices {
575 locationWindow.removePolygonMapObject(polygons[i])
576 print("Removed polygon \‍(i)")
577 }
578 }
579
580 /**
581 * Demonstrate polyline map objects
582 */
583 private func demonstratePolylineMapObjects() {
584 print("--- Polyline Map Objects ---")
585
586 guard let locationWindow = locationWindow else {
587 print("LocationWindow not available yet")
588 return
589 }
590
591 // [swift_PolylineMapObject_constructor]
592 // Create polyline map object
593 let points = [
594 NCLocationPoint(x: 100.0, y: 110.0),
595 NCLocationPoint(x: 105.0, y: 115.0),
596 NCLocationPoint(x: 110.0, y: 120.0),
597 NCLocationPoint(x: 115.0, y: 125.0)
598 ]
599 let polyline = NCLocationPolyline(points: points)
600 polylineMapObject = locationWindow.addPolylineMapObject()
601 print("Created polyline map object with \‍(points.count) points")
602 // [swift_PolylineMapObject_constructor]
603
604 // [swift_PolylineMapObject_getPolyline]
605 // Access polyline
606 let polylineShape = polylineMapObject!.getPolyLine()
607 print("Polyline has \‍(polylineShape.points.count) points")
608 // [swift_PolylineMapObject_getPolyline]
609
610 // [swift_LocationWindow_addPolylineMapObject]
611 // Add polyline map object
612 polylineMapObject = locationWindow.addPolylineMapObject()
613 print("Added polyline map object")
614 // [swift_LocationWindow_addPolylineMapObject]
615
616 if let polylineMapObject = polylineMapObject {
617 // [swift_PolylineMapObject_setPolyLine]
618 // Set polyline geometry
619 let points = [
620 NCLocationPoint(x: 100.0, y: 110.0),
621 NCLocationPoint(x: 105.0, y: 115.0),
622 NCLocationPoint(x: 110.0, y: 120.0),
623 NCLocationPoint(x: 115.0, y: 125.0)
624 ]
625 let polyline = NCLocationPolyline(points: points)
626 let success = polylineMapObject.setPolyLine(polyline)
627 print("Set polyline with \‍(points.count) points: \‍(success)")
628 // [swift_PolylineMapObject_setPolyLine]
629
630 // [swift_PolylineMapObject_setWidth]
631 // Set polyline width
632 let widthSuccess = polylineMapObject.setWidth(3.0)
633 print("Set polyline width to 3.0 pixels: \‍(widthSuccess)")
634 // [swift_PolylineMapObject_setWidth]
635
636 // [swift_PolylineMapObject_setColor]
637 // Set polyline color
638 let colorSuccess = polylineMapObject.setColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.8)
639 print("Set polyline color to green with 80% opacity: \‍(colorSuccess)")
640 // [swift_PolylineMapObject_setColor]
641
642 // [swift_PolylineMapObject_setOrder]
643 // Set polyline rendering order
644 let orderSuccess = polylineMapObject.setOrder(1)
645 print("Set polyline rendering order to 1: \‍(orderSuccess)")
646 // [swift_PolylineMapObject_setOrder]
647
648 // [swift_PolylineMapObject_setCapType]
649 // Set polyline cap type
650 let capTypeSuccess = polylineMapObject.setCapType(.round)
651 print("Set polyline cap type to ROUND: \‍(capTypeSuccess)")
652 // [swift_PolylineMapObject_setCapType]
653
654 // [swift_PolylineMapObject_setJoinType]
655 // Set polyline join type
656 let joinTypeSuccess = polylineMapObject.setJoinType(.round)
657 print("Set polyline join type to ROUND: \‍(joinTypeSuccess)")
658 // [swift_PolylineMapObject_setJoinType]
659
660 // [swift_PolylineMapObject_setMiterLimit]
661 // Set polyline miter limit
662 let miterLimitSuccess = polylineMapObject.setMiterLimit(2.0)
663 print("Set polyline miter limit to 2.0: \‍(miterLimitSuccess)")
664 // [swift_PolylineMapObject_setMiterLimit]
665
666 // [swift_PolylineMapObject_setOutlineWidth]
667 // Set polyline outline width
668 let outlineWidthSuccess = polylineMapObject.setOutlineWidth(1.0)
669 print("Set polyline outline width to 1.0 pixels: \‍(outlineWidthSuccess)")
670 // [swift_PolylineMapObject_setOutlineWidth]
671
672 // [swift_PolylineMapObject_setOutlineColor]
673 // Set polyline outline color
674 let outlineColorSuccess = polylineMapObject.setOutlineColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
675 print("Set polyline outline color to black: \‍(outlineColorSuccess)")
676 // [swift_PolylineMapObject_setOutlineColor]
677
678 // [swift_PolylineMapObject_setOutlineAlpha]
679 // Set polyline outline alpha
680 let outlineAlphaSuccess = polylineMapObject.setOutlineAlpha(0.5)
681 print("Set polyline outline alpha to 0.5: \‍(outlineAlphaSuccess)")
682 // [swift_PolylineMapObject_setOutlineAlpha]
683
684 // [swift_PolylineMapObject_setOutlineOrder]
685 // Set polyline outline rendering order
686 let outlineOrderSuccess = polylineMapObject.setOutlineOrder(0)
687 print("Set polyline outline rendering order to 0: \‍(outlineOrderSuccess)")
688 // [swift_PolylineMapObject_setOutlineOrder]
689
690 // [swift_PolylineMapObject_setOutlineCapType]
691 // Set polyline outline cap type
692 let outlineCapTypeSuccess = polylineMapObject.setOutlineCapType(.square)
693 print("Set polyline outline cap type to SQUARE: \‍(outlineCapTypeSuccess)")
694 // [swift_PolylineMapObject_setOutlineCapType]
695
696 // [swift_PolylineMapObject_setOutlineJoinType]
697 // Set polyline outline join type
698 let outlineJoinTypeSuccess = polylineMapObject.setOutlineJoinType(.miter)
699 print("Set polyline outline join type to MITER: \‍(outlineJoinTypeSuccess)")
700 // [swift_PolylineMapObject_setOutlineJoinType]
701
702 // [swift_PolylineMapObject_setOutlineMiterLimit]
703 // Set polyline outline miter limit
704 let outlineMiterLimitSuccess = polylineMapObject.setOutlineMiterLimit(3.0)
705 print("Set polyline outline miter limit to 3.0: \‍(outlineMiterLimitSuccess)")
706 // [swift_PolylineMapObject_setOutlineMiterLimit]
707
708 // [swift_PolylineMapObject_setVisible]
709 // Set visibility
710 let visibleSuccess = polylineMapObject.setVisible(true)
711 print("Set polyline visibility to true: \‍(visibleSuccess)")
712 // [swift_PolylineMapObject_setVisible]
713
714 // [swift_PolylineMapObject_getMapObjectType]
715 // Get map object type
716 let objectType = polylineMapObject.mapObjectType
717 print("Polyline map object type: \‍(objectType)")
718 // [swift_PolylineMapObject_getMapObjectType]
719
720 // [swift_MapObject_setAlpha_3]
721 // Set alpha transparency
722 let alphaSuccess = polylineMapObject.setAlpha(0.7)
723 print("Set polyline alpha to 0.7: \‍(alphaSuccess)")
724 // [swift_MapObject_setAlpha_3]
725
726 // [swift_MapObject_setInteractive_3]
727 // Set interactive mode
728 let interactiveSuccess = polylineMapObject.setInteractive(true)
729 print("Set polyline interactive to true: \‍(interactiveSuccess)")
730 // [swift_MapObject_setInteractive_3]
731
732 // [swift_MapObject_setTitle_3]
733 // Set title
734 let titleSuccess = polylineMapObject.setTitle("Polyline Object")
735 print("Set polyline title to 'Polyline Object': \‍(titleSuccess)")
736 // [swift_MapObject_setTitle_3]
737
738 // [swift_MapObject_setData_3]
739 // Set custom data
740 let customData = ["key": "value", "number": "42"]
741 let dataSuccess = polylineMapObject.setData(customData)
742 print("Set polyline custom data: \‍(dataSuccess)")
743 // [swift_MapObject_setData_3]
744
745 // [swift_MapObject_getId_3]
746 // Get object ID
747 let objectId = polylineMapObject.id
748 print("Polyline object ID: \‍(objectId)")
749 // [swift_MapObject_getId_3]
750
751 // [swift_MapObject_getType_3]
752 // Get object type
753 let objectTypeString = polylineMapObject.type
754 print("Polyline object type: \‍(objectTypeString)")
755 // [swift_MapObject_getType_3]
756
757 // [swift_MapObject_getData_3]
758 // Get custom data
759 let retrievedData = polylineMapObject.data
760 print("Polyline custom data: \‍(retrievedData)")
761 // [swift_MapObject_getData_3]
762 }
763
764 // [swift_LocationWindow_removePolylineMapObject]
765 // Remove polyline map object
766 if let polylineMapObject = polylineMapObject {
767 let removed = locationWindow.removePolylineMapObject(polylineMapObject)
768 print("Removed polyline map object: \‍(removed)")
769 self.polylineMapObject = nil
770 }
771 // [swift_LocationWindow_removePolylineMapObject]
772
773 // Test multiple polyline objects
774 var polylines: [NCPolylineMapObject] = []
775 for i in 0..<3 {
776 if let polyline = locationWindow.addPolylineMapObject() {
777 let points = [
778 NCLocationPoint(x: 120.0 + Double(i) * 30, y: 130.0 + Double(i) * 30),
779 NCLocationPoint(x: 125.0 + Double(i) * 30, y: 135.0 + Double(i) * 30),
780 NCLocationPoint(x: 130.0 + Double(i) * 30, y: 140.0 + Double(i) * 30)
781 ]
782 let polylineGeometry = NCLocationPolyline(points: points)
783 polyline.setPolyLine(polylineGeometry)
784 polyline.setColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6)
785 polyline.setWidth(2.0)
786 polylines.append(polyline)
787 print("Created polyline \‍(i) with \‍(points.count) points")
788 }
789 }
790
791 for i in polylines.indices {
792 locationWindow.removePolylineMapObject(polylines[i])
793 print("Removed polyline \‍(i)")
794 }
795 }
796
797 /**
798 * Demonstrate dotted polyline map objects
799 */
800 private func demonstrateDottedPolylineMapObjects() {
801 print("--- Dotted Polyline Map Objects ---")
802
803 guard let locationWindow = locationWindow else {
804 print("LocationWindow not available yet")
805 return
806 }
807
808 // [swift_DottedPolylineMapObject_constructor]
809 // Create dotted polyline map object
810 let points = [
811 NCLocationPoint(x: 160.0, y: 170.0),
812 NCLocationPoint(x: 165.0, y: 175.0),
813 NCLocationPoint(x: 170.0, y: 180.0),
814 NCLocationPoint(x: 175.0, y: 185.0)
815 ]
816 let polyline = NCLocationPolyline(points: points)
817 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
818 print("Created dotted polyline map object with \‍(points.count) points")
819 // [swift_DottedPolylineMapObject_constructor]
820
821 // [swift_DottedPolylineMapObject_getPolyline]
822 // Access dotted polyline
823 let dottedPolylineShape = dottedPolylineMapObject!.getPolyLine()
824 print("Dotted polyline has \‍(dottedPolylineShape.points.count) points")
825 // [swift_DottedPolylineMapObject_getPolyline]
826
827 // [swift_LocationWindow_addDottedPolylineMapObject]
828 // Add dotted polyline map object
829 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
830 print("Added dotted polyline map object")
831 // [swift_LocationWindow_addDottedPolylineMapObject]
832
833 if let dottedPolylineMapObject = dottedPolylineMapObject {
834 // [swift_DottedPolylineMapObject_setPolyline]
835 // Set dotted polyline geometry
836 let points = [
837 NCLocationPoint(x: 160.0, y: 170.0),
838 NCLocationPoint(x: 165.0, y: 175.0),
839 NCLocationPoint(x: 170.0, y: 180.0),
840 NCLocationPoint(x: 175.0, y: 185.0)
841 ]
842 let polyline = NCLocationPolyline(points: points)
843 let success = dottedPolylineMapObject.setPolyline(polyline)
844 print("Set dotted polyline with \‍(points.count) points: \‍(success)")
845 // [swift_DottedPolylineMapObject_setPolyline]
846
847 // [swift_DottedPolylineMapObject_setColor]
848 // Set dotted polyline color
849 let colorSuccess = dottedPolylineMapObject.setColor(red: 0.5, green: 0.0, blue: 1.0, alpha: 0.8)
850 print("Set dotted polyline color to purple with 80% opacity: \‍(colorSuccess)")
851 // [swift_DottedPolylineMapObject_setColor]
852
853 // [swift_DottedPolylineMapObject_setWidth]
854 // Set dotted polyline width
855 let widthSuccess = dottedPolylineMapObject.setWidth(3.0)
856 print("Set dotted polyline width to 3.0 pixels: \‍(widthSuccess)")
857 // [swift_DottedPolylineMapObject_setWidth]
858
859 // [swift_DottedPolylineMapObject_setOrder]
860 // Set dotted polyline rendering order
861 let orderSuccess = dottedPolylineMapObject.setOrder(2)
862 print("Set dotted polyline rendering order to 2: \‍(orderSuccess)")
863 // [swift_DottedPolylineMapObject_setOrder]
864
865 // [swift_DottedPolylineMapObject_setCollisionEnabled]
866 // Enable collision detection
867 let dottedCollisionSuccess = dottedPolylineMapObject.setCollisionEnabled(true)
868 print("Enabled collision detection for dotted polyline: \‍(dottedCollisionSuccess)")
869 // [swift_DottedPolylineMapObject_setCollisionEnabled]
870
871 // [swift_DottedPolylineMapObject_setPlacement]
872 // Set placement type
873 let dottedPlacementSuccess = dottedPolylineMapObject.setPlacement(.center)
874 print("Set dotted polyline placement to CENTER: \‍(dottedPlacementSuccess)")
875 // [swift_DottedPolylineMapObject_setPlacement]
876
877 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
878 // Set placement min ratio
879 let dottedMinRatioSuccess = dottedPolylineMapObject.setPlacementMinRatio(0.5)
880 print("Set dotted polyline placement min ratio to 0.5: \‍(dottedMinRatioSuccess)")
881 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
882
883 // [swift_DottedPolylineMapObject_setPlacementSpacing]
884 // Set placement spacing
885 let dottedSpacingSuccess = dottedPolylineMapObject.setPlacementSpacing(10.0)
886 print("Set dotted polyline placement spacing to 10.0: \‍(dottedSpacingSuccess)")
887 // [swift_DottedPolylineMapObject_setPlacementSpacing]
888
889 // [swift_DottedPolylineMapObject_setPriority]
890 // Set rendering priority
891 let dottedPrioritySuccess = dottedPolylineMapObject.setPriority(1)
892 print("Set dotted polyline rendering priority to 1: \‍(dottedPrioritySuccess)")
893 // [swift_DottedPolylineMapObject_setPriority]
894
895 // [swift_DottedPolylineMapObject_setRepeatDistance]
896 // Set repeat distance
897 let dottedRepeatDistanceSuccess = dottedPolylineMapObject.setRepeatDistance(20.0)
898 print("Set dotted polyline repeat distance to 20.0: \‍(dottedRepeatDistanceSuccess)")
899 // [swift_DottedPolylineMapObject_setRepeatDistance]
900
901 // [swift_DottedPolylineMapObject_setRepeatGroup]
902 // Set repeat group
903 let dottedRepeatGroupSuccess = dottedPolylineMapObject.setRepeatGroup(1)
904 print("Set dotted polyline repeat group to 1: \‍(dottedRepeatGroupSuccess)")
905 // [swift_DottedPolylineMapObject_setRepeatGroup]
906
907 // [swift_DottedPolylineMapObject_setSize]
908 // Set size
909 let dottedSize = NCSize(width: 16.0, height: 16.0)
910 let dottedSizeSuccess = dottedPolylineMapObject.setSize(dottedSize)
911 print("Set dotted polyline size to (\‍(dottedSize.width), \‍(dottedSize.height)): \‍(dottedSizeSuccess)")
912 // [swift_DottedPolylineMapObject_setSize]
913
914 // [swift_DottedPolylineMapObject_setVisible]
915 // Set visibility
916 let visibleSuccess = dottedPolylineMapObject.setVisible(true)
917 print("Set dotted polyline visibility to true: \‍(visibleSuccess)")
918 // [swift_DottedPolylineMapObject_setVisible]
919
920 // [swift_DottedPolylineMapObject_getMapObjectType]
921 // Get map object type
922 let objectType = dottedPolylineMapObject.mapObjectType
923 print("Dotted polyline map object type: \‍(objectType)")
924 // [swift_DottedPolylineMapObject_getMapObjectType]
925
926 // [swift_MapObject_setAlpha_4]
927 // Set alpha transparency
928 let alphaSuccess = dottedPolylineMapObject.setAlpha(0.8)
929 print("Set dotted polyline alpha to 0.8: \‍(alphaSuccess)")
930 // [swift_MapObject_setAlpha_4]
931
932 // [swift_MapObject_setInteractive_4]
933 // Set interactive mode
934 let interactiveSuccess = dottedPolylineMapObject.setInteractive(true)
935 print("Set dotted polyline interactive to true: \‍(interactiveSuccess)")
936 // [swift_MapObject_setInteractive_4]
937
938 // [swift_MapObject_setTitle_4]
939 // Set title
940 let titleSuccess = dottedPolylineMapObject.setTitle("Dotted Polyline Object")
941 print("Set dotted polyline title to 'Dotted Polyline Object': \‍(titleSuccess)")
942 // [swift_MapObject_setTitle_4]
943
944 // [swift_MapObject_setData_4]
945 // Set custom data
946 let customData = ["key": "value", "number": "42"]
947 let dataSuccess = dottedPolylineMapObject.setData(customData)
948 print("Set dotted polyline custom data: \‍(dataSuccess)")
949 // [swift_MapObject_setData_4]
950
951 // [swift_MapObject_getId_4]
952 // Get object ID
953 let objectId = dottedPolylineMapObject.id
954 print("Dotted polyline object ID: \‍(objectId)")
955 // [swift_MapObject_getId_4]
956
957 // [swift_MapObject_getType_4]
958 // Get object type
959 let objectTypeString = dottedPolylineMapObject.type
960 print("Dotted polyline object type: \‍(objectTypeString)")
961 // [swift_MapObject_getType_4]
962
963 // [swift_MapObject_getData_4]
964 // Get custom data
965 let retrievedData = dottedPolylineMapObject.data
966 print("Dotted polyline custom data: \‍(retrievedData)")
967 // [swift_MapObject_getData_4]
968 }
969
970 // [swift_LocationWindow_removeDottedPolylineMapObject]
971 // Remove dotted polyline map object
972 if let dottedPolylineMapObject = dottedPolylineMapObject {
973 let removed = locationWindow.removeDottedPolylineMapObject(dottedPolylineMapObject)
974 print("Removed dotted polyline map object: \‍(removed)")
975 self.dottedPolylineMapObject = nil
976 }
977 // [swift_LocationWindow_removeDottedPolylineMapObject]
978
979 // Test multiple dotted polyline objects
980 var dottedPolylines: [NCDottedPolylineMapObject] = []
981 for i in 0..<3 {
982 if let dottedPolyline = locationWindow.addDottedPolylineMapObject() {
983 let points = [
984 NCLocationPoint(x: 180.0 + Double(i) * 30, y: 190.0 + Double(i) * 30),
985 NCLocationPoint(x: 185.0 + Double(i) * 30, y: 195.0 + Double(i) * 30),
986 NCLocationPoint(x: 190.0 + Double(i) * 30, y: 200.0 + Double(i) * 30)
987 ]
988 let polylineGeometry = NCLocationPolyline(points: points)
989 dottedPolyline.setPolyline(polylineGeometry)
990 dottedPolylines.append(dottedPolyline)
991 print("Created dotted polyline \‍(i) with \‍(points.count) points")
992 }
993 }
994
995 for i in dottedPolylines.indices {
996 locationWindow.removeDottedPolylineMapObject(dottedPolylines[i])
997 print("Removed dotted polyline \‍(i)")
998 }
999 }
1000
1001 /**
1002 * Demonstrate remove all map objects
1003 */
1004 private func demonstrateRemoveAllMapObjects() {
1005 print("--- Remove All Map Objects ---")
1006
1007 guard let locationWindow = locationWindow else {
1008 print("LocationWindow not available yet")
1009 return
1010 }
1011
1012 print("Current map objects count: \‍(getMapObjectsCount())")
1013
1014 // [swift_LocationWindow_removeAllMapObjects]
1015 // Remove all map objects
1016 locationWindow.removeAllMapObjects()
1017 print("Removed all map objects")
1018 // [swift_LocationWindow_removeAllMapObjects]
1019
1020 print("Map objects count after removal: \‍(getMapObjectsCount())")
1021 }
1022
1023 /**
1024 * Get current map objects count
1025 */
1026 private func getMapObjectsCount() -> Int {
1027 var count = 0
1028 if circleMapObject != nil { count += 1 }
1029 if iconMapObject != nil { count += 1 }
1030 if polygonMapObject != nil { count += 1 }
1031 if polylineMapObject != nil { count += 1 }
1032 if dottedPolylineMapObject != nil { count += 1 }
1033 return count
1034 }
1035
1036 /**
1037 * Cleanup resources
1038 */
1039 private func cleanup() {
1040 print("--- Cleanup ---")
1041
1042 if let locationWindow = locationWindow {
1043 locationWindow.removeAllMapObjects()
1044 print("Cleaned up all map objects")
1045 }
1046
1047 circleMapObject = nil
1048 iconMapObject = nil
1049 polygonMapObject = nil
1050 polylineMapObject = nil
1051 dottedPolylineMapObject = nil
1052 print("Cleared map objects references")
1053 }
1054}
1055
1056// Main function to run the example
1057let example = LocationWindowMapObjectsExample()