6 * LocationWindowMapObjects usage example for Swift
7 * Demonstrates specific methods: addCircleMapObject, removeCircleMapObject, addIconMapObject,
8 * removeIconMapObject, addPolygonMapObject, addPolylineMapObject, removePolylineMapObject,
9 * addDottedPolylineMapObject, removeDottedPolylineMapObject, addModelMapObject, removeModelMapObject, removeAllMapObjects
11class LocationWindowMapObjectsExample {
12 private var locationWindow: NCLocationWindow?
13 private var circleMapObject: NCCircleMapObject?
14 private var iconMapObject: NCIconMapObject?
15 private var modelMapObject: NCModelMapObject?
16 private var polygonMapObject: NCPolygonMapObject?
17 private var polylineMapObject: NCPolylineMapObject?
18 private var dottedPolylineMapObject: NCDottedPolylineMapObject?
19 private var clusterMapObjectController: NCClusterMapObjectController?
20 private var clusterMapObjectControllerListener: DemoClusterMapObjectControllerListener?
23 demonstrateLocationWindowMapObjectsMethods()
27 * Demonstrate LocationWindowMapObjects methods
29 private func demonstrateLocationWindowMapObjectsMethods() {
30 print("=== LocationWindowMapObjects Example ===")
32 // Initialize LocationWindow (in real app, this would be provided by the framework)
33 // locationWindow = getLocationWindow()
35 demonstrateLocationScopedGeometryRecords()
37 demonstrateCircleMapObjects()
38 demonstrateIconMapObjects()
39 demonstrateClusterMapObjects()
40 demonstrateModelMapObjects()
41 demonstratePolygonMapObjects()
42 demonstratePolylineMapObjects()
43 demonstrateDottedPolylineMapObjects()
44 demonstrateRemoveAllMapObjects()
50 * Metrics geometry scoped to a location / sublocation (@see NCLocationPolygon, NCLocationPolyline).
52 private func demonstrateLocationScopedGeometryRecords() {
53 print("--- LocationPolygon / LocationPolyline records ---")
55 // [swift_LocationPolygon_record]
57 NCGlobalPoint(latitude: 55.751, longitude: 37.617),
58 NCGlobalPoint(latitude: 55.752, longitude: 37.618),
59 NCGlobalPoint(latitude: 55.751, longitude: 37.619),
62 NCGlobalPoint(latitude: 55.7512, longitude: 37.6174),
63 NCGlobalPoint(latitude: 55.7514, longitude: 37.6176),
64 NCGlobalPoint(latitude: 55.7512, longitude: 37.6178),
66 let locationPolygon = NCLocationPolygon(points: ring, sublocationId: 7, innerRings: holes)
67 print("LocationPolygon: sublocation \(locationPolygon.sublocationId ?? -1), vertices \(locationPolygon.points.count), holes \(locationPolygon.innerRings.count)")
68 // [swift_LocationPolygon_record]
70 // [swift_LocationWindow_addPointBatch]
71 let batch = locationWindow?.addPointBatch()
73 NCPointSprite(position: NCGlobalPoint(latitude: 55.751, longitude: 37.617), heading: 0, color: UIColor.orange, size: 5),
74 NCPointSprite(position: NCGlobalPoint(latitude: 55.752, longitude: 37.618), heading: 90, color: UIColor.blue, size: 5),
76 let hit = batch?.hitTest(CGPoint(x: 12, y: 8), radius: 8)
77 print("PointBatch hit \(hit ?? -1)")
78 // [swift_LocationWindow_addPointBatch]
80 // [swift_LocationWindow_addGeoJson]
81 let geoJson = #"{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[37.617,55.751],[37.619,55.751],[37.619,55.752],[37.617,55.751]],[[37.6174,55.7512],[37.6176,55.7512],[37.6176,55.7514],[37.6174,55.7512]]]}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[37.617,55.751],[37.620,55.753]]}}]}"#
82 let imported = locationWindow?.addGeoJson(geoJson, sublocationId: 7)
83 print("GeoJSON polygons \(imported?.polygons.count ?? 0), lines \(imported?.polylines.count ?? 0)")
84 // [swift_LocationWindow_addGeoJson]
86 // [swift_LocationPolyline_record]
88 NCGlobalPoint(latitude: 55.751, longitude: 37.617),
89 NCGlobalPoint(latitude: 55.753, longitude: 37.620),
91 let locationPolyline = NCLocationPolyline(points: linePts, sublocationId: 7)
92 print("LocationPolyline points \(locationPolyline.points.count)")
93 // [swift_LocationPolyline_record]
97 * Demonstrate circle map objects
99 private func demonstrateCircleMapObjects() {
100 print("--- Circle Map Objects ---")
102 guard let locationWindow = locationWindow else {
103 print("LocationWindow not available yet")
107 // [swift_CircleMapObject_constructor]
108 // Create circle map object
109 let center = NCGlobalPoint(latitude: 10.0, longitude: 20.0)
110 circleMapObject = locationWindow.addCircleMapObject()
111 print("Created circle map object with center (\(center.latitude), \(center.longitude)) and radius 5.0")
112 // [swift_CircleMapObject_constructor]
114 // [swift_CircleMapObject_getRadius]
115 // Access circle radius
116 let radius = circleMapObject!.getRadius()
117 print("Circle radius: \(radius)")
118 // [swift_CircleMapObject_getRadius]
120 // [swift_LocationWindow_addCircleMapObject]
121 // Add circle map object
122 circleMapObject = locationWindow.addCircleMapObject()
123 print("Added circle map object")
124 // [swift_LocationWindow_addCircleMapObject]
126 if let circleMapObject = circleMapObject {
127 // [swift_CircleMapObject_setPosition]
128 // Set circle position
129 let centerPoint = NCGlobalPoint(latitude: 100.0, longitude: 200.0)
130 let success = circleMapObject.setPosition(centerPoint, sublocationId: 7)
131 print("Set circle position to (\(centerPoint.latitude), \(centerPoint.longitude)): \(success)")
132 // [swift_CircleMapObject_setPosition]
134 // [swift_CircleMapObject_setPositionAnimated]
135 // Set circle position with animation
136 let animatedPoint = NCGlobalPoint(latitude: 150.0, longitude: 250.0)
137 let animatedSuccess = circleMapObject.setPositionAnimated(animatedPoint, duration: 2.0, animationType: .linear)
138 print("Set circle position with animation to (\(animatedPoint.latitude), \(animatedPoint.longitude)): \(animatedSuccess)")
139 // [swift_CircleMapObject_setPositionAnimated]
141 // [swift_CircleMapObject_setRadius]
143 let radiusSuccess = circleMapObject.setRadius(10.0)
144 print("Set circle radius to 10.0 meters: \(radiusSuccess)")
145 // [swift_CircleMapObject_setRadius]
147 // [swift_CircleMapObject_setCollisionEnabled]
148 // Enable collision detection
149 let collisionSuccess = circleMapObject.setCollisionEnabled(true)
150 print("Enabled collision detection for circle: \(collisionSuccess)")
151 // [swift_CircleMapObject_setCollisionEnabled]
153 // [swift_CircleMapObject_setBuffer]
154 // Set collision buffer
155 let bufferSuccess = circleMapObject.setBuffer(width: 5.0, height: 5.0)
156 print("Set collision buffer to 5x5 pixels: \(bufferSuccess)")
157 // [swift_CircleMapObject_setBuffer]
159 // [swift_CircleMapObject_setOffset]
160 // Set position offset
161 let offsetSuccess = circleMapObject.setOffset(x: 2.0, longitude: 3.0)
162 print("Set position offset to (2.0, 3.0) pixels: \(offsetSuccess)")
163 // [swift_CircleMapObject_setOffset]
165 // [swift_CircleMapObject_setOutlineColor]
167 let outlineColorSuccess = circleMapObject.setOutlineColor(UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0))
168 print("Set circle outline color to blue: \(outlineColorSuccess)")
169 // [swift_CircleMapObject_setOutlineColor]
171 // [swift_CircleMapObject_setOutlineAlpha]
173 let outlineAlphaSuccess = circleMapObject.setOutlineAlpha(0.5)
174 print("Set circle outline alpha to 0.5: \(outlineAlphaSuccess)")
175 // [swift_CircleMapObject_setOutlineAlpha]
177 // [swift_CircleMapObject_setOutlineRadius]
178 // Set outline radius
179 let outlineRadiusSuccess = circleMapObject.setOutlineRadius(2.0)
180 print("Set circle outline radius to 2.0: \(outlineRadiusSuccess)")
181 // [swift_CircleMapObject_setOutlineRadius]
183 // [swift_CircleMapObject_setColor]
185 let colorSuccess = circleMapObject.setColor(UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8))
186 print("Set circle color to red with 80% opacity: \(colorSuccess)")
187 // [swift_CircleMapObject_setColor]
189 // [swift_CircleMapObject_setPriority]
190 // Set rendering priority
191 let prioritySuccess = circleMapObject.setPriority(1)
192 print("Set rendering priority to 1: \(prioritySuccess)")
193 // [swift_CircleMapObject_setPriority]
195 // [swift_MapObject_setVisible]
197 let visibleSuccess = circleMapObject.setVisible(true)
198 print("Set circle visibility to true: \(visibleSuccess)")
199 // [swift_MapObject_setVisible]
201 // [swift_CircleMapObject_getMapObjectType]
202 // Get map object type
203 let objectType = circleMapObject.mapObjectType
204 print("Circle map object type: \(objectType)")
205 // [swift_CircleMapObject_getMapObjectType]
207 // [swift_MapObject_setAlpha]
208 // Set alpha transparency
209 let alphaSuccess = circleMapObject.setAlpha(0.7)
210 print("Set circle alpha to 0.7: \(alphaSuccess)")
211 // [swift_MapObject_setAlpha]
213 // [swift_MapObject_setInteractive]
214 // Set interactive mode
215 let interactiveSuccess = circleMapObject.setInteractive(true)
216 print("Set circle interactive to true: \(interactiveSuccess)")
217 // [swift_MapObject_setInteractive]
219 // [swift_MapObject_setTitle]
221 let titleSuccess = circleMapObject.setTitle("Circle Object")
222 print("Set circle title to 'Circle Object': \(titleSuccess)")
223 // [swift_MapObject_setTitle]
225 // [swift_TitleStyle_record]
226 let titleStyle = NCTitleStyle()
227 titleStyle.fontSize = 14
228 titleStyle.color = "#3366CC"
229 titleStyle.outlineColor = "#FFFFFF"
230 titleStyle.anchor = .top
231 titleStyle.visible = true
232 // [swift_TitleStyle_record]
234 // [swift_MapObject_setTitleWithStyle]
235 // Set title with style
236 let titleStyleSuccess = circleMapObject.setTitleWithStyle("Styled Circle", style: titleStyle)
237 print("Set circle title with style: \(titleStyleSuccess)")
238 // [swift_MapObject_setTitleWithStyle]
240 // [swift_MapObject_setData]
242 let customData = ["key": "value", "number": "42"]
243 let dataSuccess = circleMapObject.setData(customData)
244 print("Set circle custom data: \(dataSuccess)")
245 // [swift_MapObject_setData]
247 // [swift_MapObject_getId]
249 let objectId = circleMapObject.id
250 print("Circle object ID: \(objectId)")
251 // [swift_MapObject_getId]
253 // [swift_MapObject_getType]
255 let objectTypeString = circleMapObject.type
256 print("Circle object type: \(objectTypeString)")
257 // [swift_MapObject_getType]
259 // [swift_MapObject_getData]
261 let retrievedData = circleMapObject.data
262 print("Circle custom data: \(retrievedData)")
263 // [swift_MapObject_getData]
266 // [swift_LocationWindow_removeCircleMapObject]
267 // Remove circle map object
268 if let circleMapObject = circleMapObject {
269 let removed = locationWindow.removeCircleMapObject(circleMapObject)
270 print("Removed circle map object: \(removed)")
271 self.circleMapObject = nil
273 // [swift_LocationWindow_removeCircleMapObject]
275 // Test multiple circle objects
276 var circles: [NCCircleMapObject] = []
278 if let circle = locationWindow.addCircleMapObject() {
279 circle.setPosition(NCGlobalPoint(latitude: 50.0 * Double(i), longitude: 100.0 * Double(i)), sublocationId: 7)
280 circle.setColor(UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.6))
281 circle.setRadius(5.0 + Double(i) * 2.0)
282 circles.append(circle)
283 print("Created circle \(i) at (\(50.0 * Double(i)), \(100.0 * Double(i))) with radius \(5.0 + Double(i) * 2.0)")
287 for i in circles.indices {
288 locationWindow.removeCircleMapObject(circles[i])
289 print("Removed circle \(i)")
294 * Demonstrate icon map objects
296 private func demonstrateIconMapObjects() {
297 print("--- Icon Map Objects ---")
299 guard let locationWindow = locationWindow else {
300 print("LocationWindow not available yet")
304 // [swift_IconMapObject_constructor]
305 // Create icon map object
306 let position = NCGlobalPoint(latitude: 30.0, longitude: 40.0)
307 iconMapObject = locationWindow.addIconMapObject()
308 print("Created icon map object at (\(position.latitude), \(position.longitude))")
309 // [swift_IconMapObject_constructor]
311 // [swift_LocationWindow_addIconMapObject]
312 // Add icon map object
313 iconMapObject = locationWindow.addIconMapObject()
314 print("Added icon map object")
315 // [swift_LocationWindow_addIconMapObject]
317 if let iconMapObject = iconMapObject {
318 // [swift_IconMapObject_setPosition]
320 let position = NCGlobalPoint(latitude: 30.0, longitude: 40.0)
321 let success = iconMapObject.setPosition(position, sublocationId: 7)
322 print("Set icon position to (\(position.latitude), \(position.longitude)): \(success)")
323 // [swift_IconMapObject_setPosition]
325 // [swift_IconMapObject_setPositionAnimated]
326 // Set icon position with animation
327 let animatedPosition = NCGlobalPoint(latitude: 35.0, longitude: 45.0)
328 let animatedSuccess = iconMapObject.setPositionAnimated(animatedPosition, duration: 1.5, animationType: .cubic)
329 print("Set icon position with animation to (\(animatedPosition.latitude), \(animatedPosition.longitude)): \(animatedSuccess)")
330 // [swift_IconMapObject_setPositionAnimated]
332 // [swift_IconMapObject_setBitmap]
333 if let iconImage = UIImage(contentsOfFile: "/path/to/icon.png") {
334 let bitmapSuccess = iconMapObject.setBitmap(iconImage)
335 print("Set icon bitmap (UIImage): \(bitmapSuccess)")
337 // [swift_IconMapObject_setBitmap]
339 // [swift_IconMapObject_setFlat]
340 // Set icon flat mode
341 let flatSuccess = iconMapObject.setFlat(true)
342 print("Set icon flat mode to true: \(flatSuccess)")
343 // [swift_IconMapObject_setFlat]
345 // [swift_IconMapObject_setSize]
347 let size = NCSize(width: 32.0, height: 32.0)
348 let sizeSuccess = iconMapObject.setSize(size)
349 print("Set icon size to (\(size.width), \(size.height)): \(sizeSuccess)")
350 // [swift_IconMapObject_setSize]
352 // [swift_IconMapObject_setAngle]
353 // Set icon rotation angle (radians)
354 let angleSuccess = iconMapObject.setAngle(Float.pi / 4)
355 print("Set icon rotation angle to π/4: \(angleSuccess)")
356 // [swift_IconMapObject_setAngle]
358 // [swift_IconMapObject_setAngleAnimated]
359 // Set icon rotation with animation (radians)
360 let angleAnimatedSuccess = iconMapObject.setAngleAnimated(Float.pi / 2, duration: 2.0, animationType: .sine)
361 print("Set icon rotation with animation to π/2: \(angleAnimatedSuccess)")
362 // [swift_IconMapObject_setAngleAnimated]
364 // [swift_IconMapObject_setCollisionEnabled]
365 // Enable collision detection
366 let collisionSuccess = iconMapObject.setCollisionEnabled(true)
367 print("Enabled collision detection for icon: \(collisionSuccess)")
368 // [swift_IconMapObject_setCollisionEnabled]
370 // [swift_IconMapObject_setBuffer]
371 // Set collision buffer
372 let bufferSuccess = iconMapObject.setBuffer(width: 10.0, height: 10.0)
373 print("Set collision buffer to 10x10 pixels: \(bufferSuccess)")
374 // [swift_IconMapObject_setBuffer]
376 // [swift_IconMapObject_setOffset]
377 // Set position offset
378 let offsetSuccess = iconMapObject.setOffset(x: 0.0, longitude: -16.0)
379 print("Set position offset to (0.0, -16.0) pixels: \(offsetSuccess)")
380 // [swift_IconMapObject_setOffset]
382 // [swift_IconMapObject_setPriority]
383 // Set rendering priority
384 let prioritySuccess = iconMapObject.setPriority(2)
385 print("Set rendering priority to 2: \(prioritySuccess)")
386 // [swift_IconMapObject_setPriority]
388 // [swift_IconMapObject_setVisible]
390 let visibleSuccess = iconMapObject.setVisible(true)
391 print("Set icon visibility to true: \(visibleSuccess)")
392 // [swift_IconMapObject_setVisible]
394 // [swift_IconMapObject_getMapObjectType]
395 // Get map object type
396 let objectType = iconMapObject.mapObjectType
397 print("Icon map object type: \(objectType)")
398 // [swift_IconMapObject_getMapObjectType]
400 // [swift_MapObject_setAlpha_1]
401 // Set alpha transparency
402 let alphaSuccess = iconMapObject.setAlpha(0.8)
403 print("Set icon alpha to 0.8: \(alphaSuccess)")
404 // [swift_MapObject_setAlpha_1]
406 // [swift_MapObject_setInteractive_1]
407 // Set interactive mode
408 let interactiveSuccess = iconMapObject.setInteractive(true)
409 print("Set icon interactive to true: \(interactiveSuccess)")
410 // [swift_MapObject_setInteractive_1]
412 // [swift_MapObject_setTitle_1]
414 let titleSuccess = iconMapObject.setTitle("Icon Object")
415 print("Set icon title to 'Icon Object': \(titleSuccess)")
416 // [swift_MapObject_setTitle_1]
418 // [swift_MapObject_setData_1]
420 let customData = ["key": "value", "number": "42"]
421 let dataSuccess = iconMapObject.setData(customData)
422 print("Set icon custom data: \(dataSuccess)")
423 // [swift_MapObject_setData_1]
425 // [swift_MapObject_getId_1]
427 let objectId = iconMapObject.id
428 print("Icon object ID: \(objectId)")
429 // [swift_MapObject_getId_1]
431 // [swift_MapObject_getType_1]
433 let objectTypeString = iconMapObject.type
434 print("Icon object type: \(objectTypeString)")
435 // [swift_MapObject_getType_1]
437 // [swift_MapObject_getData_1]
439 let retrievedData = iconMapObject.data
440 print("Icon custom data: \(retrievedData)")
441 // [swift_MapObject_getData_1]
444 // [swift_LocationWindow_removeIconMapObject]
445 // Remove icon map object
446 if let iconMapObject = iconMapObject {
447 let removed = locationWindow.removeIconMapObject(iconMapObject)
448 print("Removed icon map object: \(removed)")
449 self.iconMapObject = nil
451 // [swift_LocationWindow_removeIconMapObject]
453 // Test multiple icon objects
454 var icons: [NCIconMapObject] = []
456 if let icon = locationWindow.addIconMapObject() {
457 icon.setPosition(NCGlobalPoint(latitude: 60.0 * Double(i), longitude: 120.0 * Double(i)), sublocationId: 7)
458 if let img = UIImage(contentsOfFile: "/path/to/icon.png") {
459 _ = icon.setBitmap(img)
461 icon.setSize(NCSize(width: 24.0, height: 24.0))
463 print("Created icon \(i) at (\(60.0 * Double(i)), \(120.0 * Double(i)))")
467 for i in icons.indices {
468 locationWindow.removeIconMapObject(icons[i])
469 print("Removed icon \(i)")
474 * 3D model map objects (OBJ + texture via ModelProvider / NCModelProviderFactory).
476 private func demonstrateModelMapObjects() {
477 print("--- Model Map Objects ---")
479 guard let locationWindow = locationWindow else {
480 print("LocationWindow not available yet")
484 // [swift_LocationWindow_addModelMapObject]
485 modelMapObject = locationWindow.addModelMapObject()
486 print("Added model map object: \(modelMapObject != nil)")
487 // [swift_LocationWindow_addModelMapObject]
489 guard let m = modelMapObject else { return }
491 // [swift_ModelMapObject_setPosition]
492 let posOk = m.setPosition(NCGlobalPoint(latitude: 12.0, longitude: 34.0), sublocationId: 7)
493 print("Model setPosition: \(posOk)")
494 // [swift_ModelMapObject_setPosition]
496 // [swift_ModelMapObject_setPositionAnimated]
497 let posAnimOk = m.setPositionAnimated(
498 NCGlobalPoint(latitude: 15.0, longitude: 40.0),
502 print("Model setPositionAnimated: \(posAnimOk)")
503 // [swift_ModelMapObject_setPositionAnimated]
505 // [swift_ModelMapObject_setModel]
506 if let texture = UIImage(contentsOfFile: "/path/to/model_texture.png") {
507 let provider = NCModelProviderFactory.fromFile("/path/to/model.obj", texture: texture)
508 let modelOk = m.setModel(provider)
509 print("Model setModel: \(modelOk)")
511 // [swift_ModelMapObject_setModel]
513 // [swift_ModelMapObject_setSize]
514 let sizeOk = m.setSize(width: 64.0, height: 64.0)
515 print("Model setSize: \(sizeOk)")
516 // [swift_ModelMapObject_setSize]
518 // [swift_ModelMapObject_setCollisionEnabled]
519 let collOk = m.setCollisionEnabled(true)
520 print("Model setCollisionEnabled: \(collOk)")
521 // [swift_ModelMapObject_setCollisionEnabled]
523 // [swift_ModelMapObject_setAngle]
524 let angleOk = m.setAngle(Float.pi / 4)
525 print("Model setAngle: \(angleOk)")
526 // [swift_ModelMapObject_setAngle]
528 // [swift_ModelMapObject_setAngleAnimated]
529 let angleAnimOk = m.setAngleAnimated(Float.pi / 2, duration: 0.5, animationType: .quint)
530 print("Model setAngleAnimated: \(angleAnimOk)")
531 // [swift_ModelMapObject_setAngleAnimated]
533 // [swift_ModelMapObject_setBuffer]
534 let bufOk = m.setBuffer(width: 4.0, height: 4.0)
535 print("Model setBuffer: \(bufOk)")
536 // [swift_ModelMapObject_setBuffer]
538 // [swift_ModelMapObject_setPriority]
539 let priOk = m.setPriority(10.0)
540 print("Model setPrioritlongitude: \(priOk)")
541 // [swift_ModelMapObject_setPriority]
543 // [swift_LocationWindow_removeModelMapObject]
544 let removed = locationWindow.removeModelMapObject(m)
545 print("Removed model map object: \(removed)")
547 // [swift_LocationWindow_removeModelMapObject]
551 * Demonstrate polygon map objects
553 private func demonstratePolygonMapObjects() {
554 print("--- Polygon Map Objects ---")
556 guard let locationWindow = locationWindow else {
557 print("LocationWindow not available yet")
561 // [swift_LocationWindow_addPolygonMapObject]
562 // Add polygon map object
563 polygonMapObject = locationWindow.addPolygonMapObject()
564 print("Added polygon map object")
565 // [swift_LocationWindow_addPolygonMapObject]
567 if let polygonMapObject = polygonMapObject {
568 // [swift_PolygonMapObject_setPolygon]
569 // Set polygon geometry
571 NCGlobalPoint(latitude: 50.0, longitude: 60.0),
572 NCGlobalPoint(latitude: 55.0, longitude: 65.0),
573 NCGlobalPoint(latitude: 60.0, longitude: 60.0),
574 NCGlobalPoint(latitude: 55.0, longitude: 55.0),
576 let polygon = NCLocationPolygon(points: points, sublocationId: 0, innerRings: [])
577 let success = polygonMapObject.setPolygon(polygon)
578 print("Set polygon with \(points.count) points: \(success)")
579 // [swift_PolygonMapObject_setPolygon]
581 // [swift_PolygonMapObject_setColor]
583 let colorSuccess = polygonMapObject.setColor(UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.7))
584 print("Set polygon color to green with 70% opacity: \(colorSuccess)")
585 // [swift_PolygonMapObject_setColor]
587 // [swift_PolygonMapObject_setOrder]
588 // Set polygon rendering order
589 let orderSuccess = polygonMapObject.setOrder(2)
590 print("Set polygon rendering order to 2: \(orderSuccess)")
591 // [swift_PolygonMapObject_setOrder]
593 // [swift_PolygonMapObject_setOutlineColor]
594 // Set polygon outline color
595 let outlineColorSuccess = polygonMapObject.setOutlineColor(UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0))
596 print("Set polygon outline color to blue: \(outlineColorSuccess)")
597 // [swift_PolygonMapObject_setOutlineColor]
599 // [swift_PolygonMapObject_setOutlineWidth]
600 // Set polygon outline width
601 let outlineWidthSuccess = polygonMapObject.setOutlineWidth(2.0)
602 print("Set polygon outline width to 2.0 pixels: \(outlineWidthSuccess)")
603 // [swift_PolygonMapObject_setOutlineWidth]
605 // [swift_PolygonMapObject_setOutlineAlpha]
606 // Set polygon outline alpha
607 let outlineAlphaSuccess = polygonMapObject.setOutlineAlpha(0.8)
608 print("Set polygon outline alpha to 0.8: \(outlineAlphaSuccess)")
609 // [swift_PolygonMapObject_setOutlineAlpha]
611 // [swift_PolygonMapObject_setOutlineOrder]
612 // Set polygon outline order
613 let outlineOrderSuccess = polygonMapObject.setOutlineOrder(1)
614 print("Set polygon outline order to 1: \(outlineOrderSuccess)")
615 // [swift_PolygonMapObject_setOutlineOrder]
617 // [swift_PolygonMapObject_setVisible]
619 let visibleSuccess = polygonMapObject.setVisible(true)
620 print("Set polygon visibility to true: \(visibleSuccess)")
621 // [swift_PolygonMapObject_setVisible]
623 // [swift_PolygonMapObject_getMapObjectType]
624 // Get map object type
625 let objectType = polygonMapObject.mapObjectType
626 print("Polygon map object type: \(objectType)")
627 // [swift_PolygonMapObject_getMapObjectType]
629 // [swift_MapObject_setAlpha_2]
630 // Set alpha transparency
631 let alphaSuccess = polygonMapObject.setAlpha(0.6)
632 print("Set polygon alpha to 0.6: \(alphaSuccess)")
633 // [swift_MapObject_setAlpha_2]
635 // [swift_MapObject_setInteractive_2]
636 // Set interactive mode
637 let interactiveSuccess = polygonMapObject.setInteractive(true)
638 print("Set polygon interactive to true: \(interactiveSuccess)")
639 // [swift_MapObject_setInteractive_2]
641 // [swift_MapObject_setTitle_2]
643 let titleSuccess = polygonMapObject.setTitle("Polygon Object")
644 print("Set polygon title to 'Polygon Object': \(titleSuccess)")
645 // [swift_MapObject_setTitle_2]
647 // [swift_MapObject_setData_2]
649 let customData = ["key": "value", "number": "42"]
650 let dataSuccess = polygonMapObject.setData(customData)
651 print("Set polygon custom data: \(dataSuccess)")
652 // [swift_MapObject_setData_2]
654 // [swift_MapObject_getId_2]
656 let objectId = polygonMapObject.id
657 print("Polygon object ID: \(objectId)")
658 // [swift_MapObject_getId_2]
660 // [swift_MapObject_getType_2]
662 let objectTypeString = polygonMapObject.type
663 print("Polygon object type: \(objectTypeString)")
664 // [swift_MapObject_getType_2]
666 // [swift_MapObject_getData_2]
668 let retrievedData = polygonMapObject.data
669 print("Polygon custom data: \(retrievedData)")
670 // [swift_MapObject_getData_2]
673 // [swift_LocationWindow_removePolygonMapObject]
674 // Remove polygon map object
675 if let polygonMapObject = polygonMapObject {
676 let removed = locationWindow.removePolygonMapObject(polygonMapObject)
677 print("Removed polygon map object: \(removed)")
678 self.polygonMapObject = nil
680 // [swift_LocationWindow_removePolygonMapObject]
682 // Test multiple polygon objects
683 var polygons: [NCPolygonMapObject] = []
685 if let polygon = locationWindow.addPolygonMapObject() {
687 NCGlobalPoint(latitude: 300.0 + Double(i) * 50, longitude: 400.0 + Double(i) * 50),
688 NCGlobalPoint(latitude: 350.0 + Double(i) * 50, longitude: 450.0 + Double(i) * 50),
689 NCGlobalPoint(latitude: 400.0 + Double(i) * 50, longitude: 400.0 + Double(i) * 50),
690 NCGlobalPoint(latitude: 350.0 + Double(i) * 50, longitude: 350.0 + Double(i) * 50),
692 let polygonGeometry = NCLocationPolygon(points: points, sublocationId: 0, innerRings: [])
693 polygon.setPolygon(polygonGeometry)
694 polygon.setColor(UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.5))
695 polygons.append(polygon)
696 print("Created polygon \(i) with \(points.count) points")
700 for i in polygons.indices {
701 locationWindow.removePolygonMapObject(polygons[i])
702 print("Removed polygon \(i)")
707 * Demonstrate polyline map objects
709 private func demonstratePolylineMapObjects() {
710 print("--- Polyline Map Objects ---")
712 guard let locationWindow = locationWindow else {
713 print("LocationWindow not available yet")
717 // [swift_PolylineMapObject_constructor]
718 // Create polyline map object
720 NCGlobalPoint(latitude: 100.0, longitude: 110.0),
721 NCGlobalPoint(latitude: 105.0, longitude: 115.0),
722 NCGlobalPoint(latitude: 110.0, longitude: 120.0),
723 NCGlobalPoint(latitude: 115.0, longitude: 125.0),
725 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
726 polylineMapObject = locationWindow.addPolylineMapObject()
727 print("Created polyline map object with \(points.count) points")
728 // [swift_PolylineMapObject_constructor]
730 // [swift_PolylineMapObject_getPolyline]
732 let polylineShape = polylineMapObject!.getPolyLine()
733 print("Polyline has \(polylineShape.polyline.points.count) points")
734 // [swift_PolylineMapObject_getPolyline]
736 // [swift_LocationWindow_addPolylineMapObject]
737 // Add polyline map object
738 polylineMapObject = locationWindow.addPolylineMapObject()
739 print("Added polyline map object")
740 // [swift_LocationWindow_addPolylineMapObject]
742 if let polylineMapObject = polylineMapObject {
743 // [swift_PolylineMapObject_setPolyLine]
744 // Set polyline geometry
746 NCGlobalPoint(latitude: 100.0, longitude: 110.0),
747 NCGlobalPoint(latitude: 105.0, longitude: 115.0),
748 NCGlobalPoint(latitude: 110.0, longitude: 120.0),
749 NCGlobalPoint(latitude: 115.0, longitude: 125.0),
751 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
752 let success = polylineMapObject.setPolyLine(polyline)
753 print("Set polyline with \(points.count) points: \(success)")
754 // [swift_PolylineMapObject_setPolyLine]
756 // [swift_PolylineMapObject_setDrawnFraction]
757 _ = polylineMapObject.setDrawnFraction(0)
758 // [swift_PolylineMapObject_setDrawnFraction]
760 // [swift_PolylineMapObject_setDrawnFractionAnimated]
761 let grew = polylineMapObject.setDrawnFractionAnimated(1, duration: 1.0, animationType: .linear)
762 print("Polyline grow started: \(grew)")
763 // [swift_PolylineMapObject_setDrawnFractionAnimated]
765 // [swift_PolylineMapObject_drawnFraction]
766 print("Drawn fraction: \(polylineMapObject.drawnFraction())")
767 // [swift_PolylineMapObject_drawnFraction]
769 // [swift_PolylineMapObject_setWidth]
770 // Set polyline width
771 let widthSuccess = polylineMapObject.setWidth(3.0)
772 print("Set polyline width to 3.0 pixels: \(widthSuccess)")
773 // [swift_PolylineMapObject_setWidth]
775 // [swift_PolylineMapObject_setColor]
776 // Set polyline color
777 let colorSuccess = polylineMapObject.setColor(UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.8))
778 print("Set polyline color to green with 80% opacity: \(colorSuccess)")
779 // [swift_PolylineMapObject_setColor]
781 // [swift_PolylineMapObject_setDashLength]
782 // Set dash segment length
783 let dashSuccess = polylineMapObject.setDashLength(3.0)
784 print("Set polyline dash length: \(dashSuccess)")
785 // [swift_PolylineMapObject_setDashLength]
787 // [swift_PolylineMapObject_dashLength]
788 // Get dash segment length
789 let dashLength = polylineMapObject.dashLength()
790 print("Polyline dash length: \(dashLength)")
791 // [swift_PolylineMapObject_dashLength]
793 // [swift_PolylineMapObject_setGapLength]
794 // Set gap length between dashes
795 let gapSuccess = polylineMapObject.setGapLength(1.0)
796 print("Set polyline gap length: \(gapSuccess)")
797 // [swift_PolylineMapObject_setGapLength]
799 // [swift_PolylineMapObject_gapLength]
800 // Get gap length between dashes
801 let gapLength = polylineMapObject.gapLength()
802 print("Polyline gap length: \(gapLength)")
803 // [swift_PolylineMapObject_gapLength]
805 // [swift_PolylineMapObject_setOrder]
806 // Set polyline rendering order
807 let orderSuccess = polylineMapObject.setOrder(1)
808 print("Set polyline rendering order to 1: \(orderSuccess)")
809 // [swift_PolylineMapObject_setOrder]
811 // [swift_PolylineMapObject_setCapType]
812 // Set polyline cap type
813 let capTypeSuccess = polylineMapObject.setCapType(.round)
814 print("Set polyline cap type to ROUND: \(capTypeSuccess)")
815 // [swift_PolylineMapObject_setCapType]
817 // [swift_PolylineMapObject_setJoinType]
818 // Set polyline join type
819 let joinTypeSuccess = polylineMapObject.setJoinType(.round)
820 print("Set polyline join type to ROUND: \(joinTypeSuccess)")
821 // [swift_PolylineMapObject_setJoinType]
823 // [swift_PolylineMapObject_setMiterLimit]
824 // Set polyline miter limit
825 let miterLimitSuccess = polylineMapObject.setMiterLimit(2.0)
826 print("Set polyline miter limit to 2.0: \(miterLimitSuccess)")
827 // [swift_PolylineMapObject_setMiterLimit]
829 // [swift_PolylineMapObject_setOutlineWidth]
830 // Set polyline outline width
831 let outlineWidthSuccess = polylineMapObject.setOutlineWidth(1.0)
832 print("Set polyline outline width to 1.0 pixels: \(outlineWidthSuccess)")
833 // [swift_PolylineMapObject_setOutlineWidth]
835 // [swift_PolylineMapObject_setOutlineColor]
836 // Set polyline outline color
837 let outlineColorSuccess = polylineMapObject.setOutlineColor(UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0))
838 print("Set polyline outline color to black: \(outlineColorSuccess)")
839 // [swift_PolylineMapObject_setOutlineColor]
841 // [swift_PolylineMapObject_setOutlineAlpha]
842 // Set polyline outline alpha
843 let outlineAlphaSuccess = polylineMapObject.setOutlineAlpha(0.5)
844 print("Set polyline outline alpha to 0.5: \(outlineAlphaSuccess)")
845 // [swift_PolylineMapObject_setOutlineAlpha]
847 // [swift_PolylineMapObject_setOutlineOrder]
848 // Set polyline outline rendering order
849 let outlineOrderSuccess = polylineMapObject.setOutlineOrder(0)
850 print("Set polyline outline rendering order to 0: \(outlineOrderSuccess)")
851 // [swift_PolylineMapObject_setOutlineOrder]
853 // [swift_PolylineMapObject_setOutlineCapType]
854 // Set polyline outline cap type
855 let outlineCapTypeSuccess = polylineMapObject.setOutlineCapType(.square)
856 print("Set polyline outline cap type to SQUARE: \(outlineCapTypeSuccess)")
857 // [swift_PolylineMapObject_setOutlineCapType]
859 // [swift_PolylineMapObject_setOutlineJoinType]
860 // Set polyline outline join type
861 let outlineJoinTypeSuccess = polylineMapObject.setOutlineJoinType(.miter)
862 print("Set polyline outline join type to MITER: \(outlineJoinTypeSuccess)")
863 // [swift_PolylineMapObject_setOutlineJoinType]
865 // [swift_PolylineMapObject_setOutlineMiterLimit]
866 // Set polyline outline miter limit
867 let outlineMiterLimitSuccess = polylineMapObject.setOutlineMiterLimit(3.0)
868 print("Set polyline outline miter limit to 3.0: \(outlineMiterLimitSuccess)")
869 // [swift_PolylineMapObject_setOutlineMiterLimit]
871 // [swift_PolylineMapObject_setVisible]
873 let visibleSuccess = polylineMapObject.setVisible(true)
874 print("Set polyline visibility to true: \(visibleSuccess)")
875 // [swift_PolylineMapObject_setVisible]
877 // [swift_PolylineMapObject_getMapObjectType]
878 // Get map object type
879 let objectType = polylineMapObject.mapObjectType
880 print("Polyline map object type: \(objectType)")
881 // [swift_PolylineMapObject_getMapObjectType]
883 // [swift_MapObject_setAlpha_3]
884 // Set alpha transparency
885 let alphaSuccess = polylineMapObject.setAlpha(0.7)
886 print("Set polyline alpha to 0.7: \(alphaSuccess)")
887 // [swift_MapObject_setAlpha_3]
889 // [swift_MapObject_setInteractive_3]
890 // Set interactive mode
891 let interactiveSuccess = polylineMapObject.setInteractive(true)
892 print("Set polyline interactive to true: \(interactiveSuccess)")
893 // [swift_MapObject_setInteractive_3]
895 // [swift_MapObject_setTitle_3]
897 let titleSuccess = polylineMapObject.setTitle("Polyline Object")
898 print("Set polyline title to 'Polyline Object': \(titleSuccess)")
899 // [swift_MapObject_setTitle_3]
901 // [swift_MapObject_setData_3]
903 let customData = ["key": "value", "number": "42"]
904 let dataSuccess = polylineMapObject.setData(customData)
905 print("Set polyline custom data: \(dataSuccess)")
906 // [swift_MapObject_setData_3]
908 // [swift_MapObject_getId_3]
910 let objectId = polylineMapObject.id
911 print("Polyline object ID: \(objectId)")
912 // [swift_MapObject_getId_3]
914 // [swift_MapObject_getType_3]
916 let objectTypeString = polylineMapObject.type
917 print("Polyline object type: \(objectTypeString)")
918 // [swift_MapObject_getType_3]
920 // [swift_MapObject_getData_3]
922 let retrievedData = polylineMapObject.data
923 print("Polyline custom data: \(retrievedData)")
924 // [swift_MapObject_getData_3]
927 // [swift_LocationWindow_removePolylineMapObject]
928 // Remove polyline map object
929 if let polylineMapObject = polylineMapObject {
930 let removed = locationWindow.removePolylineMapObject(polylineMapObject)
931 print("Removed polyline map object: \(removed)")
932 self.polylineMapObject = nil
934 // [swift_LocationWindow_removePolylineMapObject]
936 // Test multiple polyline objects
937 var polylines: [NCPolylineMapObject] = []
939 if let polyline = locationWindow.addPolylineMapObject() {
941 NCGlobalPoint(latitude: 120.0 + Double(i) * 30, longitude: 130.0 + Double(i) * 30),
942 NCGlobalPoint(latitude: 125.0 + Double(i) * 30, longitude: 135.0 + Double(i) * 30),
943 NCGlobalPoint(latitude: 130.0 + Double(i) * 30, longitude: 140.0 + Double(i) * 30),
945 let polylineGeometry = NCLocationPolyline(points: points, sublocationId: 0)
946 polyline.setPolyLine(polylineGeometry)
947 polyline.setColor(UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6))
948 polyline.setWidth(2.0)
949 polylines.append(polyline)
950 print("Created polyline \(i) with \(points.count) points")
954 for i in polylines.indices {
955 locationWindow.removePolylineMapObject(polylines[i])
956 print("Removed polyline \(i)")
961 * Demonstrate dotted polyline map objects
963 private func demonstrateDottedPolylineMapObjects() {
964 print("--- Dotted Polyline Map Objects ---")
966 guard let locationWindow = locationWindow else {
967 print("LocationWindow not available yet")
971 // [swift_DottedPolylineMapObject_constructor]
972 // Create dotted polyline map object
974 NCGlobalPoint(latitude: 160.0, longitude: 170.0),
975 NCGlobalPoint(latitude: 165.0, longitude: 175.0),
976 NCGlobalPoint(latitude: 170.0, longitude: 180.0),
977 NCGlobalPoint(latitude: 175.0, longitude: 185.0),
979 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
980 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
981 print("Created dotted polyline map object with \(points.count) points")
982 // [swift_DottedPolylineMapObject_constructor]
984 // [swift_DottedPolylineMapObject_getPolyline]
985 // Access dotted polyline
986 let dottedPolylineShape = dottedPolylineMapObject!.getPolyLine()
987 print("Dotted polyline has \(dottedPolylineShape.polyline.points.count) points")
988 // [swift_DottedPolylineMapObject_getPolyline]
990 // [swift_LocationWindow_addDottedPolylineMapObject]
991 // Add dotted polyline map object
992 dottedPolylineMapObject = locationWindow.addDottedPolylineMapObject()
993 print("Added dotted polyline map object")
994 // [swift_LocationWindow_addDottedPolylineMapObject]
996 if let dottedPolylineMapObject = dottedPolylineMapObject {
997 // [swift_DottedPolylineMapObject_setPolyline]
998 // Set dotted polyline geometry
1000 NCGlobalPoint(latitude: 160.0, longitude: 170.0),
1001 NCGlobalPoint(latitude: 165.0, longitude: 175.0),
1002 NCGlobalPoint(latitude: 170.0, longitude: 180.0),
1003 NCGlobalPoint(latitude: 175.0, longitude: 185.0),
1005 let polyline = NCLocationPolyline(points: points, sublocationId: 0)
1006 let success = dottedPolylineMapObject.setPolyline(polyline)
1007 print("Set dotted polyline with \(points.count) points: \(success)")
1008 // [swift_DottedPolylineMapObject_setPolyline]
1010 // [swift_DottedPolylineMapObject_setColor]
1011 // Set dotted polyline color
1012 let colorSuccess = dottedPolylineMapObject.setColor(UIColor(red: 0.5, green: 0.0, blue: 1.0, alpha: 0.8))
1013 print("Set dotted polyline color to purple with 80% opacity: \(colorSuccess)")
1014 // [swift_DottedPolylineMapObject_setColor]
1016 // [swift_DottedPolylineMapObject_setWidth]
1017 // Set dotted polyline width
1018 let widthSuccess = dottedPolylineMapObject.setWidth(3.0)
1019 print("Set dotted polyline width to 3.0 pixels: \(widthSuccess)")
1020 // [swift_DottedPolylineMapObject_setWidth]
1022 // [swift_DottedPolylineMapObject_setOrder]
1023 // Set dotted polyline rendering order
1024 let orderSuccess = dottedPolylineMapObject.setOrder(2)
1025 print("Set dotted polyline rendering order to 2: \(orderSuccess)")
1026 // [swift_DottedPolylineMapObject_setOrder]
1028 // [swift_DottedPolylineMapObject_setCollisionEnabled]
1029 // Enable collision detection
1030 let dottedCollisionSuccess = dottedPolylineMapObject.setCollisionEnabled(true)
1031 print("Enabled collision detection for dotted polyline: \(dottedCollisionSuccess)")
1032 // [swift_DottedPolylineMapObject_setCollisionEnabled]
1034 // [swift_DottedPolylineMapObject_setPlacement]
1035 // Set placement type
1036 let dottedPlacementSuccess = dottedPolylineMapObject.setPlacement(.center)
1037 print("Set dotted polyline placement to CENTER: \(dottedPlacementSuccess)")
1038 // [swift_DottedPolylineMapObject_setPlacement]
1040 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
1041 // Set placement min ratio
1042 let dottedMinRatioSuccess = dottedPolylineMapObject.setPlacementMinRatio(0.5)
1043 print("Set dotted polyline placement min ratio to 0.5: \(dottedMinRatioSuccess)")
1044 // [swift_DottedPolylineMapObject_setPlacementMinRatio]
1046 // [swift_DottedPolylineMapObject_setPlacementSpacing]
1047 // Set placement spacing
1048 let dottedSpacingSuccess = dottedPolylineMapObject.setPlacementSpacing(10.0)
1049 print("Set dotted polyline placement spacing to 10.0: \(dottedSpacingSuccess)")
1050 // [swift_DottedPolylineMapObject_setPlacementSpacing]
1052 // [swift_DottedPolylineMapObject_setPriority]
1053 // Set rendering priority
1054 let dottedPrioritySuccess = dottedPolylineMapObject.setPriority(1)
1055 print("Set dotted polyline rendering priority to 1: \(dottedPrioritySuccess)")
1056 // [swift_DottedPolylineMapObject_setPriority]
1058 // [swift_DottedPolylineMapObject_setRepeatDistance]
1059 // Set repeat distance
1060 let dottedRepeatDistanceSuccess = dottedPolylineMapObject.setRepeatDistance(20.0)
1061 print("Set dotted polyline repeat distance to 20.0: \(dottedRepeatDistanceSuccess)")
1062 // [swift_DottedPolylineMapObject_setRepeatDistance]
1064 // [swift_DottedPolylineMapObject_setRepeatGroup]
1066 let dottedRepeatGroupSuccess = dottedPolylineMapObject.setRepeatGroup(1)
1067 print("Set dotted polyline repeat group to 1: \(dottedRepeatGroupSuccess)")
1068 // [swift_DottedPolylineMapObject_setRepeatGroup]
1070 // [swift_DottedPolylineMapObject_setSize]
1072 let dottedSize = NCSize(width: 16.0, height: 16.0)
1073 let dottedSizeSuccess = dottedPolylineMapObject.setSize(dottedSize)
1074 print("Set dotted polyline size to (\(dottedSize.width), \(dottedSize.height)): \(dottedSizeSuccess)")
1075 // [swift_DottedPolylineMapObject_setSize]
1077 // [swift_DottedPolylineMapObject_setVisible]
1079 let visibleSuccess = dottedPolylineMapObject.setVisible(true)
1080 print("Set dotted polyline visibility to true: \(visibleSuccess)")
1081 // [swift_DottedPolylineMapObject_setVisible]
1083 // [swift_DottedPolylineMapObject_getMapObjectType]
1084 // Get map object type
1085 let objectType = dottedPolylineMapObject.mapObjectType
1086 print("Dotted polyline map object type: \(objectType)")
1087 // [swift_DottedPolylineMapObject_getMapObjectType]
1089 // [swift_MapObject_setAlpha_4]
1090 // Set alpha transparency
1091 let alphaSuccess = dottedPolylineMapObject.setAlpha(0.8)
1092 print("Set dotted polyline alpha to 0.8: \(alphaSuccess)")
1093 // [swift_MapObject_setAlpha_4]
1095 // [swift_MapObject_setInteractive_4]
1096 // Set interactive mode
1097 let interactiveSuccess = dottedPolylineMapObject.setInteractive(true)
1098 print("Set dotted polyline interactive to true: \(interactiveSuccess)")
1099 // [swift_MapObject_setInteractive_4]
1101 // [swift_MapObject_setTitle_4]
1103 let titleSuccess = dottedPolylineMapObject.setTitle("Dotted Polyline Object")
1104 print("Set dotted polyline title to 'Dotted Polyline Object': \(titleSuccess)")
1105 // [swift_MapObject_setTitle_4]
1107 // [swift_MapObject_setData_4]
1109 let customData = ["key": "value", "number": "42"]
1110 let dataSuccess = dottedPolylineMapObject.setData(customData)
1111 print("Set dotted polyline custom data: \(dataSuccess)")
1112 // [swift_MapObject_setData_4]
1114 // [swift_MapObject_getId_4]
1116 let objectId = dottedPolylineMapObject.id
1117 print("Dotted polyline object ID: \(objectId)")
1118 // [swift_MapObject_getId_4]
1120 // [swift_MapObject_getType_4]
1122 let objectTypeString = dottedPolylineMapObject.type
1123 print("Dotted polyline object type: \(objectTypeString)")
1124 // [swift_MapObject_getType_4]
1126 // [swift_MapObject_getData_4]
1128 let retrievedData = dottedPolylineMapObject.data
1129 print("Dotted polyline custom data: \(retrievedData)")
1130 // [swift_MapObject_getData_4]
1133 // [swift_LocationWindow_removeDottedPolylineMapObject]
1134 // Remove dotted polyline map object
1135 if let dottedPolylineMapObject = dottedPolylineMapObject {
1136 let removed = locationWindow.removeDottedPolylineMapObject(dottedPolylineMapObject)
1137 print("Removed dotted polyline map object: \(removed)")
1138 self.dottedPolylineMapObject = nil
1140 // [swift_LocationWindow_removeDottedPolylineMapObject]
1142 // Test multiple dotted polyline objects
1143 var dottedPolylines: [NCDottedPolylineMapObject] = []
1145 if let dottedPolyline = locationWindow.addDottedPolylineMapObject() {
1147 NCGlobalPoint(latitude: 180.0 + Double(i) * 30, longitude: 190.0 + Double(i) * 30),
1148 NCGlobalPoint(latitude: 185.0 + Double(i) * 30, longitude: 195.0 + Double(i) * 30),
1149 NCGlobalPoint(latitude: 190.0 + Double(i) * 30, longitude: 200.0 + Double(i) * 30),
1151 let polylineGeometry = NCLocationPolyline(points: points, sublocationId: 0)
1152 dottedPolyline.setPolyline(polylineGeometry)
1153 dottedPolylines.append(dottedPolyline)
1154 print("Created dotted polyline \(i) with \(points.count) points")
1158 for i in dottedPolylines.indices {
1159 locationWindow.removeDottedPolylineMapObject(dottedPolylines[i])
1160 print("Removed dotted polyline \(i)")
1165 * Demonstrate icon clustering via ClusterMapObjectController.
1167 private func demonstrateClusterMapObjects() {
1168 print("--- Cluster map objects ---")
1170 guard let locationWindow = locationWindow else {
1171 print("LocationWindow not available")
1175 // [swift_LocationWindow_addClusterMapObjectController]
1176 clusterMapObjectController = locationWindow.addClusterMapObjectController()
1177 print("Added cluster map object controller")
1178 // [swift_LocationWindow_addClusterMapObjectController]
1180 guard let controller = clusterMapObjectController else { return }
1182 let clusterIcon1 = locationWindow.addIconMapObject()
1183 let clusterIcon2 = locationWindow.addIconMapObject()
1184 clusterIcon1?.setPosition(NCGlobalPoint(latitude: 100.0, longitude: 100.0), sublocationId: 7)
1185 clusterIcon2?.setPosition(NCGlobalPoint(latitude: 105.0, longitude: 102.0), sublocationId: 7)
1187 // [swift_ClusterMapObjectController_addIconMapObject]
1188 let added1 = controller.add(clusterIcon1)
1189 let added2 = controller.add(clusterIcon2)
1190 print("Registered icons for clustering: \(added1), \(added2)")
1191 // [swift_ClusterMapObjectController_addIconMapObject]
1193 // [swift_ClusterMapObjectController_setEnabled]
1194 controller.setEnabled(true)
1195 print("Clustering enabled")
1196 // [swift_ClusterMapObjectController_setEnabled]
1198 // [swift_ClusterMapObjectController_isEnabled]
1199 let clusteringEnabled = controller.isEnabled()
1200 print("Clustering is enabled: \(clusteringEnabled)")
1201 // [swift_ClusterMapObjectController_isEnabled]
1203 // [swift_ClusterMapObjectController_setRadius]
1204 controller.setRadius(40.0)
1205 print("Set cluster radius to 40 px")
1206 // [swift_ClusterMapObjectController_setRadius]
1208 // [swift_ClusterMapObjectController_getRadius]
1209 let clusterRadius = controller.getRadius()
1210 print("Cluster radius: \(clusterRadius)")
1211 // [swift_ClusterMapObjectController_getRadius]
1213 // [swift_ClusterMapObjectController_setInteractive]
1214 let interactiveSuccess = controller.setInteractive(true)
1215 print("Set cluster markers interactive: \(interactiveSuccess)")
1216 // [swift_ClusterMapObjectController_setInteractive]
1218 // [swift_ClusterMapObjectController_setClusterSize]
1219 let sizeSuccess = controller.setClusterSize(32.0, height: 32.0)
1220 print("Set default cluster icon size: \(sizeSuccess)")
1221 // [swift_ClusterMapObjectController_setClusterSize]
1223 let listener = DemoClusterMapObjectControllerListener()
1224 clusterMapObjectControllerListener = listener
1226 // [swift_ClusterMapObjectController_addListener]
1227 controller.add(listener)
1228 print("Added cluster map object controller listener")
1229 // [swift_ClusterMapObjectController_addListener]
1231 // [swift_ClusterMapObjectController_getClusters]
1232 let clusters = controller.getClusters()
1233 print("Visible clusters: \(clusters.count)")
1234 // [swift_ClusterMapObjectController_getClusters]
1236 if let cluster = clusters.first {
1237 // [swift_ClusterMapObject_setBitmap]
1238 if let clusterImage = UIImage(contentsOfFile: "/path/to/cluster.png") {
1239 let bitmapSuccess = cluster.setBitmap(clusterImage)
1240 print("Set cluster bitmap (UIImage): \(bitmapSuccess)")
1242 // [swift_ClusterMapObject_setBitmap]
1245 // [swift_ClusterMapObjectController_removeListener]
1246 controller.remove(listener)
1247 print("Removed cluster map object controller listener")
1248 // [swift_ClusterMapObjectController_removeListener]
1250 if let clusterIcon1 = clusterIcon1 {
1251 // [swift_ClusterMapObjectController_removeIconMapObject]
1252 let removed = controller.remove(clusterIcon1)
1253 print("Removed icon from cluster controller: \(removed)")
1254 // [swift_ClusterMapObjectController_removeIconMapObject]
1255 locationWindow.removeIconMapObject(clusterIcon1)
1257 if let clusterIcon2 = clusterIcon2 {
1258 locationWindow.removeIconMapObject(clusterIcon2)
1261 // [swift_ClusterMapObjectController_clear]
1263 print("Cleared cluster controller")
1264 // [swift_ClusterMapObjectController_clear]
1266 // [swift_LocationWindow_removeClusterMapObjectController]
1267 let controllerRemoved = locationWindow.removeClusterMapObjectController(controller)
1268 print("Removed cluster map object controller: \(controllerRemoved)")
1269 // [swift_LocationWindow_removeClusterMapObjectController]
1271 clusterMapObjectController = nil
1272 clusterMapObjectControllerListener = nil
1276 * Demonstrate remove all map objects
1278 private func demonstrateRemoveAllMapObjects() {
1279 print("--- Remove All Map Objects ---")
1281 guard let locationWindow = locationWindow else {
1282 print("LocationWindow not available yet")
1286 print("Current map objects count: \(getMapObjectsCount())")
1288 // [swift_LocationWindow_removeAllMapObjects]
1289 // Remove all map objects
1290 locationWindow.removeAllMapObjects()
1291 print("Removed all map objects")
1292 // [swift_LocationWindow_removeAllMapObjects]
1294 print("Map objects count after removal: \(getMapObjectsCount())")
1298 * Get current map objects count
1300 private func getMapObjectsCount() -> Int {
1302 if circleMapObject != nil { count += 1 }
1303 if iconMapObject != nil { count += 1 }
1304 if polygonMapObject != nil { count += 1 }
1305 if polylineMapObject != nil { count += 1 }
1306 if dottedPolylineMapObject != nil { count += 1 }
1313 private func cleanup() {
1314 print("--- Cleanup ---")
1316 if let locationWindow = locationWindow {
1317 locationWindow.removeAllMapObjects()
1318 print("Cleaned up all map objects")
1321 circleMapObject = nil
1323 modelMapObject = nil
1324 polygonMapObject = nil
1325 polylineMapObject = nil
1326 dottedPolylineMapObject = nil
1327 print("Cleared map objects references")
1331class DemoClusterMapObjectControllerListener: NSObject, NCClusterMapObjectControllerListener {
1332 private let clusterChangeListener = DemoClusterMapObjectListener()
1333 private weak var activeCluster: NCClusterMapObject?
1335 // [swift_ClusterMapObjectControllerListener_onClusterCreated]
1336 func onClusterCreated(_ controller: NCClusterMapObjectController?, cluster: NCClusterMapObject?) {
1337 guard let cluster else { return }
1338 // [swift_ClusterMapObject_addListener]
1339 cluster.add(clusterChangeListener)
1340 print("Added cluster change listener, initial count: \(cluster.count)")
1341 // [swift_ClusterMapObject_addListener]
1342 activeCluster = cluster
1344 // [swift_ClusterMapObjectControllerListener_onClusterCreated]
1346 // [swift_ClusterMapObjectControllerListener_onClusterDestroyed]
1347 func onClusterDestroyed(_ controller: NCClusterMapObjectController?, clusterId: Int32) {
1348 if let cluster = activeCluster, cluster.id == clusterId {
1349 // [swift_ClusterMapObject_removeListener]
1350 cluster.remove(clusterChangeListener)
1351 print("Removed cluster change listener")
1352 // [swift_ClusterMapObject_removeListener]
1355 print("Cluster destroyed, id: \(clusterId)")
1357 // [swift_ClusterMapObjectControllerListener_onClusterDestroyed]
1360class DemoClusterMapObjectListener: NSObject, NCClusterMapObjectListener {
1362 // [swift_ClusterMapObjectListener_onClusterChanged]
1363 func onClusterChanged(_ cluster: NCClusterMapObject) {
1364 let memberCount = cluster.count
1365 print("Cluster changed, member count: \(memberCount)")
1367 // [swift_ClusterMapObjectListener_onClusterChanged]
1370// Main function to run the example
1371let example = LocationWindowMapObjectsExample()