5 * LocationWindowMapObjects usage example for Swift
6 * Demonstrates specific methods: addCircleMapObject, removeCircleMapObject, addIconMapObject,
7 * removeIconMapObject, addPolygonMapObject, addPolylineMapObject, removePolylineMapObject,
8 * addDottedPolylineMapObject, removeDottedPolylineMapObject, removeAllMapObjects
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?
19 demonstrateLocationWindowMapObjectsMethods()
23 * Demonstrate LocationWindowMapObjects methods
25 private func demonstrateLocationWindowMapObjectsMethods() {
26 print("=== LocationWindowMapObjects Example ===")
28 // Initialize LocationWindow (in real app, this would be provided by the framework)
29 // locationWindow = getLocationWindow()
31 demonstrateCircleMapObjects()
32 demonstrateIconMapObjects()
33 demonstratePolygonMapObjects()
34 demonstratePolylineMapObjects()
35 demonstrateDottedPolylineMapObjects()
36 demonstrateRemoveAllMapObjects()
42 * Demonstrate circle map objects
44 private func demonstrateCircleMapObjects() {
45 print("--- Circle Map Objects ---")
47 guard let locationWindow = locationWindow else {
48 print("LocationWindow not available yet")
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]
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]
65 // [swift_CircleMapObject_getRadius]
66 // Access circle radius
67 let radius = circleMapObject!.getRadius()
68 print("Circle radius: \(radius)")
69 // [swift_CircleMapObject_getRadius]
71 // [swift_LocationWindow_addCircleMapObject]
72 // Add circle map object
73 circleMapObject = locationWindow.addCircleMapObject()
74 print("Added circle map object")
75 // [swift_LocationWindow_addCircleMapObject]
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]
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]
92 // [swift_CircleMapObject_setRadius]
94 let radiusSuccess = circleMapObject.setRadius(10.0)
95 print("Set circle radius to 10.0 meters: \(radiusSuccess)")
96 // [swift_CircleMapObject_setRadius]
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]
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]
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]
116 // [swift_CircleMapObject_setOutlineColor]
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]
122 // [swift_CircleMapObject_setOutlineAlpha]
124 let outlineAlphaSuccess = circleMapObject.setOutlineAlpha(0.5)
125 print("Set circle outline alpha to 0.5: \(outlineAlphaSuccess)")
126 // [swift_CircleMapObject_setOutlineAlpha]
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]
134 // [swift_CircleMapObject_setColor]
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]
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]
146 // [swift_MapObject_setVisible]
148 let visibleSuccess = circleMapObject.setVisible(true)
149 print("Set circle visibility to true: \(visibleSuccess)")
150 // [swift_MapObject_setVisible]
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]
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]
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]
170 // [swift_MapObject_setTitle]
172 let titleSuccess = circleMapObject.setTitle("Circle Object")
173 print("Set circle title to 'Circle Object': \(titleSuccess)")
174 // [swift_MapObject_setTitle]
176 // [swift_MapObject_setData]
178 let customData = ["key": "value", "number": "42"]
179 let dataSuccess = circleMapObject.setData(customData)
180 print("Set circle custom data: \(dataSuccess)")
181 // [swift_MapObject_setData]
183 // [swift_MapObject_getId]
185 let objectId = circleMapObject.id
186 print("Circle object ID: \(objectId)")
187 // [swift_MapObject_getId]
189 // [swift_MapObject_getType]
191 let objectTypeString = circleMapObject.type
192 print("Circle object type: \(objectTypeString)")
193 // [swift_MapObject_getType]
195 // [swift_MapObject_getData]
197 let retrievedData = circleMapObject.data
198 print("Circle custom data: \(retrievedData)")
199 // [swift_MapObject_getData]
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
209 // [swift_LocationWindow_removeCircleMapObject]
211 // Test multiple circle objects
212 var circles: [NCCircleMapObject] = []
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)")
223 for i in circles.indices {
224 locationWindow.removeCircleMapObject(circles[i])
225 print("Removed circle \(i)")
230 * Demonstrate icon map objects
232 private func demonstrateIconMapObjects() {
233 print("--- Icon Map Objects ---")
235 guard let locationWindow = locationWindow else {
236 print("LocationWindow not available yet")
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]
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]
253 // [swift_LocationWindow_addIconMapObject]
254 // Add icon map object
255 iconMapObject = locationWindow.addIconMapObject()
256 print("Added icon map object")
257 // [swift_LocationWindow_addIconMapObject]
259 if let iconMapObject = iconMapObject {
260 // [swift_IconMapObject_setPosition]
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]
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]
274 // [swift_IconMapObject_setIcon]
276 let iconSuccess = iconMapObject.setIcon("path/to/icon.png")
277 print("Set icon image: \(iconSuccess)")
278 // [swift_IconMapObject_setIcon]
280 // [swift_IconMapObject_setBitmap]
282 let bitmapSuccess = iconMapObject.setBitmap("path/to/bitmap.png")
283 print("Set icon bitmap: \(bitmapSuccess)")
284 // [swift_IconMapObject_setBitmap]
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]
292 // [swift_IconMapObject_setSize]
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]
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]
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]
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]
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]
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]
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]
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]
341 // [swift_IconMapObject_setVisible]
343 let visibleSuccess = iconMapObject.setVisible(true)
344 print("Set icon visibility to true: \(visibleSuccess)")
345 // [swift_IconMapObject_setVisible]
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]
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]
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]
365 // [swift_MapObject_setTitle_1]
367 let titleSuccess = iconMapObject.setTitle("Icon Object")
368 print("Set icon title to 'Icon Object': \(titleSuccess)")
369 // [swift_MapObject_setTitle_1]
371 // [swift_MapObject_setData_1]
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]
378 // [swift_MapObject_getId_1]
380 let objectId = iconMapObject.id
381 print("Icon object ID: \(objectId)")
382 // [swift_MapObject_getId_1]
384 // [swift_MapObject_getType_1]
386 let objectTypeString = iconMapObject.type
387 print("Icon object type: \(objectTypeString)")
388 // [swift_MapObject_getType_1]
390 // [swift_MapObject_getData_1]
392 let retrievedData = iconMapObject.data
393 print("Icon custom data: \(retrievedData)")
394 // [swift_MapObject_getData_1]
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
404 // [swift_LocationWindow_removeIconMapObject]
406 // Test multiple icon objects
407 var icons: [NCIconMapObject] = []
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))
414 print("Created icon \(i) at (\(60.0 * Double(i)), \(120.0 * Double(i)))")
418 for i in icons.indices {
419 locationWindow.removeIconMapObject(icons[i])
420 print("Removed icon \(i)")
425 * Demonstrate polygon map objects
427 private func demonstratePolygonMapObjects() {
428 print("--- Polygon Map Objects ---")
430 guard let locationWindow = locationWindow else {
431 print("LocationWindow not available yet")
435 // [swift_LocationWindow_addPolygonMapObject]
436 // Add polygon map object
437 polygonMapObject = locationWindow.addPolygonMapObject()
438 print("Added polygon map object")
439 // [swift_LocationWindow_addPolygonMapObject]
441 if let polygonMapObject = polygonMapObject {
442 // [swift_PolygonMapObject_setPolygon]
443 // Set polygon geometry
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)
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]
455 // [swift_PolygonMapObject_setColor]
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]
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]
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]
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]
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]
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]
491 // [swift_PolygonMapObject_setVisible]
493 let visibleSuccess = polygonMapObject.setVisible(true)
494 print("Set polygon visibility to true: \(visibleSuccess)")
495 // [swift_PolygonMapObject_setVisible]
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]
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]
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]
515 // [swift_MapObject_setTitle_2]
517 let titleSuccess = polygonMapObject.setTitle("Polygon Object")
518 print("Set polygon title to 'Polygon Object': \(titleSuccess)")
519 // [swift_MapObject_setTitle_2]
521 // [swift_MapObject_setData_2]
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]
528 // [swift_MapObject_getId_2]
530 let objectId = polygonMapObject.id
531 print("Polygon object ID: \(objectId)")
532 // [swift_MapObject_getId_2]
534 // [swift_MapObject_getType_2]
536 let objectTypeString = polygonMapObject.type
537 print("Polygon object type: \(objectTypeString)")
538 // [swift_MapObject_getType_2]
540 // [swift_MapObject_getData_2]
542 let retrievedData = polygonMapObject.data
543 print("Polygon custom data: \(retrievedData)")
544 // [swift_MapObject_getData_2]
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
554 // [swift_LocationWindow_removePolygonMapObject]
556 // Test multiple polygon objects
557 var polygons: [NCPolygonMapObject] = []
559 if let polygon = locationWindow.addPolygonMapObject() {
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)
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")
574 for i in polygons.indices {
575 locationWindow.removePolygonMapObject(polygons[i])
576 print("Removed polygon \(i)")
581 * Demonstrate polyline map objects
583 private func demonstratePolylineMapObjects() {
584 print("--- Polyline Map Objects ---")
586 guard let locationWindow = locationWindow else {
587 print("LocationWindow not available yet")
591 // [swift_PolylineMapObject_constructor]
592 // Create polyline map object
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)
599 let polyline = NCLocationPolyline(points: points)
600 polylineMapObject = locationWindow.addPolylineMapObject()
601 print("Created polyline map object with \(points.count) points")
602 // [swift_PolylineMapObject_constructor]
604 // [swift_PolylineMapObject_getPolyline]
606 let polylineShape = polylineMapObject!.getPolyLine()
607 print("Polyline has \(polylineShape.points.count) points")
608 // [swift_PolylineMapObject_getPolyline]
610 // [swift_LocationWindow_addPolylineMapObject]
611 // Add polyline map object
612 polylineMapObject = locationWindow.addPolylineMapObject()
613 print("Added polyline map object")
614 // [swift_LocationWindow_addPolylineMapObject]
616 if let polylineMapObject = polylineMapObject {
617 // [swift_PolylineMapObject_setPolyLine]
618 // Set polyline geometry
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)
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
708 // [swift_PolylineMapObject_setVisible]
710 let visibleSuccess = polylineMapObject.setVisible(true)
711 print("Set polyline visibility to true: \(visibleSuccess)")
712 // [swift_PolylineMapObject_setVisible]
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]
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]
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]
732 // [swift_MapObject_setTitle_3]
734 let titleSuccess = polylineMapObject.setTitle("Polyline Object")
735 print("Set polyline title to 'Polyline Object': \(titleSuccess)")
736 // [swift_MapObject_setTitle_3]
738 // [swift_MapObject_setData_3]
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]
745 // [swift_MapObject_getId_3]
747 let objectId = polylineMapObject.id
748 print("Polyline object ID: \(objectId)")
749 // [swift_MapObject_getId_3]
751 // [swift_MapObject_getType_3]
753 let objectTypeString = polylineMapObject.type
754 print("Polyline object type: \(objectTypeString)")
755 // [swift_MapObject_getType_3]
757 // [swift_MapObject_getData_3]
759 let retrievedData = polylineMapObject.data
760 print("Polyline custom data: \(retrievedData)")
761 // [swift_MapObject_getData_3]
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
771 // [swift_LocationWindow_removePolylineMapObject]
773 // Test multiple polyline objects
774 var polylines: [NCPolylineMapObject] = []
776 if let polyline = locationWindow.addPolylineMapObject() {
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)
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")
791 for i in polylines.indices {
792 locationWindow.removePolylineMapObject(polylines[i])
793 print("Removed polyline \(i)")
798 * Demonstrate dotted polyline map objects
800 private func demonstrateDottedPolylineMapObjects() {
801 print("--- Dotted Polyline Map Objects ---")
803 guard let locationWindow = locationWindow else {
804 print("LocationWindow not available yet")
808 // [swift_DottedPolylineMapObject_constructor]
809 // Create dotted polyline map object
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)
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]
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]
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]
833 if let dottedPolylineMapObject = dottedPolylineMapObject {
834 // [swift_DottedPolylineMapObject_setPolyline]
835 // Set dotted polyline geometry
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)
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
901 // [swift_DottedPolylineMapObject_setRepeatGroup]
903 let dottedRepeatGroupSuccess = dottedPolylineMapObject.setRepeatGroup(1)
904 print("Set dotted polyline repeat group to 1: \(dottedRepeatGroupSuccess)")
905 // [swift_DottedPolylineMapObject_setRepeatGroup]
907 // [swift_DottedPolylineMapObject_setSize]
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]
914 // [swift_DottedPolylineMapObject_setVisible]
916 let visibleSuccess = dottedPolylineMapObject.setVisible(true)
917 print("Set dotted polyline visibility to true: \(visibleSuccess)")
918 // [swift_DottedPolylineMapObject_setVisible]
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]
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]
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]
938 // [swift_MapObject_setTitle_4]
940 let titleSuccess = dottedPolylineMapObject.setTitle("Dotted Polyline Object")
941 print("Set dotted polyline title to 'Dotted Polyline Object': \(titleSuccess)")
942 // [swift_MapObject_setTitle_4]
944 // [swift_MapObject_setData_4]
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]
951 // [swift_MapObject_getId_4]
953 let objectId = dottedPolylineMapObject.id
954 print("Dotted polyline object ID: \(objectId)")
955 // [swift_MapObject_getId_4]
957 // [swift_MapObject_getType_4]
959 let objectTypeString = dottedPolylineMapObject.type
960 print("Dotted polyline object type: \(objectTypeString)")
961 // [swift_MapObject_getType_4]
963 // [swift_MapObject_getData_4]
965 let retrievedData = dottedPolylineMapObject.data
966 print("Dotted polyline custom data: \(retrievedData)")
967 // [swift_MapObject_getData_4]
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
977 // [swift_LocationWindow_removeDottedPolylineMapObject]
979 // Test multiple dotted polyline objects
980 var dottedPolylines: [NCDottedPolylineMapObject] = []
982 if let dottedPolyline = locationWindow.addDottedPolylineMapObject() {
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)
988 let polylineGeometry = NCLocationPolyline(points: points)
989 dottedPolyline.setPolyline(polylineGeometry)
990 dottedPolylines.append(dottedPolyline)
991 print("Created dotted polyline \(i) with \(points.count) points")
995 for i in dottedPolylines.indices {
996 locationWindow.removeDottedPolylineMapObject(dottedPolylines[i])
997 print("Removed dotted polyline \(i)")
1002 * Demonstrate remove all map objects
1004 private func demonstrateRemoveAllMapObjects() {
1005 print("--- Remove All Map Objects ---")
1007 guard let locationWindow = locationWindow else {
1008 print("LocationWindow not available yet")
1012 print("Current map objects count: \(getMapObjectsCount())")
1014 // [swift_LocationWindow_removeAllMapObjects]
1015 // Remove all map objects
1016 locationWindow.removeAllMapObjects()
1017 print("Removed all map objects")
1018 // [swift_LocationWindow_removeAllMapObjects]
1020 print("Map objects count after removal: \(getMapObjectsCount())")
1024 * Get current map objects count
1026 private func getMapObjectsCount() -> Int {
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 }
1039 private func cleanup() {
1040 print("--- Cleanup ---")
1042 if let locationWindow = locationWindow {
1043 locationWindow.removeAllMapObjects()
1044 print("Cleaned up all map objects")
1047 circleMapObject = nil
1049 polygonMapObject = nil
1050 polylineMapObject = nil
1051 dottedPolylineMapObject = nil
1052 print("Cleared map objects references")
1056// Main function to run the example
1057let example = LocationWindowMapObjectsExample()