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 demonstrateLocationScopedGeometryRecords()
33 demonstrateCircleMapObjects()
34 demonstrateIconMapObjects()
35 demonstratePolygonMapObjects()
36 demonstratePolylineMapObjects()
37 demonstrateDottedPolylineMapObjects()
38 demonstrateRemoveAllMapObjects()
44 * Metrics geometry scoped to a location / sublocation (@see NCLocationPolygon, NCLocationPolyline).
46 private func demonstrateLocationScopedGeometryRecords() {
47 print("--- LocationPolygon / LocationPolyline records ---")
49 // [swift_LocationPolygon_record]
51 NCPoint(x: 1.0, y: 2.0),
52 NCPoint(x: 3.0, y: 4.0),
53 NCPoint(x: 5.0, y: 2.0),
55 let metricPolygon = NCPolygon(points: ring)
56 let locationPolygon = NCLocationPolygon(polygon: metricPolygon, locationId: 42, sublocationId: 7)
57 let polygonBack = locationPolygon.polygon
58 print("LocationPolygon location \(locationPolygon.locationId) sublocation \(locationPolygon.sublocationId) vertices \(polygonBack.points.count)")
59 // [swift_LocationPolygon_record]
61 // [swift_LocationPolyline_record]
62 let linePts = [NCPoint(x: 0.0, y: 0.0), NCPoint(x: 10.0, y: 10.0)]
63 let metricPolyline = NCPolyline(points: linePts)
64 let locationPolyline = NCLocationPolyline(polyline: metricPolyline, locationId: 42, sublocationId: 7)
65 let polylineBack = locationPolyline.polyline
66 print("LocationPolyline points \(polylineBack.points.count)")
67 // [swift_LocationPolyline_record]
71 * Demonstrate circle map objects
73 private func demonstrateCircleMapObjects() {
74 print("--- Circle Map Objects ---")
76 guard let locationWindow = locationWindow else {
77 print("LocationWindow not available yet")
81 // [swift_CircleMapObject_constructor]
82 // Create circle map object
83 let center = NCLocationPoint(x: 10.0, y: 20.0)
84 circleMapObject = locationWindow.addCircleMapObject()
85 print("Created circle map object with center (\(center.x), \(center.y)) and radius 5.0")
86 // [swift_CircleMapObject_constructor]
88 // [swift_CircleMapObject_getCenter]
89 // Access circle center
90 let circleCenter = circleMapObject!.getPosition()
91 print("Circle center: (\(circleCenter.x), \(circleCenter.y))")
92 // [swift_CircleMapObject_getCenter]
94 // [swift_CircleMapObject_getRadius]
95 // Access circle radius
96 let radius = circleMapObject!.getRadius()
97 print("Circle radius: \(radius)")
98 // [swift_CircleMapObject_getRadius]
100 // [swift_LocationWindow_addCircleMapObject]
101 // Add circle map object
102 circleMapObject = locationWindow.addCircleMapObject()
103 print("Added circle map object")
104 // [swift_LocationWindow_addCircleMapObject]
106 if let circleMapObject = circleMapObject {
107 // [swift_CircleMapObject_setPosition]
108 // Set circle position
109 let centerPoint = NCLocationPoint(x: 100.0, y: 200.0)
110 let success = circleMapObject.setPosition(centerPoint)
111 print("Set circle position to (\(centerPoint.x), \(centerPoint.y)): \(success)")
112 // [swift_CircleMapObject_setPosition]
114 // [swift_CircleMapObject_setPositionAnimated]
115 // Set circle position with animation
116 let animatedPoint = NCLocationPoint(x: 150.0, y: 250.0)
117 let animatedSuccess = circleMapObject.setPositionAnimated(animatedPoint, duration: 2.0, animationType: .linear)
118 print("Set circle position with animation to (\(animatedPoint.x), \(animatedPoint.y)): \(animatedSuccess)")
119 // [swift_CircleMapObject_setPositionAnimated]
121 // [swift_CircleMapObject_setRadius]
123 let radiusSuccess = circleMapObject.setRadius(10.0)
124 print("Set circle radius to 10.0 meters: \(radiusSuccess)")
125 // [swift_CircleMapObject_setRadius]
127 // [swift_CircleMapObject_setCollisionEnabled]
128 // Enable collision detection
129 let collisionSuccess = circleMapObject.setCollisionEnabled(true)
130 print("Enabled collision detection for circle: \(collisionSuccess)")
131 // [swift_CircleMapObject_setCollisionEnabled]
133 // [swift_CircleMapObject_setBuffer]
134 // Set collision buffer
135 let bufferSuccess = circleMapObject.setBuffer(width: 5.0, height: 5.0)
136 print("Set collision buffer to 5x5 pixels: \(bufferSuccess)")
137 // [swift_CircleMapObject_setBuffer]
139 // [swift_CircleMapObject_setOffset]
140 // Set position offset
141 let offsetSuccess = circleMapObject.setOffset(x: 2.0, y: 3.0)
142 print("Set position offset to (2.0, 3.0) pixels: \(offsetSuccess)")
143 // [swift_CircleMapObject_setOffset]
145 // [swift_CircleMapObject_setOutlineColor]
147 let outlineColorSuccess = circleMapObject.setOutlineColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
148 print("Set circle outline color to blue: \(outlineColorSuccess)")
149 // [swift_CircleMapObject_setOutlineColor]
151 // [swift_CircleMapObject_setOutlineAlpha]
153 let outlineAlphaSuccess = circleMapObject.setOutlineAlpha(0.5)
154 print("Set circle outline alpha to 0.5: \(outlineAlphaSuccess)")
155 // [swift_CircleMapObject_setOutlineAlpha]
157 // [swift_CircleMapObject_setOutlineRadius]
158 // Set outline radius
159 let outlineRadiusSuccess = circleMapObject.setOutlineRadius(2.0)
160 print("Set circle outline radius to 2.0: \(outlineRadiusSuccess)")
161 // [swift_CircleMapObject_setOutlineRadius]
163 // [swift_CircleMapObject_setColor]
165 let colorSuccess = circleMapObject.setColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8)
166 print("Set circle color to red with 80% opacity: \(colorSuccess)")
167 // [swift_CircleMapObject_setColor]
169 // [swift_CircleMapObject_setPriority]
170 // Set rendering priority
171 let prioritySuccess = circleMapObject.setPriority(1)
172 print("Set rendering priority to 1: \(prioritySuccess)")
173 // [swift_CircleMapObject_setPriority]
175 // [swift_MapObject_setVisible]
177 let visibleSuccess = circleMapObject.setVisible(true)
178 print("Set circle visibility to true: \(visibleSuccess)")
179 // [swift_MapObject_setVisible]
181 // [swift_CircleMapObject_getMapObjectType]
182 // Get map object type
183 let objectType = circleMapObject.mapObjectType
184 print("Circle map object type: \(objectType)")
185 // [swift_CircleMapObject_getMapObjectType]
187 // [swift_MapObject_setAlpha]
188 // Set alpha transparency
189 let alphaSuccess = circleMapObject.setAlpha(0.7)
190 print("Set circle alpha to 0.7: \(alphaSuccess)")
191 // [swift_MapObject_setAlpha]
193 // [swift_MapObject_setInteractive]
194 // Set interactive mode
195 let interactiveSuccess = circleMapObject.setInteractive(true)
196 print("Set circle interactive to true: \(interactiveSuccess)")
197 // [swift_MapObject_setInteractive]
199 // [swift_MapObject_setTitle]
201 let titleSuccess = circleMapObject.setTitle("Circle Object")
202 print("Set circle title to 'Circle Object': \(titleSuccess)")
203 // [swift_MapObject_setTitle]
205 // [swift_MapObject_setData]
207 let customData = ["key": "value", "number": "42"]
208 let dataSuccess = circleMapObject.setData(customData)
209 print("Set circle custom data: \(dataSuccess)")
210 // [swift_MapObject_setData]
212 // [swift_MapObject_getId]
214 let objectId = circleMapObject.id
215 print("Circle object ID: \(objectId)")
216 // [swift_MapObject_getId]
218 // [swift_MapObject_getType]
220 let objectTypeString = circleMapObject.type
221 print("Circle object type: \(objectTypeString)")
222 // [swift_MapObject_getType]
224 // [swift_MapObject_getData]
226 let retrievedData = circleMapObject.data
227 print("Circle custom data: \(retrievedData)")
228 // [swift_MapObject_getData]
231 // [swift_LocationWindow_removeCircleMapObject]
232 // Remove circle map object
233 if let circleMapObject = circleMapObject {
234 let removed = locationWindow.removeCircleMapObject(circleMapObject)
235 print("Removed circle map object: \(removed)")
236 self.circleMapObject = nil
238 // [swift_LocationWindow_removeCircleMapObject]
240 // Test multiple circle objects
241 var circles: [NCCircleMapObject] = []
243 if let circle = locationWindow.addCircleMapObject() {
244 circle.setPosition(NCLocationPoint(x: 50.0 * Double(i), y: 100.0 * Double(i)))
245 circle.setColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.6)
246 circle.setRadius(5.0 + Double(i) * 2.0)
247 circles.append(circle)
248 print("Created circle \(i) at (\(50.0 * Double(i)), \(100.0 * Double(i))) with radius \(5.0 + Double(i) * 2.0)")
252 for i in circles.indices {
253 locationWindow.removeCircleMapObject(circles[i])
254 print("Removed circle \(i)")
259 * Demonstrate icon map objects
261 private func demonstrateIconMapObjects() {
262 print("--- Icon Map Objects ---")
264 guard let locationWindow = locationWindow else {
265 print("LocationWindow not available yet")
269 // [swift_IconMapObject_constructor]
270 // Create icon map object
271 let position = NCLocationPoint(x: 30.0, y: 40.0)
272 iconMapObject = locationWindow.addIconMapObject()
273 print("Created icon map object at (\(position.x), \(position.y))")
274 // [swift_IconMapObject_constructor]
276 // [swift_IconMapObject_getPosition]
277 // Access icon position
278 let iconPosition = iconMapObject!.getPosition()
279 print("Icon position: (\(iconPosition.x), \(iconPosition.y))")
280 // [swift_IconMapObject_getPosition]
282 // [swift_LocationWindow_addIconMapObject]
283 // Add icon map object
284 iconMapObject = locationWindow.addIconMapObject()
285 print("Added icon map object")
286 // [swift_LocationWindow_addIconMapObject]
288 if let iconMapObject = iconMapObject {
289 // [swift_IconMapObject_setPosition]
291 let position = NCLocationPoint(x: 30.0, y: 40.0)
292 let success = iconMapObject.setPosition(position)
293 print("Set icon position to (\(position.x), \(position.y)): \(success)")
294 // [swift_IconMapObject_setPosition]
296 // [swift_IconMapObject_setPositionAnimated]
297 // Set icon position with animation
298 let animatedPosition = NCLocationPoint(x: 35.0, y: 45.0)
299 let animatedSuccess = iconMapObject.setPositionAnimated(animatedPosition, duration: 1.5, animationType: .cubic)
300 print("Set icon position with animation to (\(animatedPosition.x), \(animatedPosition.y)): \(animatedSuccess)")
301 // [swift_IconMapObject_setPositionAnimated]
303 // [swift_IconMapObject_setIcon]
305 let iconSuccess = iconMapObject.setIcon("path/to/icon.png")
306 print("Set icon image: \(iconSuccess)")
307 // [swift_IconMapObject_setIcon]
309 // [swift_IconMapObject_setBitmap]
311 let bitmapSuccess = iconMapObject.setBitmap("path/to/bitmap.png")
312 print("Set icon bitmap: \(bitmapSuccess)")
313 // [swift_IconMapObject_setBitmap]
315 // [swift_IconMapObject_setFlat]
316 // Set icon flat mode
317 let flatSuccess = iconMapObject.setFlat(true)
318 print("Set icon flat mode to true: \(flatSuccess)")
319 // [swift_IconMapObject_setFlat]
321 // [swift_IconMapObject_setSize]
323 let size = NCSize(width: 32.0, height: 32.0)
324 let sizeSuccess = iconMapObject.setSize(size)
325 print("Set icon size to (\(size.width), \(size.height)): \(sizeSuccess)")
326 // [swift_IconMapObject_setSize]
328 // [swift_IconMapObject_setAngle]
329 // Set icon rotation angle
330 let angleSuccess = iconMapObject.setAngle(45.0)
331 print("Set icon rotation angle to 45 degrees: \(angleSuccess)")
332 // [swift_IconMapObject_setAngle]
334 // [swift_IconMapObject_setAngleAnimated]
335 // Set icon rotation with animation
336 let angleAnimatedSuccess = iconMapObject.setAngleAnimated(90.0, duration: 2.0, animationType: .sine)
337 print("Set icon rotation with animation to 90 degrees: \(angleAnimatedSuccess)")
338 // [swift_IconMapObject_setAngleAnimated]
340 // [swift_IconMapObject_setCollisionEnabled]
341 // Enable collision detection
342 let collisionSuccess = iconMapObject.setCollisionEnabled(true)
343 print("Enabled collision detection for icon: \(collisionSuccess)")
344 // [swift_IconMapObject_setCollisionEnabled]
346 // [swift_IconMapObject_setBuffer]
347 // Set collision buffer
348 let bufferSuccess = iconMapObject.setBuffer(width: 10.0, height: 10.0)
349 print("Set collision buffer to 10x10 pixels: \(bufferSuccess)")
350 // [swift_IconMapObject_setBuffer]
352 // [swift_IconMapObject_setPlacement]
353 // Set icon placement
354 let placementSuccess = iconMapObject.setPlacement(.center)
355 print("Set icon placement to CENTER: \(placementSuccess)")
356 // [swift_IconMapObject_setPlacement]
358 // [swift_IconMapObject_setOffset]
359 // Set position offset
360 let offsetSuccess = iconMapObject.setOffset(x: 0.0, y: -16.0)
361 print("Set position offset to (0.0, -16.0) pixels: \(offsetSuccess)")
362 // [swift_IconMapObject_setOffset]
364 // [swift_IconMapObject_setPriority]
365 // Set rendering priority
366 let prioritySuccess = iconMapObject.setPriority(2)
367 print("Set rendering priority to 2: \(prioritySuccess)")
368 // [swift_IconMapObject_setPriority]
370 // [swift_IconMapObject_setVisible]
372 let visibleSuccess = iconMapObject.setVisible(true)
373 print("Set icon visibility to true: \(visibleSuccess)")
374 // [swift_IconMapObject_setVisible]
376 // [swift_IconMapObject_getMapObjectType]
377 // Get map object type
378 let objectType = iconMapObject.mapObjectType
379 print("Icon map object type: \(objectType)")
380 // [swift_IconMapObject_getMapObjectType]
382 // [swift_MapObject_setAlpha_1]
383 // Set alpha transparency
384 let alphaSuccess = iconMapObject.setAlpha(0.8)
385 print("Set icon alpha to 0.8: \(alphaSuccess)")
386 // [swift_MapObject_setAlpha_1]
388 // [swift_MapObject_setInteractive_1]
389 // Set interactive mode
390 let interactiveSuccess = iconMapObject.setInteractive(true)
391 print("Set icon interactive to true: \(interactiveSuccess)")
392 // [swift_MapObject_setInteractive_1]
394 // [swift_MapObject_setTitle_1]
396 let titleSuccess = iconMapObject.setTitle("Icon Object")
397 print("Set icon title to 'Icon Object': \(titleSuccess)")
398 // [swift_MapObject_setTitle_1]
400 // [swift_MapObject_setData_1]
402 let customData = ["key": "value", "number": "42"]
403 let dataSuccess = iconMapObject.setData(customData)
404 print("Set icon custom data: \(dataSuccess)")
405 // [swift_MapObject_setData_1]
407 // [swift_MapObject_getId_1]
409 let objectId = iconMapObject.id
410 print("Icon object ID: \(objectId)")
411 // [swift_MapObject_getId_1]
413 // [swift_MapObject_getType_1]
415 let objectTypeString = iconMapObject.type
416 print("Icon object type: \(objectTypeString)")
417 // [swift_MapObject_getType_1]
419 // [swift_MapObject_getData_1]
421 let retrievedData = iconMapObject.data
422 print("Icon custom data: \(retrievedData)")
423 // [swift_MapObject_getData_1]
426 // [swift_LocationWindow_removeIconMapObject]
427 // Remove icon map object
428 if let iconMapObject = iconMapObject {
429 let removed = locationWindow.removeIconMapObject(iconMapObject)
430 print("Removed icon map object: \(removed)")
431 self.iconMapObject = nil
433 // [swift_LocationWindow_removeIconMapObject]
435 // Test multiple icon objects
436 var icons: [NCIconMapObject] = []
438 if let icon = locationWindow.addIconMapObject() {
439 icon.setPosition(NCLocationPoint(x: 60.0 * Double(i), y: 120.0 * Double(i)))
440 icon.setIcon("path/to/icon\(i).png")
441 icon.setSize(NCSize(width: 24.0, height: 24.0))
443 print("Created icon \(i) at (\(60.0 * Double(i)), \(120.0 * Double(i)))")
447 for i in icons.indices {
448 locationWindow.removeIconMapObject(icons[i])
449 print("Removed icon \(i)")
454 * Demonstrate polygon map objects
456 private func demonstratePolygonMapObjects() {
457 print("--- Polygon Map Objects ---")
459 guard let locationWindow = locationWindow else {
460 print("LocationWindow not available yet")
464 // [swift_LocationWindow_addPolygonMapObject]
465 // Add polygon map object
466 polygonMapObject = locationWindow.addPolygonMapObject()
467 print("Added polygon map object")
468 // [swift_LocationWindow_addPolygonMapObject]
470 if let polygonMapObject = polygonMapObject {
471 // [swift_PolygonMapObject_setPolygon]
472 // Set polygon geometry
474 NCPoint(x: 50.0, y: 60.0),
475 NCPoint(x: 55.0, y: 65.0),
476 NCPoint(x: 60.0, y: 60.0),
477 NCPoint(x: 55.0, y: 55.0),
479 let metricPolygon = NCPolygon(points: points)
480 let polygon = NCLocationPolygon(polygon: metricPolygon, locationId: 1, sublocationId: 0)
481 let success = polygonMapObject.setPolygon(polygon)
482 print("Set polygon with \(points.count) points: \(success)")
483 // [swift_PolygonMapObject_setPolygon]
485 // [swift_PolygonMapObject_setColor]
487 let colorSuccess = polygonMapObject.setColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.7)
488 print("Set polygon color to green with 70% opacity: \(colorSuccess)")
489 // [swift_PolygonMapObject_setColor]
491 // [swift_PolygonMapObject_setOrder]
492 // Set polygon rendering order
493 let orderSuccess = polygonMapObject.setOrder(2)
494 print("Set polygon rendering order to 2: \(orderSuccess)")
495 // [swift_PolygonMapObject_setOrder]
497 // [swift_PolygonMapObject_setOutlineColor]
498 // Set polygon outline color
499 let outlineColorSuccess = polygonMapObject.setOutlineColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
500 print("Set polygon outline color to blue: \(outlineColorSuccess)")
501 // [swift_PolygonMapObject_setOutlineColor]
503 // [swift_PolygonMapObject_setOutlineWidth]
504 // Set polygon outline width
505 let outlineWidthSuccess = polygonMapObject.setOutlineWidth(2.0)
506 print("Set polygon outline width to 2.0 pixels: \(outlineWidthSuccess)")
507 // [swift_PolygonMapObject_setOutlineWidth]
509 // [swift_PolygonMapObject_setOutlineAlpha]
510 // Set polygon outline alpha
511 let outlineAlphaSuccess = polygonMapObject.setOutlineAlpha(0.8)
512 print("Set polygon outline alpha to 0.8: \(outlineAlphaSuccess)")
513 // [swift_PolygonMapObject_setOutlineAlpha]
515 // [swift_PolygonMapObject_setOutlineOrder]
516 // Set polygon outline order
517 let outlineOrderSuccess = polygonMapObject.setOutlineOrder(1)
518 print("Set polygon outline order to 1: \(outlineOrderSuccess)")
519 // [swift_PolygonMapObject_setOutlineOrder]
521 // [swift_PolygonMapObject_setVisible]
523 let visibleSuccess = polygonMapObject.setVisible(true)
524 print("Set polygon visibility to true: \(visibleSuccess)")
525 // [swift_PolygonMapObject_setVisible]
527 // [swift_PolygonMapObject_getMapObjectType]
528 // Get map object type
529 let objectType = polygonMapObject.mapObjectType
530 print("Polygon map object type: \(objectType)")
531 // [swift_PolygonMapObject_getMapObjectType]
533 // [swift_MapObject_setAlpha_2]
534 // Set alpha transparency
535 let alphaSuccess = polygonMapObject.setAlpha(0.6)
536 print("Set polygon alpha to 0.6: \(alphaSuccess)")
537 // [swift_MapObject_setAlpha_2]
539 // [swift_MapObject_setInteractive_2]
540 // Set interactive mode
541 let interactiveSuccess = polygonMapObject.setInteractive(true)
542 print("Set polygon interactive to true: \(interactiveSuccess)")
543 // [swift_MapObject_setInteractive_2]
545 // [swift_MapObject_setTitle_2]
547 let titleSuccess = polygonMapObject.setTitle("Polygon Object")
548 print("Set polygon title to 'Polygon Object': \(titleSuccess)")
549 // [swift_MapObject_setTitle_2]
551 // [swift_MapObject_setData_2]
553 let customData = ["key": "value", "number": "42"]
554 let dataSuccess = polygonMapObject.setData(customData)
555 print("Set polygon custom data: \(dataSuccess)")
556 // [swift_MapObject_setData_2]
558 // [swift_MapObject_getId_2]
560 let objectId = polygonMapObject.id
561 print("Polygon object ID: \(objectId)")
562 // [swift_MapObject_getId_2]
564 // [swift_MapObject_getType_2]
566 let objectTypeString = polygonMapObject.type
567 print("Polygon object type: \(objectTypeString)")
568 // [swift_MapObject_getType_2]
570 // [swift_MapObject_getData_2]
572 let retrievedData = polygonMapObject.data
573 print("Polygon custom data: \(retrievedData)")
574 // [swift_MapObject_getData_2]
577 // [swift_LocationWindow_removePolygonMapObject]
578 // Remove polygon map object
579 if let polygonMapObject = polygonMapObject {
580 let removed = locationWindow.removePolygonMapObject(polygonMapObject)
581 print("Removed polygon map object: \(removed)")
582 self.polygonMapObject = nil
584 // [swift_LocationWindow_removePolygonMapObject]
586 // Test multiple polygon objects
587 var polygons: [NCPolygonMapObject] = []
589 if let polygon = locationWindow.addPolygonMapObject() {
591 NCPoint(x: 300.0 + Double(i) * 50, y: 400.0 + Double(i) * 50),
592 NCPoint(x: 350.0 + Double(i) * 50, y: 450.0 + Double(i) * 50),
593 NCPoint(x: 400.0 + Double(i) * 50, y: 400.0 + Double(i) * 50),
594 NCPoint(x: 350.0 + Double(i) * 50, y: 350.0 + Double(i) * 50),
596 let metricPoly = NCPolygon(points: points)
597 let polygonGeometry = NCLocationPolygon(polygon: metricPoly, locationId: 1, sublocationId: 0)
598 polygon.setPolygon(polygonGeometry)
599 polygon.setColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.5)
600 polygons.append(polygon)
601 print("Created polygon \(i) with \(points.count) points")
605 for i in polygons.indices {
606 locationWindow.removePolygonMapObject(polygons[i])
607 print("Removed polygon \(i)")
612 * Demonstrate polyline map objects
614 private func demonstratePolylineMapObjects() {
615 print("--- Polyline Map Objects ---")
617 guard let locationWindow = locationWindow else {
618 print("LocationWindow not available yet")
622 // [swift_PolylineMapObject_constructor]
623 // Create polyline map object
625 NCPoint(x: 100.0, y: 110.0),
626 NCPoint(x: 105.0, y: 115.0),
627 NCPoint(x: 110.0, y: 120.0),
628 NCPoint(x: 115.0, y: 125.0),
630 let metricPolyline = NCPolyline(points: points)
631 let polyline = NCLocationPolyline(polyline: metricPolyline, locationId: 1, sublocationId: 0)
632 polylineMapObject = locationWindow.addPolylineMapObject()
633 print("Created polyline map object with \(points.count) points")
634 // [swift_PolylineMapObject_constructor]
636 // [swift_PolylineMapObject_getPolyline]
638 let polylineShape = polylineMapObject!.getPolyLine()
639 print("Polyline has \(polylineShape.polyline.points.count) points")
640 // [swift_PolylineMapObject_getPolyline]
642 // [swift_LocationWindow_addPolylineMapObject]
643 // Add polyline map object
644 polylineMapObject = locationWindow.addPolylineMapObject()
645 print("Added polyline map object")
646 // [swift_LocationWindow_addPolylineMapObject]
648 if let polylineMapObject = polylineMapObject {
649 // [swift_PolylineMapObject_setPolyLine]
650 // Set polyline geometry
652 NCPoint(x: 100.0, y: 110.0),
653 NCPoint(x: 105.0, y: 115.0),
654 NCPoint(x: 110.0, y: 120.0),
655 NCPoint(x: 115.0, y: 125.0),
657 let metricPl = NCPolyline(points: points)
658 let polyline = NCLocationPolyline(polyline: metricPl, locationId: 1, sublocationId: 0)
659 let success = polylineMapObject.setPolyLine(polyline)
660 print("Set polyline with \(points.count) points: \(success)")
661 // [swift_PolylineMapObject_setPolyLine]
663 // [swift_PolylineMapObject_setWidth]
664 // Set polyline width
665 let widthSuccess = polylineMapObject.setWidth(3.0)
666 print("Set polyline width to 3.0 pixels: \(widthSuccess)")
667 // [swift_PolylineMapObject_setWidth]
669 // [swift_PolylineMapObject_setColor]
670 // Set polyline color
671 let colorSuccess = polylineMapObject.setColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.8)
672 print("Set polyline color to green with 80% opacity: \(colorSuccess)")
673 // [swift_PolylineMapObject_setColor]
675 // [swift_PolylineMapObject_setOrder]
676 // Set polyline rendering order
677 let orderSuccess = polylineMapObject.setOrder(1)
678 print("Set polyline rendering order to 1: \(orderSuccess)")
679 // [swift_PolylineMapObject_setOrder]
681 // [swift_PolylineMapObject_setCapType]
682 // Set polyline cap type
683 let capTypeSuccess = polylineMapObject.setCapType(.round)
684 print("Set polyline cap type to ROUND: \(capTypeSuccess)")
685 // [swift_PolylineMapObject_setCapType]
687 // [swift_PolylineMapObject_setJoinType]
688 // Set polyline join type
689 let joinTypeSuccess = polylineMapObject.setJoinType(.round)
690 print("Set polyline join type to ROUND: \(joinTypeSuccess)")
691 // [swift_PolylineMapObject_setJoinType]
693 // [swift_PolylineMapObject_setMiterLimit]
694 // Set polyline miter limit
695 let miterLimitSuccess = polylineMapObject.setMiterLimit(2.0)
696 print("Set polyline miter limit to 2.0: \(miterLimitSuccess)")
697 // [swift_PolylineMapObject_setMiterLimit]
699 // [swift_PolylineMapObject_setOutlineWidth]
700 // Set polyline outline width
701 let outlineWidthSuccess = polylineMapObject.setOutlineWidth(1.0)
702 print("Set polyline outline width to 1.0 pixels: \(outlineWidthSuccess)")
703 // [swift_PolylineMapObject_setOutlineWidth]
705 // [swift_PolylineMapObject_setOutlineColor]
706 // Set polyline outline color
707 let outlineColorSuccess = polylineMapObject.setOutlineColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
708 print("Set polyline outline color to black: \(outlineColorSuccess)")
709 // [swift_PolylineMapObject_setOutlineColor]
711 // [swift_PolylineMapObject_setOutlineAlpha]
712 // Set polyline outline alpha
713 let outlineAlphaSuccess = polylineMapObject.setOutlineAlpha(0.5)
714 print("Set polyline outline alpha to 0.5: \(outlineAlphaSuccess)")
715 // [swift_PolylineMapObject_setOutlineAlpha]
717 // [swift_PolylineMapObject_setOutlineOrder]
718 // Set polyline outline rendering order
719 let outlineOrderSuccess = polylineMapObject.setOutlineOrder(0)
720 print("Set polyline outline rendering order to 0: \(outlineOrderSuccess)")
721 // [swift_PolylineMapObject_setOutlineOrder]
723 // [swift_PolylineMapObject_setOutlineCapType]
724 // Set polyline outline cap type
725 let outlineCapTypeSuccess = polylineMapObject.setOutlineCapType(.square)
726 print("Set polyline outline cap type to SQUARE: \(outlineCapTypeSuccess)")
727 // [swift_PolylineMapObject_setOutlineCapType]
729 // [swift_PolylineMapObject_setOutlineJoinType]
730 // Set polyline outline join type
731 let outlineJoinTypeSuccess = polylineMapObject.setOutlineJoinType(.miter)
732 print("Set polyline outline join type to MITER: \(outlineJoinTypeSuccess)")
733 // [swift_PolylineMapObject_setOutlineJoinType]
735 // [swift_PolylineMapObject_setOutlineMiterLimit]
736 // Set polyline outline miter limit
737 let outlineMiterLimitSuccess = polylineMapObject.setOutlineMiterLimit(3.0)
738 print("Set polyline outline miter limit to 3.0: \(outlineMiterLimitSuccess)")
739 // [swift_PolylineMapObject_setOutlineMiterLimit]
741 // [swift_PolylineMapObject_setVisible]
743 let visibleSuccess = polylineMapObject.setVisible(true)
744 print("Set polyline visibility to true: \(visibleSuccess)")
745 // [swift_PolylineMapObject_setVisible]
747 // [swift_PolylineMapObject_getMapObjectType]
748 // Get map object type
749 let objectType = polylineMapObject.mapObjectType
750 print("Polyline map object type: \(objectType)")
751 // [swift_PolylineMapObject_getMapObjectType]
753 // [swift_MapObject_setAlpha_3]
754 // Set alpha transparency
755 let alphaSuccess = polylineMapObject.setAlpha(0.7)
756 print("Set polyline alpha to 0.7: \(alphaSuccess)")
757 // [swift_MapObject_setAlpha_3]
759 // [swift_MapObject_setInteractive_3]
760 // Set interactive mode
761 let interactiveSuccess = polylineMapObject.setInteractive(true)
762 print("Set polyline interactive to true: \(interactiveSuccess)")
763 // [swift_MapObject_setInteractive_3]
765 // [swift_MapObject_setTitle_3]
767 let titleSuccess = polylineMapObject.setTitle("Polyline Object")
768 print("Set polyline title to 'Polyline Object': \(titleSuccess)")
769 // [swift_MapObject_setTitle_3]
771 // [swift_MapObject_setData_3]
773 let customData = ["key": "value", "number": "42"]
774 let dataSuccess = polylineMapObject.setData(customData)
775 print("Set polyline custom data: \(dataSuccess)")
776 // [swift_MapObject_setData_3]
778 // [swift_MapObject_getId_3]
780 let objectId = polylineMapObject.id
781 print("Polyline object ID: \(objectId)")
782 // [swift_MapObject_getId_3]
784 // [swift_MapObject_getType_3]
786 let objectTypeString = polylineMapObject.type
787 print("Polyline object type: \(objectTypeString)")
788 // [swift_MapObject_getType_3]
790 // [swift_MapObject_getData_3]
792 let retrievedData = polylineMapObject.data
793 print("Polyline custom data: \(retrievedData)")
794 // [swift_MapObject_getData_3]
797 // [swift_LocationWindow_removePolylineMapObject]
798 // Remove polyline map object
799 if let polylineMapObject = polylineMapObject {
800 let removed = locationWindow.removePolylineMapObject(polylineMapObject)
801 print("Removed polyline map object: \(removed)")
802 self.polylineMapObject = nil
804 // [swift_LocationWindow_removePolylineMapObject]
806 // Test multiple polyline objects
807 var polylines: [NCPolylineMapObject] = []
809 if let polyline = locationWindow.addPolylineMapObject() {
811 NCPoint(x: 120.0 + Double(i) * 30, y: 130.0 + Double(i) * 30),
812 NCPoint(x: 125.0 + Double(i) * 30, y: 135.0 + Double(i) * 30),
813 NCPoint(x: 130.0 + Double(i) * 30, y: 140.0 + Double(i) * 30),
815 let metricPl = NCPolyline(points: points)
816 let polylineGeometry = NCLocationPolyline(polyline: metricPl, locationId: 1, sublocationId: 0)
817 polyline.setPolyLine(polylineGeometry)
818 polyline.setColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6)
819 polyline.setWidth(2.0)
820 polylines.append(polyline)
821 print("Created polyline \(i) with \(points.count) points")
825 for i in polylines.indices {
826 locationWindow.removePolylineMapObject(polylines[i])
827 print("Removed polyline \(i)")
832 * Demonstrate dotted polyline map objects
834 private func demonstrateDottedPolylineMapObjects() {
835 print("--- Dotted Polyline Map Objects ---")
837 guard let locationWindow = locationWindow else {
838 print("LocationWindow not available yet")
842 // [swift_DottedPolylineMapObject_constructor]
843 // Create dotted polyline map object
845 NCPoint(x: 160.0, y: 170.0),
846 NCPoint(x: 165.0, y: 175.0),
847 NCPoint(x: 170.0, y: 180.0),
848 NCPoint(x: 175.0, y: 185.0),
850 let dottedMetric = NCPolyline(points: points)
851 let polyline = NCLocationPolyline(polyline: dottedMetric, locationId: 1, sublocationId: 0)
852 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
853 print("Created dotted polyline map object with \(points.count) points")
854 // [swift_DottedPolylineMapObject_constructor]
856 // [swift_DottedPolylineMapObject_getPolyline]
857 // Access dotted polyline
858 let dottedPolylineShape = dottedPolylineMapObject!.getPolyLine()
859 print("Dotted polyline has \(dottedPolylineShape.polyline.points.count) points")
860 // [swift_DottedPolylineMapObject_getPolyline]
862 // [swift_LocationWindow_addDottedPolylineMapObject]
863 // Add dotted polyline map object
864 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
865 print("Added dotted polyline map object")
866 // [swift_LocationWindow_addDottedPolylineMapObject]
868 if let dottedPolylineMapObject = dottedPolylineMapObject {
869 // [swift_DottedPolylineMapObject_setPolyline]
870 // Set dotted polyline geometry
872 NCPoint(x: 160.0, y: 170.0),
873 NCPoint(x: 165.0, y: 175.0),
874 NCPoint(x: 170.0, y: 180.0),
875 NCPoint(x: 175.0, y: 185.0),
877 let dottedPl = NCPolyline(points: points)
878 let polyline = NCLocationPolyline(polyline: dottedPl, locationId: 1, sublocationId: 0)
879 let success = dottedPolylineMapObject.setPolyline(polyline)
880 print("Set dotted polyline with \(points.count) points: \(success)")
881 // [swift_DottedPolylineMapObject_setPolyline]
883 // [swift_DottedPolylineMapObject_setColor]
884 // Set dotted polyline color
885 let colorSuccess = dottedPolylineMapObject.setColor(red: 0.5, green: 0.0, blue: 1.0, alpha: 0.8)
886 print("Set dotted polyline color to purple with 80% opacity: \(colorSuccess)")
887 // [swift_DottedPolylineMapObject_setColor]
889 // [swift_DottedPolylineMapObject_setWidth]
890 // Set dotted polyline width
891 let widthSuccess = dottedPolylineMapObject.setWidth(3.0)
892 print("Set dotted polyline width to 3.0 pixels: \(widthSuccess)")
893 // [swift_DottedPolylineMapObject_setWidth]
895 // [swift_DottedPolylineMapObject_setOrder]
896 // Set dotted polyline rendering order
897 let orderSuccess = dottedPolylineMapObject.setOrder(2)
898 print("Set dotted polyline rendering order to 2: \(orderSuccess)")
899 // [swift_DottedPolylineMapObject_setOrder]
901 // [swift_DottedPolylineMapObject_setCollisionEnabled]
902 // Enable collision detection
903 let dottedCollisionSuccess = dottedPolylineMapObject.setCollisionEnabled(true)
904 print("Enabled collision detection for dotted polyline: \(dottedCollisionSuccess)")
905 // [swift_DottedPolylineMapObject_setCollisionEnabled]
907 // [swift_DottedPolylineMapObject_setPlacement]
908 // Set placement type
909 let dottedPlacementSuccess = dottedPolylineMapObject.setPlacement(.center)
910 print("Set dotted polyline placement to CENTER: \(dottedPlacementSuccess)")
911 // [swift_DottedPolylineMapObject_setPlacement]
913 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
914 // Set placement min ratio
915 let dottedMinRatioSuccess = dottedPolylineMapObject.setPlacementMinRatio(0.5)
916 print("Set dotted polyline placement min ratio to 0.5: \(dottedMinRatioSuccess)")
917 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
919 // [swift_DottedPolylineMapObject_setPlacementSpacing]
920 // Set placement spacing
921 let dottedSpacingSuccess = dottedPolylineMapObject.setPlacementSpacing(10.0)
922 print("Set dotted polyline placement spacing to 10.0: \(dottedSpacingSuccess)")
923 // [swift_DottedPolylineMapObject_setPlacementSpacing]
925 // [swift_DottedPolylineMapObject_setPriority]
926 // Set rendering priority
927 let dottedPrioritySuccess = dottedPolylineMapObject.setPriority(1)
928 print("Set dotted polyline rendering priority to 1: \(dottedPrioritySuccess)")
929 // [swift_DottedPolylineMapObject_setPriority]
931 // [swift_DottedPolylineMapObject_setRepeatDistance]
932 // Set repeat distance
933 let dottedRepeatDistanceSuccess = dottedPolylineMapObject.setRepeatDistance(20.0)
934 print("Set dotted polyline repeat distance to 20.0: \(dottedRepeatDistanceSuccess)")
935 // [swift_DottedPolylineMapObject_setRepeatDistance]
937 // [swift_DottedPolylineMapObject_setRepeatGroup]
939 let dottedRepeatGroupSuccess = dottedPolylineMapObject.setRepeatGroup(1)
940 print("Set dotted polyline repeat group to 1: \(dottedRepeatGroupSuccess)")
941 // [swift_DottedPolylineMapObject_setRepeatGroup]
943 // [swift_DottedPolylineMapObject_setSize]
945 let dottedSize = NCSize(width: 16.0, height: 16.0)
946 let dottedSizeSuccess = dottedPolylineMapObject.setSize(dottedSize)
947 print("Set dotted polyline size to (\(dottedSize.width), \(dottedSize.height)): \(dottedSizeSuccess)")
948 // [swift_DottedPolylineMapObject_setSize]
950 // [swift_DottedPolylineMapObject_setVisible]
952 let visibleSuccess = dottedPolylineMapObject.setVisible(true)
953 print("Set dotted polyline visibility to true: \(visibleSuccess)")
954 // [swift_DottedPolylineMapObject_setVisible]
956 // [swift_DottedPolylineMapObject_getMapObjectType]
957 // Get map object type
958 let objectType = dottedPolylineMapObject.mapObjectType
959 print("Dotted polyline map object type: \(objectType)")
960 // [swift_DottedPolylineMapObject_getMapObjectType]
962 // [swift_MapObject_setAlpha_4]
963 // Set alpha transparency
964 let alphaSuccess = dottedPolylineMapObject.setAlpha(0.8)
965 print("Set dotted polyline alpha to 0.8: \(alphaSuccess)")
966 // [swift_MapObject_setAlpha_4]
968 // [swift_MapObject_setInteractive_4]
969 // Set interactive mode
970 let interactiveSuccess = dottedPolylineMapObject.setInteractive(true)
971 print("Set dotted polyline interactive to true: \(interactiveSuccess)")
972 // [swift_MapObject_setInteractive_4]
974 // [swift_MapObject_setTitle_4]
976 let titleSuccess = dottedPolylineMapObject.setTitle("Dotted Polyline Object")
977 print("Set dotted polyline title to 'Dotted Polyline Object': \(titleSuccess)")
978 // [swift_MapObject_setTitle_4]
980 // [swift_MapObject_setData_4]
982 let customData = ["key": "value", "number": "42"]
983 let dataSuccess = dottedPolylineMapObject.setData(customData)
984 print("Set dotted polyline custom data: \(dataSuccess)")
985 // [swift_MapObject_setData_4]
987 // [swift_MapObject_getId_4]
989 let objectId = dottedPolylineMapObject.id
990 print("Dotted polyline object ID: \(objectId)")
991 // [swift_MapObject_getId_4]
993 // [swift_MapObject_getType_4]
995 let objectTypeString = dottedPolylineMapObject.type
996 print("Dotted polyline object type: \(objectTypeString)")
997 // [swift_MapObject_getType_4]
999 // [swift_MapObject_getData_4]
1001 let retrievedData = dottedPolylineMapObject.data
1002 print("Dotted polyline custom data: \(retrievedData)")
1003 // [swift_MapObject_getData_4]
1006 // [swift_LocationWindow_removeDottedPolylineMapObject]
1007 // Remove dotted polyline map object
1008 if let dottedPolylineMapObject = dottedPolylineMapObject {
1009 let removed = locationWindow.removeDottedPolylineMapObject(dottedPolylineMapObject)
1010 print("Removed dotted polyline map object: \(removed)")
1011 self.dottedPolylineMapObject = nil
1013 // [swift_LocationWindow_removeDottedPolylineMapObject]
1015 // Test multiple dotted polyline objects
1016 var dottedPolylines: [NCDottedPolylineMapObject] = []
1018 if let dottedPolyline = locationWindow.addDottedPolylineMapObject() {
1020 NCPoint(x: 180.0 + Double(i) * 30, y: 190.0 + Double(i) * 30),
1021 NCPoint(x: 185.0 + Double(i) * 30, y: 195.0 + Double(i) * 30),
1022 NCPoint(x: 190.0 + Double(i) * 30, y: 200.0 + Double(i) * 30),
1024 let pl = NCPolyline(points: points)
1025 let polylineGeometry = NCLocationPolyline(polyline: pl, locationId: 1, sublocationId: 0)
1026 dottedPolyline.setPolyline(polylineGeometry)
1027 dottedPolylines.append(dottedPolyline)
1028 print("Created dotted polyline \(i) with \(points.count) points")
1032 for i in dottedPolylines.indices {
1033 locationWindow.removeDottedPolylineMapObject(dottedPolylines[i])
1034 print("Removed dotted polyline \(i)")
1039 * Demonstrate remove all map objects
1041 private func demonstrateRemoveAllMapObjects() {
1042 print("--- Remove All Map Objects ---")
1044 guard let locationWindow = locationWindow else {
1045 print("LocationWindow not available yet")
1049 print("Current map objects count: \(getMapObjectsCount())")
1051 // [swift_LocationWindow_removeAllMapObjects]
1052 // Remove all map objects
1053 locationWindow.removeAllMapObjects()
1054 print("Removed all map objects")
1055 // [swift_LocationWindow_removeAllMapObjects]
1057 print("Map objects count after removal: \(getMapObjectsCount())")
1061 * Get current map objects count
1063 private func getMapObjectsCount() -> Int {
1065 if circleMapObject != nil { count += 1 }
1066 if iconMapObject != nil { count += 1 }
1067 if polygonMapObject != nil { count += 1 }
1068 if polylineMapObject != nil { count += 1 }
1069 if dottedPolylineMapObject != nil { count += 1 }
1076 private func cleanup() {
1077 print("--- Cleanup ---")
1079 if let locationWindow = locationWindow {
1080 locationWindow.removeAllMapObjects()
1081 print("Cleaned up all map objects")
1084 circleMapObject = nil
1086 polygonMapObject = nil
1087 polylineMapObject = nil
1088 dottedPolylineMapObject = nil
1089 print("Cleared map objects references")
1093// Main function to run the example
1094let example = LocationWindowMapObjectsExample()