Loading...
Searching...
No Matches
location_window_map_objects_example.dart
Go to the documentation of this file.
1import 'dart:ffi';
2import 'dart:io' show File;
3import 'dart:math' as math;
4import 'dart:typed_data';
5import 'package:flutter/painting.dart' show AssetImage;
6import 'package:meta/meta.dart';
7import 'package:navigine_sdk/com/_library_context.dart' as __lib;
8import 'package:navigine_sdk/com/_native_base.dart' as __lib;
9import 'package:navigine_sdk/com/_weak_map.dart';
10import 'package:navigine_sdk/com/builtin_types__conversion.dart';
11import 'package:navigine_sdk/com/navigine/idl/animation_type.dart';
12import 'package:navigine_sdk/com/navigine/idl/cap_type.dart';
13import 'package:navigine_sdk/com/navigine/idl/circle_map_object.dart';
14import 'package:navigine_sdk/com/navigine/idl/dotted_polyline_map_object.dart';
15import 'package:navigine_sdk/com/navigine/idl/cluster_map_object.dart';
16import 'package:navigine_sdk/com/navigine/idl/cluster_map_object_controller.dart';
17import 'package:navigine_sdk/com/navigine/idl/cluster_map_object_controller_listener.dart';
18import 'package:navigine_sdk/com/navigine/idl/cluster_map_object_listener.dart';
19import 'package:navigine_sdk/com/navigine/idl/icon_map_object.dart';
20import 'package:navigine_sdk/com/navigine/idl/join_type.dart';
21import 'package:navigine_sdk/com/navigine/idl/location_point.dart';
22import 'package:navigine_sdk/com/navigine/sdk/location_polygon.dart';
23import 'package:navigine_sdk/com/navigine/sdk/location_polyline.dart';
24import 'package:navigine_sdk/com/navigine/idl/location_window.dart';
25import 'package:navigine_sdk/com/navigine/idl/map_object.dart';
26import 'package:navigine_sdk/com/navigine/idl/map_object_type.dart';
27import 'package:navigine_sdk/com/navigine/idl/model_map_object.dart';
28import 'package:navigine_sdk/com/navigine/idl/placement.dart';
29import 'package:navigine_sdk/com/navigine/idl/point.dart';
30import 'package:navigine_sdk/com/navigine/idl/polygon.dart';
31import 'package:navigine_sdk/com/navigine/idl/polygon_map_object.dart';
32import 'package:navigine_sdk/com/navigine/idl/polyline.dart';
33import 'package:navigine_sdk/com/navigine/idl/polyline_map_object.dart';
34import 'package:navigine_sdk/image_provider.dart';
35import 'package:navigine_sdk/model_provider.dart';
36
44class LocationWindowMapObjectsExample {
53 DemoClusterMapObjectControllerListener? _clusterMapObjectControllerListener;
54
55 LocationWindowMapObjectsExample() {
56 _demonstrateLocationWindowMapObjectsMethods();
57 }
58
62 void _demonstrateLocationWindowMapObjectsMethods() {
63 print("=== LocationWindowMapObjects Example ===");
64
65 _demonstrateLocationScopedGeometryRecords();
66
67 _demonstrateCircleMapObjects();
68 _demonstrateIconMapObjects();
69 _demonstrateClusterMapObjects();
70 _demonstrateModelMapObjects();
71 _demonstratePolygonMapObjects();
72 _demonstratePolylineMapObjects();
73 _demonstrateDottedPolylineMapObjects();
74 _demonstrateRemoveAllMapObjects();
75 _cleanup();
76 }
77
81 void _demonstrateLocationScopedGeometryRecords() {
82 print("--- LocationPolygon / LocationPolyline records ---");
83
84 // [dart_LocationPolygon_record]
85 List<Point> ring = [
86 Point(1.0, 2.0),
87 Point(3.0, 4.0),
88 Point(5.0, 2.0),
89 ];
90 Polygon metricPolygon = Polygon(ring);
91 LocationPolygon locationPolygon = LocationPolygon(metricPolygon, 42, 7);
92 Polygon polygonBack = locationPolygon.polygon;
93 print(
94 "LocationPolygon: location ${locationPolygon.locationId} sublocation ${locationPolygon.sublocationId} vertices ${polygonBack.points.length}",
95 );
96 // [dart_LocationPolygon_record]
97
98 // [dart_LocationPolyline_record]
99 List<Point> linePts = [Point(0.0, 0.0), Point(10.0, 10.0)];
100 Polyline metricPolyline = Polyline(linePts);
101 LocationPolyline locationPolyline = LocationPolyline(metricPolyline, 42, 7);
102 Polyline polylineBack = locationPolyline.polyline;
103 print("LocationPolyline points ${polylineBack.points.length}");
104 // [dart_LocationPolyline_record]
105 }
106
110 void _demonstrateCircleMapObjects() {
111 print("--- Circle Map Objects ---");
112
113 if (_locationWindow == null) {
114 print("LocationWindow not available yet");
115 return;
116 }
117
118 // [dart_CircleMapObject_constructor]
119 // Create circle map object
120 LocationPoint center = LocationPoint(10.0, 20.0);
121 _circleMapObject = _locationWindow!.addCircleMapObject();
122 print(
123 "Created circle map object with center (${center.x}, ${center.y}) and radius 5.0",
124 );
125 // [dart_CircleMapObject_constructor]
126
127 // [dart_CircleMapObject_getCenter]
128 // Access circle center
129 LocationPoint circleCenter = _circleMapObject!.getPosition();
130 print("Circle center: (${circleCenter.x}, ${circleCenter.y})");
131 // [dart_CircleMapObject_getCenter]
132
133 // [dart_CircleMapObject_getRadius]
134 // Access circle radius
135 double radius = _circleMapObject!.getRadius();
136 print("Circle radius: $radius");
137 // [dart_CircleMapObject_getRadius]
138
139 // [dart_LocationWindow_addCircleMapObject]
140 // Add circle map object
141 _circleMapObject = _locationWindow!.addCircleMapObject();
142 print("Added circle map object");
143 // [dart_LocationWindow_addCircleMapObject]
144
145 if (_circleMapObject != null) {
146 // [dart_CircleMapObject_setPosition]
147 // Set circle position
148 LocationPoint centerPoint = LocationPoint(100.0, 200.0);
149 bool success = _circleMapObject!.setPosition(centerPoint);
150 print(
151 "Set circle position to (${centerPoint.x}, ${centerPoint.y}): $success",
152 );
153 // [dart_CircleMapObject_setPosition]
154
155 // [dart_CircleMapObject_setPositionAnimated]
156 // Set circle position with animation
157 LocationPoint animatedPoint = LocationPoint(150.0, 250.0);
158 bool animatedSuccess = _circleMapObject!.setPositionAnimated(
159 animatedPoint,
160 2.0,
161 AnimationType.LINEAR,
162 );
163 print(
164 "Set circle position with animation to (${animatedPoint.x}, ${animatedPoint.y}): $animatedSuccess",
165 );
166 // [dart_CircleMapObject_setPositionAnimated]
167
168 // [dart_CircleMapObject_setOffset]
169 // Set position offset
170 bool offsetSuccess = _circleMapObject!.setOffset(2.0, 3.0);
171 print("Set position offset to (2.0, 3.0) pixels: $offsetSuccess");
172 // [dart_CircleMapObject_setOffset]
173
174 // [dart_CircleMapObject_setOutlineColor]
175 // Set outline color
176 bool outlineColorSuccess = _circleMapObject!.setOutlineColor(
177 0.0,
178 0.0,
179 1.0,
180 1.0,
181 );
182 print("Set circle outline color to blue: $outlineColorSuccess");
183 // [dart_CircleMapObject_setOutlineColor]
184
185 // [dart_CircleMapObject_setOutlineAlpha]
186 // Set outline alpha
187 bool outlineAlphaSuccess = _circleMapObject!.setOutlineAlpha(0.5);
188 print("Set circle outline alpha to 0.5: $outlineAlphaSuccess");
189 // [dart_CircleMapObject_setOutlineAlpha]
190
191 // [dart_CircleMapObject_setOutlineRadius]
192 // Set outline radius
193 bool outlineRadiusSuccess = _circleMapObject!.setOutlineRadius(2.0);
194 print("Set circle outline radius to 2.0: $outlineRadiusSuccess");
195 // [dart_CircleMapObject_setOutlineRadius]
196
197 // [dart_CircleMapObject_setColor]
198 // Set circle color
199 bool colorSuccess = _circleMapObject!.setColor(1.0, 0.0, 0.0, 0.8);
200 print("Set circle color to red with 80% opacity: $colorSuccess");
201 // [dart_CircleMapObject_setColor]
202
203 // [dart_CircleMapObject_setRadius]
204 // Set circle radius
205 bool radiusSuccess = _circleMapObject!.setRadius(10.0);
206 print("Set circle radius to 10.0 meters: $radiusSuccess");
207 // [dart_CircleMapObject_setRadius]
208
209 // [dart_CircleMapObject_setCollisionEnabled]
210 // Enable collision detection
211 bool collisionSuccess = _circleMapObject!.setCollisionEnabled(true);
212 print("Enabled collision detection for circle: $collisionSuccess");
213 // [dart_CircleMapObject_setCollisionEnabled]
214
215 // [dart_CircleMapObject_setBuffer]
216 // Set collision buffer
217 bool bufferSuccess = _circleMapObject!.setBuffer(5.0, 5.0);
218 print("Set collision buffer to 5x5 pixels: $bufferSuccess");
219 // [dart_CircleMapObject_setBuffer]
220
221 // [dart_CircleMapObject_setPriority]
222 // Set rendering priority
223 bool prioritySuccess = _circleMapObject!.setPriority(1);
224 print("Set rendering priority to 1: $prioritySuccess");
225 // [dart_CircleMapObject_setPriority]
226
227 // [dart_MapObject_setVisible]
228 // Set visibility
229 bool visibleSuccess = _circleMapObject!.setVisible(true);
230 print("Set circle visibility to true: $visibleSuccess");
231 // [dart_MapObject_setVisible]
232
233 // [dart_CircleMapObject_getMapObjectType]
234 // Get map object type
235 MapObjectType objectType = _circleMapObject!.mapObjectType;
236 print("Circle map object type: $objectType");
237 // [dart_CircleMapObject_getMapObjectType]
238
239 // [dart_MapObject_setAlpha]
240 // Set alpha transparency
241 bool alphaSuccess = _circleMapObject!.setAlpha(0.7);
242 print("Set circle alpha to 0.7: $alphaSuccess");
243 // [dart_MapObject_setAlpha]
244
245 // [dart_MapObject_setInteractive]
246 // Set interactive mode
247 bool interactiveSuccess = _circleMapObject!.setInteractive(true);
248 print("Set circle interactive to true: $interactiveSuccess");
249 // [dart_MapObject_setInteractive]
250
251 // [dart_MapObject_setTitle]
252 // Set title
253 bool titleSuccess = _circleMapObject!.setTitle("Circle Object");
254 print("Set circle title to 'Circle Object': $titleSuccess");
255 // [dart_MapObject_setTitle]
256
257 // [dart_MapObject_setData]
258 // Set custom data
259 Map<String, dynamic> customData = {"key": "value", "number": 42};
260 bool dataSuccess = _circleMapObject!.setData(customData);
261 print("Set circle custom data: $dataSuccess");
262 // [dart_MapObject_setData]
263
264 // [dart_MapObject_getId]
265 // Get object ID
266 int objectId = _circleMapObject!.id;
267 print("Circle object ID: $objectId");
268 // [dart_MapObject_getId]
269
270 // [dart_MapObject_getType]
271 // Get object type
272 String objectTypeString = _circleMapObject!.type;
273 print("Circle object type: $objectTypeString");
274 // [dart_MapObject_getType]
275
276 // [dart_MapObject_getData]
277 // Get custom data
278 Map<String, dynamic> retrievedData = _circleMapObject!.data;
279 print("Circle custom data: $retrievedData");
280 // [dart_MapObject_getData]
281 }
282
283 // [dart_LocationWindow_removeCircleMapObject]
284 // Remove circle map object
285 if (_circleMapObject != null) {
286 bool removed = _locationWindow!.removeCircleMapObject(_circleMapObject!);
287 print("Removed circle map object: $removed");
288 _circleMapObject = null;
289 }
290 // [dart_LocationWindow_removeCircleMapObject]
291
292 // Test multiple circle objects
293 List<CircleMapObject> circles = [];
294 for (int i = 0; i < 3; i++) {
295 CircleMapObject circle = _locationWindow!.addCircleMapObject();
296 if (circle != null) {
297 circle.setPosition(LocationPoint(50.0 * i, 100.0 * i));
298 circle.setColor(0.0, 1.0, 0.0, 0.6);
299 circle.setRadius(5.0 + i * 2.0);
300 circles.add(circle);
301 print(
302 "Created circle $i at (${50.0 * i}, ${100.0 * i}) with radius ${5.0 + i * 2.0}",
303 );
304 }
305 }
306
307 for (int i = 0; i < circles.length; i++) {
308 _locationWindow!.removeCircleMapObject(circles[i]);
309 print("Removed circle $i");
310 }
311 }
312
316 void _demonstrateIconMapObjects() {
317 print("--- Icon Map Objects ---");
318
319 if (_locationWindow == null) {
320 print("LocationWindow not available yet");
321 return;
322 }
323
324 // [dart_IconMapObject_constructor]
325 // Create icon map object
326 LocationPoint position = LocationPoint(30.0, 40.0);
327 _iconMapObject = _locationWindow!.addIconMapObject();
328 print("Created icon map object at (${position.x}, ${position.y})");
329 // [dart_IconMapObject_constructor]
330
331 // [dart_IconMapObject_getPosition]
332 // Access icon position
333 LocationPoint iconPosition = _iconMapObject!.getPosition();
334 print("Icon position: (${iconPosition.x}, ${iconPosition.y})");
335 // [dart_IconMapObject_getPosition]
336
337 // [dart_LocationWindow_addIconMapObject]
338 // Add icon map object
339 _iconMapObject = _locationWindow!.addIconMapObject();
340 print("Added icon map object");
341 // [dart_LocationWindow_addIconMapObject]
342
343 if (_iconMapObject != null) {
344 // [dart_IconMapObject_setPosition]
345 // Set icon position
346 LocationPoint iconPoint = LocationPoint(200.0, 300.0);
347 bool success = _iconMapObject!.setPosition(iconPoint);
348 print("Set icon position to (${iconPoint.x}, ${iconPoint.y}): $success");
349 // [dart_IconMapObject_setPosition]
350
351 // [dart_IconMapObject_setPositionAnimated]
352 // Set icon position with animation
353 LocationPoint animatedIconPoint = LocationPoint(250.0, 350.0);
354 bool animatedSuccess = _iconMapObject!.setPositionAnimated(
355 animatedIconPoint,
356 1.5,
357 AnimationType.CUBIC,
358 );
359 print(
360 "Set icon position with animation to (${animatedIconPoint.x}, ${animatedIconPoint.y}): $animatedSuccess",
361 );
362 // [dart_IconMapObject_setPositionAnimated]
363
364 // [dart_IconMapObject_setSize]
365 // Set icon size
366 bool sizeSuccess = _iconMapObject!.setSize(32.0, 32.0);
367 print("Set icon size to 32x32 pixels: $sizeSuccess");
368 // [dart_IconMapObject_setSize]
369
370 // [dart_IconMapObject_setAngle]
371 // Set icon rotation angle
372 bool angleSuccess = _iconMapObject!.setAngle(45.0);
373 print("Set icon rotation angle to 45 degrees: $angleSuccess");
374 // [dart_IconMapObject_setAngle]
375
376 // [dart_IconMapObject_setAngleAnimated]
377 // Set icon rotation with animation
378 bool angleAnimatedSuccess = _iconMapObject!.setAngleAnimated(
379 90.0,
380 2.0,
381 AnimationType.SINE,
382 );
383 print(
384 "Set icon rotation with animation to 90 degrees: $angleAnimatedSuccess",
385 );
386 // [dart_IconMapObject_setAngleAnimated]
387
388 // [dart_IconMapObject_setCollisionEnabled]
389 // Enable collision detection
390 bool collisionSuccess = _iconMapObject!.setCollisionEnabled(true);
391 print("Enabled collision detection for icon: $collisionSuccess");
392 // [dart_IconMapObject_setCollisionEnabled]
393
394 // [dart_IconMapObject_setBuffer]
395 // Set collision buffer
396 bool bufferSuccess = _iconMapObject!.setBuffer(10.0, 10.0);
397 print("Set collision buffer to 10x10 pixels: $bufferSuccess");
398 // [dart_IconMapObject_setBuffer]
399
400 // [dart_IconMapObject_setOffset]
401 // Set position offset
402 bool offsetSuccess = _iconMapObject!.setOffset(0.0, -16.0);
403 print("Set position offset to (0.0, -16.0) pixels: $offsetSuccess");
404 // [dart_IconMapObject_setOffset]
405
406 // [dart_IconMapObject_setPriority]
407 // Set rendering priority
408 bool prioritySuccess = _iconMapObject!.setPriority(2);
409 print("Set rendering priority to 2: $prioritySuccess");
410 // [dart_IconMapObject_setPriority]
411
412 // [dart_IconMapObject_setVisible]
413 // Set visibility
414 bool visibleSuccess = _iconMapObject!.setVisible(true);
415 print("Set icon visibility to true: $visibleSuccess");
416 // [dart_IconMapObject_setVisible]
417
418 // [dart_IconMapObject_getMapObjectType]
419 // Get map object type
420 MapObjectType objectType = _iconMapObject!.mapObjectType;
421 print("Icon map object type: $objectType");
422 // [dart_IconMapObject_getMapObjectType]
423
424 // [dart_IconMapObject_setBitmap]
425 // Icon pixels come from package:navigine_sdk ImageProvider (async decode in the engine).
426 ImageProvider iconProvider = ImageProvider.fromImageProvider(
427 const AssetImage('assets/icon.png'),
428 cacheable: true,
429 );
430 bool bitmapSuccess = _iconMapObject!.setBitmap(iconProvider);
431 print("Set icon from ImageProvider: $bitmapSuccess");
432 // [dart_IconMapObject_setBitmap]
433
434 // [dart_IconMapObject_setFlat]
435 // Set icon flat mode
436 bool flatSuccess = _iconMapObject!.setFlat(true);
437 print("Set icon flat mode to true: $flatSuccess");
438 // [dart_IconMapObject_setFlat]
439
440 // [dart_MapObject_setAlpha_1]
441 // Set alpha transparency
442 bool alphaSuccess = _iconMapObject!.setAlpha(0.7);
443 print("Set icon alpha to 0.7: $alphaSuccess");
444 // [dart_MapObject_setAlpha_1]
445
446 // [dart_MapObject_setInteractive_1]
447 // Set interactive mode
448 bool interactiveSuccess = _iconMapObject!.setInteractive(true);
449 print("Set icon interactive to true: $interactiveSuccess");
450 // [dart_MapObject_setInteractive_1]
451
452 // [dart_MapObject_setTitle_1]
453 // Set title
454 bool titleSuccess = _iconMapObject!.setTitle("Icon Object");
455 print("Set icon title to 'Icon Object': $titleSuccess");
456 // [dart_MapObject_setTitle_1]
457
458 // [dart_MapObject_setData_1]
459 // Set custom data
460 Map<String, dynamic> customData = {"key": "value", "number": 42};
461 bool dataSuccess = _iconMapObject!.setData(customData);
462 print("Set icon custom data: $dataSuccess");
463 // [dart_MapObject_setData_1]
464
465 // [dart_MapObject_getId_1]
466 // Get object ID
467 int objectId = _iconMapObject!.id;
468 print("Icon object ID: $objectId");
469 // [dart_MapObject_getId_1]
470
471 // [dart_MapObject_getType_1]
472 // Get object type
473 String objectTypeString = _iconMapObject!.type;
474 print("Icon object type: $objectTypeString");
475 // [dart_MapObject_getType_1]
476
477 // [dart_MapObject_getData_1]
478 // Get custom data
479 Map<String, dynamic> retrievedData = _iconMapObject!.data;
480 print("Icon custom data: $retrievedData");
481 // [dart_MapObject_getData_1]
482 }
483
484 // [dart_LocationWindow_removeIconMapObject]
485 // Remove icon map object
486 if (_iconMapObject != null) {
487 bool removed = _locationWindow!.removeIconMapObject(_iconMapObject!);
488 print("Removed icon map object: $removed");
489 _iconMapObject = null;
490 }
491 // [dart_LocationWindow_removeIconMapObject]
492
493 // Test multiple icon objects
494 List<IconMapObject> icons = [];
495 ImageProvider loopIcon = ImageProvider.fromImageProvider(
496 const AssetImage('assets/icon.png'),
497 cacheable: true,
498 );
499 for (int i = 0; i < 3; i++) {
500 final IconMapObject? icon = _locationWindow!.addIconMapObject();
501 if (icon != null) {
502 icon.setPosition(LocationPoint(100.0 * i, 150.0 * i));
503 icon.setBitmap(loopIcon);
504 icon.setSize(24.0, 24.0);
505 icon.setAngle(i * 30.0);
506 icons.add(icon);
507 print(
508 "Created icon $i at (${100.0 * i}, ${150.0 * i}) with angle ${i * 30.0}",
509 );
510 }
511 }
512
513 for (int i = 0; i < icons.length; i++) {
514 _locationWindow!.removeIconMapObject(icons[i]);
515 print("Removed icon $i");
516 }
517 }
518
522 void _demonstrateModelMapObjects() {
523 print("--- Model Map Objects ---");
524
525 if (_locationWindow == null) {
526 print("LocationWindow not available yet");
527 return;
528 }
529
530 // [dart_LocationWindow_addModelMapObject]
531 _modelMapObject = _locationWindow!.addModelMapObject();
532 print("Added model map object: ${_modelMapObject != null}");
533 // [dart_LocationWindow_addModelMapObject]
534
535 final ModelMapObject? m = _modelMapObject;
536 if (m == null) {
537 return;
538 }
539
540 // [dart_ModelMapObject_setPosition]
541 bool posOk = m.setPosition(LocationPoint(12.0, 34.0));
542 print("Model setPosition: $posOk");
543 // [dart_ModelMapObject_setPosition]
544
545 // [dart_ModelMapObject_setPositionAnimated]
546 bool posAnimOk = m.setPositionAnimated(
547 LocationPoint(15.0, 40.0),
548 0.5,
549 AnimationType.SINE,
550 );
551 print("Model setPositionAnimated: $posAnimOk");
552 // [dart_ModelMapObject_setPositionAnimated]
553
554 // [dart_ModelMapObject_setModel]
555 ImageProvider texture = ImageProvider.fromImageProvider(
556 const AssetImage('assets/model_texture.png'),
557 cacheable: true,
558 );
559 ModelProvider modelProvider = ModelProvider(
560 texture,
561 onModelRequest: () async {
562 final bytes = await File('/path/to/model.obj').readAsBytes();
563 return ByteData.sublistView(bytes);
564 },
565 );
566 bool modelOk = m.setModel(modelProvider);
567 print("Model setModel: $modelOk");
568 // [dart_ModelMapObject_setModel]
569
570 // [dart_ModelMapObject_setSize]
571 bool sizeOk = m.setSize(64.0, 64.0);
572 print("Model setSize: $sizeOk");
573 // [dart_ModelMapObject_setSize]
574
575 // [dart_ModelMapObject_setCollisionEnabled]
576 bool collOk = m.setCollisionEnabled(true);
577 print("Model setCollisionEnabled: $collOk");
578 // [dart_ModelMapObject_setCollisionEnabled]
579
580 // [dart_ModelMapObject_setAngle]
581 bool angleOk = m.setAngle(45.0);
582 print("Model setAngle: $angleOk");
583 // [dart_ModelMapObject_setAngle]
584
585 // [dart_ModelMapObject_setAngleAnimated]
586 bool angleAnimOk = m.setAngleAnimated(90.0, 0.5, AnimationType.QUINT);
587 print("Model setAngleAnimated: $angleAnimOk");
588 // [dart_ModelMapObject_setAngleAnimated]
589
590 // [dart_ModelMapObject_setBuffer]
591 bool bufOk = m.setBuffer(4.0, 4.0);
592 print("Model setBuffer: $bufOk");
593 // [dart_ModelMapObject_setBuffer]
594
595 // [dart_ModelMapObject_setPriority]
596 bool priOk = m.setPriority(10.0);
597 print("Model setPriority: $priOk");
598 // [dart_ModelMapObject_setPriority]
599
600 // [dart_LocationWindow_removeModelMapObject]
601 bool removed = _locationWindow!.removeModelMapObject(m);
602 print("Removed model map object: $removed");
603 _modelMapObject = null;
604 // [dart_LocationWindow_removeModelMapObject]
605 }
606
610 void _demonstratePolygonMapObjects() {
611 print("--- Polygon Map Objects ---");
612
613 if (_locationWindow == null) {
614 print("LocationWindow not available yet");
615 return;
616 }
617
618 // [dart_LocationWindow_addPolygonMapObject]
619 // Add polygon map object
620 _polygonMapObject = _locationWindow!.addPolygonMapObject();
621 print("Added polygon map object");
622 // [dart_LocationWindow_addPolygonMapObject]
623
624 if (_polygonMapObject != null) {
625 // [dart_PolygonMapObject_setPolygon]
626 // Set polygon geometry
627 List<Point> points = [
628 Point(100.0, 200.0),
629 Point(150.0, 250.0),
630 Point(200.0, 200.0),
631 Point(150.0, 150.0),
632 ];
633 Polygon metricPolygon = Polygon(points);
634 LocationPolygon polygon = LocationPolygon(metricPolygon, 1, 0);
635 bool success = _polygonMapObject!.setPolygon(polygon);
636 print("Set polygon with ${points.length} points: $success");
637 // [dart_PolygonMapObject_setPolygon]
638
639 // [dart_PolygonMapObject_setColor]
640 // Set polygon color
641 bool colorSuccess = _polygonMapObject!.setColor(0.0, 1.0, 0.0, 0.7);
642 print("Set polygon color to green with 70% opacity: $colorSuccess");
643 // [dart_PolygonMapObject_setColor]
644
645 // [dart_PolygonMapObject_setOutlineColor]
646 // Set polygon outline color
647 bool outlineColorSuccess = _polygonMapObject!.setOutlineColor(
648 0.0,
649 0.0,
650 1.0,
651 1.0,
652 );
653 print("Set polygon outline color to blue: $outlineColorSuccess");
654 // [dart_PolygonMapObject_setOutlineColor]
655
656 // [dart_PolygonMapObject_setOutlineWidth]
657 // Set polygon outline width
658 bool outlineWidthSuccess = _polygonMapObject!.setOutlineWidth(2.0);
659 print("Set polygon outline width to 2.0 pixels: $outlineWidthSuccess");
660 // [dart_PolygonMapObject_setOutlineWidth]
661
662 // [dart_PolygonMapObject_setOutlineAlpha]
663 // Set polygon outline alpha
664 bool outlineAlphaSuccess = _polygonMapObject!.setOutlineAlpha(0.8);
665 print("Set polygon outline alpha to 0.8: $outlineAlphaSuccess");
666 // [dart_PolygonMapObject_setOutlineAlpha]
667
668 // [dart_PolygonMapObject_setOutlineOrder]
669 // Set polygon outline order
670 bool outlineOrderSuccess = _polygonMapObject!.setOutlineOrder(1);
671 print("Set polygon outline order to 1: $outlineOrderSuccess");
672 // [dart_PolygonMapObject_setOutlineOrder]
673
674 // [dart_PolygonMapObject_setOrder]
675 // Set polygon rendering order
676 bool orderSuccess = _polygonMapObject!.setOrder(2);
677 print("Set polygon rendering order to 2: $orderSuccess");
678 // [dart_PolygonMapObject_setOrder]
679
680 // [dart_PolygonMapObject_setVisible]
681 // Set visibility
682 bool visibleSuccess = _polygonMapObject!.setVisible(true);
683 print("Set polygon visibility to true: $visibleSuccess");
684 // [dart_PolygonMapObject_setVisible]
685
686 // [dart_PolygonMapObject_getMapObjectType]
687 // Get map object type
688 MapObjectType objectType = _polygonMapObject!.mapObjectType;
689 print("Polygon map object type: $objectType");
690 // [dart_PolygonMapObject_getMapObjectType]
691
692 // [dart_MapObject_setAlpha_2]
693 // Set alpha transparency
694 bool alphaSuccess = _polygonMapObject!.setAlpha(0.7);
695 print("Set polygon alpha to 0.7: $alphaSuccess");
696 // [dart_MapObject_setAlpha_2]
697
698 // [dart_MapObject_setInteractive_2]
699 // Set interactive mode
700 bool interactiveSuccess = _polygonMapObject!.setInteractive(true);
701 print("Set polygon interactive to true: $interactiveSuccess");
702 // [dart_MapObject_setInteractive_2]
703
704 // [dart_MapObject_setTitle_2]
705 // Set title
706 bool titleSuccess = _polygonMapObject!.setTitle("Polygon Object");
707 print("Set polygon title to 'Polygon Object': $titleSuccess");
708 // [dart_MapObject_setTitle_2]
709
710 // [dart_MapObject_setData_2]
711 // Set custom data
712 Map<String, dynamic> customData = {"key": "value", "number": 42};
713 bool dataSuccess = _polygonMapObject!.setData(customData);
714 print("Set polygon custom data: $dataSuccess");
715 // [dart_MapObject_setData_2]
716
717 // [dart_MapObject_getId_2]
718 // Get object ID
719 int objectId = _polygonMapObject!.id;
720 print("Polygon object ID: $objectId");
721 // [dart_MapObject_getId_2]
722
723 // [dart_MapObject_getType_2]
724 // Get object type
725 String objectTypeString = _polygonMapObject!.type;
726 print("Polygon object type: $objectTypeString");
727 // [dart_MapObject_getType_2]
728
729 // [dart_MapObject_getData_2]
730 // Get custom data
731 Map<String, dynamic> retrievedData = _polygonMapObject!.data;
732 print("Polygon custom data: $retrievedData");
733 // [dart_MapObject_getData_2]
734 }
735
736 // [dart_LocationWindow_removePolygonMapObject]
737 // Remove polygon map object
738 if (_polygonMapObject != null) {
739 bool removed = _locationWindow!.removePolygonMapObject(
741 );
742 print("Removed polygon map object: $removed");
743 _polygonMapObject = null;
744 }
745 // [dart_LocationWindow_removePolygonMapObject]
746
747 // Test multiple polygon objects
748 List<PolygonMapObject> polygons = [];
749 for (int i = 0; i < 3; i++) {
750 PolygonMapObject polygon = _locationWindow!.addPolygonMapObject();
751 if (polygon != null) {
752 List<Point> points = [
753 Point(300.0 + i * 50, 400.0 + i * 50),
754 Point(350.0 + i * 50, 450.0 + i * 50),
755 Point(400.0 + i * 50, 400.0 + i * 50),
756 Point(350.0 + i * 50, 350.0 + i * 50),
757 ];
758 Polygon metricPoly = Polygon(points);
759 LocationPolygon polygonGeometry = LocationPolygon(metricPoly, 1, 0);
760 polygon.setPolygon(polygonGeometry);
761 polygon.setColor(0.0, 0.0, 1.0, 0.5);
762 polygons.add(polygon);
763 print("Created polygon $i with ${points.length} points");
764 }
765 }
766
767 for (int i = 0; i < polygons.length; i++) {
768 _locationWindow!.removePolygonMapObject(polygons[i]);
769 print("Removed polygon $i");
770 }
771 }
772
776 void _demonstratePolylineMapObjects() {
777 print("--- Polyline Map Objects ---");
778
779 if (_locationWindow == null) {
780 print("LocationWindow not available yet");
781 return;
782 }
783
784 // [dart_PolylineMapObject_constructor]
785 // Create polyline map object
786 List<Point> points = [
787 Point(100.0, 110.0),
788 Point(105.0, 115.0),
789 Point(110.0, 120.0),
790 Point(115.0, 125.0),
791 ];
792 Polyline polyline = Polyline(points);
793 LocationPolyline locationPolyline = LocationPolyline(polyline, 1, 0);
794 _polylineMapObject = _locationWindow!.addPolylineMapObject();
795 print("Created polyline map object with ${points.length} points");
796 // [dart_PolylineMapObject_constructor]
797
798 // [dart_PolylineMapObject_getPolyline]
799 // Access polyline
800 LocationPolyline polylineShape = _polylineMapObject!.getPolyLine();
801 print("Polyline has ${polylineShape.polyline.points.length} points");
802 // [dart_PolylineMapObject_getPolyline]
803
804 // [dart_LocationWindow_addPolylineMapObject]
805 // Add polyline map object
806 _polylineMapObject = _locationWindow!.addPolylineMapObject();
807 print("Added polyline map object");
808 // [dart_LocationWindow_addPolylineMapObject]
809
810 if (_polylineMapObject != null) {
811 // [dart_PolylineMapObject_setPolyLine]
812 // Set polyline geometry
813 List<Point> polylinePoints = [
814 Point(0.0, 0.0),
815 Point(50.0, 50.0),
816 Point(100.0, 0.0),
817 Point(150.0, 50.0),
818 ];
819 Polyline polyline = Polyline(polylinePoints);
820 LocationPolyline locationPolyline = LocationPolyline(polyline, 1, 0);
821 bool success = _polylineMapObject!.setPolyLine(locationPolyline);
822 print("Set polyline geometry: $success");
823 // [dart_PolylineMapObject_setPolyLine]
824
825 // [dart_PolylineMapObject_setWidth]
826 // Set polyline width
827 bool widthSuccess = _polylineMapObject!.setWidth(3.0);
828 print("Set polyline width to 3.0 pixels: $widthSuccess");
829 // [dart_PolylineMapObject_setWidth]
830
831 // [dart_PolylineMapObject_setColor]
832 // Set polyline color
833 bool colorSuccess = _polylineMapObject!.setColor(1.0, 0.5, 0.0, 0.9);
834 print("Set polyline color to orange with 90% opacity: $colorSuccess");
835 // [dart_PolylineMapObject_setColor]
836
837 // [dart_PolylineMapObject_setOrder]
838 // Set rendering order
839 bool orderSuccess = _polylineMapObject!.setOrder(2);
840 print("Set rendering order to 2: $orderSuccess");
841 // [dart_PolylineMapObject_setOrder]
842
843 // [dart_PolylineMapObject_setCapType]
844 // Set cap type
845 bool capSuccess = _polylineMapObject!.setCapType(CapType.ROUND);
846 print("Set cap type to ROUND: $capSuccess");
847 // [dart_PolylineMapObject_setCapType]
848
849 // [dart_PolylineMapObject_setJoinType]
850 // Set join type
851 bool joinSuccess = _polylineMapObject!.setJoinType(JoinType.ROUND);
852 print("Set join type to ROUND: $joinSuccess");
853 // [dart_PolylineMapObject_setJoinType]
854
855 // [dart_PolylineMapObject_setMiterLimit]
856 // Set miter limit
857 bool miterSuccess = _polylineMapObject!.setMiterLimit(5.0);
858 print("Set miter limit to 5.0: $miterSuccess");
859 // [dart_PolylineMapObject_setMiterLimit]
860
861 // [dart_PolylineMapObject_setOutlineWidth]
862 // Set outline width
863 bool outlineWidthSuccess = _polylineMapObject!.setOutlineWidth(1.0);
864 print("Set polyline outline width to 1.0: $outlineWidthSuccess");
865 // [dart_PolylineMapObject_setOutlineWidth]
866
867 // [dart_PolylineMapObject_setOutlineColor]
868 // Set outline color
869 bool outlineColorSuccess = _polylineMapObject!.setOutlineColor(
870 0.0,
871 0.0,
872 0.0,
873 1.0,
874 );
875 print("Set polyline outline color to black: $outlineColorSuccess");
876 // [dart_PolylineMapObject_setOutlineColor]
877
878 // [dart_PolylineMapObject_setOutlineAlpha]
879 // Set outline alpha
880 bool outlineAlphaSuccess = _polylineMapObject!.setOutlineAlpha(0.8);
881 print("Set polyline outline alpha to 0.8: $outlineAlphaSuccess");
882 // [dart_PolylineMapObject_setOutlineAlpha]
883
884 // [dart_PolylineMapObject_setOutlineOrder]
885 // Set outline order
886 bool outlineOrderSuccess = _polylineMapObject!.setOutlineOrder(1);
887 print("Set polyline outline order to 1: $outlineOrderSuccess");
888 // [dart_PolylineMapObject_setOutlineOrder]
889
890 // [dart_PolylineMapObject_setOutlineCapType]
891 // Set outline cap type
892 bool outlineCapSuccess = _polylineMapObject!.setOutlineCapType(
893 CapType.ROUND,
894 );
895 print("Set polyline outline cap type to ROUND: $outlineCapSuccess");
896 // [dart_PolylineMapObject_setOutlineCapType]
897
898 // [dart_PolylineMapObject_setOutlineJoinType]
899 // Set outline join type
900 bool outlineJoinSuccess = _polylineMapObject!.setOutlineJoinType(
901 JoinType.ROUND,
902 );
903 print("Set polyline outline join type to ROUND: $outlineJoinSuccess");
904 // [dart_PolylineMapObject_setOutlineJoinType]
905
906 // [dart_PolylineMapObject_setOutlineMiterLimit]
907 // Set outline miter limit
908 bool outlineMiterSuccess = _polylineMapObject!.setOutlineMiterLimit(3.0);
909 print("Set polyline outline miter limit to 3.0: $outlineMiterSuccess");
910 // [dart_PolylineMapObject_setOutlineMiterLimit]
911
912 // [dart_PolylineMapObject_setVisible]
913 // Set visibility
914 bool visibleSuccess = _polylineMapObject!.setVisible(true);
915 print("Set polyline visibility to true: $visibleSuccess");
916 // [dart_PolylineMapObject_setVisible]
917
918 // [dart_PolylineMapObject_getMapObjectType]
919 // Get map object type
920 MapObjectType objectType = _polylineMapObject!.mapObjectType;
921 print("Polyline map object type: $objectType");
922 // [dart_PolylineMapObject_getMapObjectType]
923
924 // [dart_MapObject_setAlpha_3]
925 // Set alpha transparency
926 bool alphaSuccess = _polylineMapObject!.setAlpha(0.7);
927 print("Set polyline alpha to 0.7: $alphaSuccess");
928 // [dart_MapObject_setAlpha_3]
929
930 // [dart_MapObject_setInteractive_3]
931 // Set interactive mode
932 bool interactiveSuccess = _polylineMapObject!.setInteractive(true);
933 print("Set polyline interactive to true: $interactiveSuccess");
934 // [dart_MapObject_setInteractive_3]
935
936 // [dart_MapObject_setTitle_3]
937 // Set title
938 bool titleSuccess = _polylineMapObject!.setTitle("Polyline Object");
939 print("Set polyline title to 'Polyline Object': $titleSuccess");
940 // [dart_MapObject_setTitle_3]
941
942 // [dart_MapObject_setData_3]
943 // Set custom data
944 Map<String, dynamic> customData = {"key": "value", "number": 42};
945 bool dataSuccess = _polylineMapObject!.setData(customData);
946 print("Set polyline custom data: $dataSuccess");
947 // [dart_MapObject_setData_3]
948
949 // [dart_MapObject_getId_3]
950 // Get object ID
951 int objectId = _polylineMapObject!.id;
952 print("Polyline object ID: $objectId");
953 // [dart_MapObject_getId_3]
954
955 // [dart_MapObject_getType_3]
956 // Get object type
957 String objectTypeString = _polylineMapObject!.type;
958 print("Polyline object type: $objectTypeString");
959 // [dart_MapObject_getType_3]
960
961 // [dart_MapObject_getData_3]
962 // Get custom data
963 Map<String, dynamic> retrievedData = _polylineMapObject!.data;
964 print("Polyline custom data: $retrievedData");
965 // [dart_MapObject_getData_3]
966 }
967
968 // [dart_LocationWindow_removePolylineMapObject]
969 // Remove polyline map object
970 if (_polylineMapObject != null) {
971 bool removed = _locationWindow!.removePolylineMapObject(
973 );
974 print("Removed polyline map object: $removed");
975 _polylineMapObject = null;
976 }
977 // [dart_LocationWindow_removePolylineMapObject]
978
979 // Test multiple polyline objects
980 List<PolylineMapObject> polylines = [];
981 for (int i = 0; i < 3; i++) {
982 PolylineMapObject polyline = _locationWindow!.addPolylineMapObject();
983 if (polyline != null) {
984 List<Point> points = [
985 Point(i * 30.0, i * 30.0),
986 Point((i + 1) * 30.0, (i + 1) * 30.0),
987 ];
988 Polyline poly = Polyline(points);
989 LocationPolyline locPoly = LocationPolyline(poly, 1, 0);
990 polyline.setPolyLine(locPoly);
991 polyline.setWidth(2.0 + i);
992 polyline.setColor(0.0, 1.0, 1.0, 0.8);
993 polylines.add(polyline);
994 print("Created polyline $i with width ${2.0 + i}");
995 }
996 }
997
998 for (int i = 0; i < polylines.length; i++) {
999 _locationWindow!.removePolylineMapObject(polylines[i]);
1000 print("Removed polyline $i");
1001 }
1002 }
1003
1007 void _demonstrateDottedPolylineMapObjects() {
1008 print("--- Dotted Polyline Map Objects ---");
1009
1010 if (_locationWindow == null) {
1011 print("LocationWindow not available yet");
1012 return;
1013 }
1014
1015 // [dart_DottedPolylineMapObject_constructor]
1016 // Create dotted polyline map object
1017 List<Point> points = [
1018 Point(160.0, 170.0),
1019 Point(165.0, 175.0),
1020 Point(170.0, 180.0),
1021 Point(175.0, 185.0),
1022 ];
1023 Polyline polyline = Polyline(points);
1024 LocationPolyline locationPolyline = LocationPolyline(polyline, 1, 0);
1025 _dottedPolylineMapObject = _locationWindow!.addDottedPolylineMapObject();
1026 print("Created dotted polyline map object with ${points.length} points");
1027 // [dart_DottedPolylineMapObject_constructor]
1028
1029 // [dart_DottedPolylineMapObject_getPolyline]
1030 // Access dotted polyline
1031 LocationPolyline dottedPolylineShape =
1032 _dottedPolylineMapObject!.getPolyLine();
1033 print(
1034 "Dotted polyline has ${dottedPolylineShape.polyline.points.length} points",
1035 );
1036 // [dart_DottedPolylineMapObject_getPolyline]
1037
1038 // [dart_LocationWindow_addDottedPolylineMapObject]
1039 // Add dotted polyline map object
1040 _dottedPolylineMapObject = _locationWindow!.addDottedPolylineMapObject();
1041 print("Added dotted polyline map object");
1042 // [dart_LocationWindow_addDottedPolylineMapObject]
1043
1044 if (_dottedPolylineMapObject != null) {
1045 // [dart_DottedPolylineMapObject_setPolyline]
1046 // Set dotted polyline geometry
1047 List<Point> dottedPoints = [
1048 Point(0.0, 100.0),
1049 Point(50.0, 150.0),
1050 Point(100.0, 100.0),
1051 Point(150.0, 150.0),
1052 ];
1053 Polyline dottedPolyline = Polyline(dottedPoints);
1054 LocationPolyline locationDottedPolyline = LocationPolyline(
1055 dottedPolyline,
1056 1,
1057 0,
1058 );
1059 bool success = _dottedPolylineMapObject!.setPolyLine(
1060 locationDottedPolyline,
1061 );
1062 print("Set dotted polyline geometry: $success");
1063 // [dart_DottedPolylineMapObject_setPolyline]
1064
1065 // [dart_DottedPolylineMapObject_setWidth]
1066 // Set dotted polyline width
1067 bool widthSuccess = _dottedPolylineMapObject!.setWidth(2.0);
1068 print("Set dotted polyline width to 2.0 pixels: $widthSuccess");
1069 // [dart_DottedPolylineMapObject_setWidth]
1070
1071 // [dart_DottedPolylineMapObject_setColor]
1072 // Set dotted polyline color
1073 bool colorSuccess = _dottedPolylineMapObject!.setColor(
1074 0.5,
1075 0.0,
1076 1.0,
1077 0.8,
1078 );
1079 print(
1080 "Set dotted polyline color to purple with 80% opacity: $colorSuccess",
1081 );
1082 // [dart_DottedPolylineMapObject_setColor]
1083
1084 // [dart_DottedPolylineMapObject_setOrder]
1085 // Set rendering order
1086 bool orderSuccess = _dottedPolylineMapObject!.setOrder(3);
1087 print("Set rendering order to 3: $orderSuccess");
1088 // [dart_DottedPolylineMapObject_setOrder]
1089
1090 // [dart_DottedPolylineMapObject_setCollisionEnabled]
1091 // Enable collision detection
1092 bool collisionSuccess = _dottedPolylineMapObject!.setCollisionEnabled(
1093 true,
1094 );
1095 print(
1096 "Enabled collision detection for dotted polyline: $collisionSuccess",
1097 );
1098 // [dart_DottedPolylineMapObject_setCollisionEnabled]
1099
1100 // [dart_DottedPolylineMapObject_setPlacement]
1101 // Set placement type
1102 bool placementSuccess = _dottedPolylineMapObject!.setPlacement(
1103 Placement.center,
1104 );
1105 print("Set dotted polyline placement to center: $placementSuccess");
1106 // [dart_DottedPolylineMapObject_setPlacement]
1107
1108 // [dart_DottedPolylineMapObject_setPlacementMinRatio]
1109 // Set placement min ratio
1110 bool minRatioSuccess = _dottedPolylineMapObject!.setPlacementMinRatio(
1111 0.5,
1112 );
1113 print("Set dotted polyline placement min ratio to 0.5: $minRatioSuccess");
1114 // [dart_DottedPolylineMapObject_setPlacementMinRatio]
1115
1116 // [dart_DottedPolylineMapObject_setPlacementSpacing]
1117 // Set placement spacing
1118 bool spacingSuccess = _dottedPolylineMapObject!.setPlacementSpacing(10.0);
1119 print("Set dotted polyline placement spacing to 10.0: $spacingSuccess");
1120 // [dart_DottedPolylineMapObject_setPlacementSpacing]
1121
1122 // [dart_DottedPolylineMapObject_setPriority]
1123 // Set rendering priority
1124 bool prioritySuccess = _dottedPolylineMapObject!.setPriority(1);
1125 print("Set dotted polyline rendering priority to 1: $prioritySuccess");
1126 // [dart_DottedPolylineMapObject_setPriority]
1127
1128 // [dart_DottedPolylineMapObject_setRepeatDistance]
1129 // Set repeat distance
1130 bool repeatDistanceSuccess = _dottedPolylineMapObject!.setRepeatDistance(
1131 20.0,
1132 );
1133 print(
1134 "Set dotted polyline repeat distance to 20.0: $repeatDistanceSuccess",
1135 );
1136 // [dart_DottedPolylineMapObject_setRepeatDistance]
1137
1138 // [dart_DottedPolylineMapObject_setRepeatGroup]
1139 // Set repeat group
1140 bool repeatGroupSuccess = _dottedPolylineMapObject!.setRepeatGroup(1);
1141 print("Set dotted polyline repeat group to 1: $repeatGroupSuccess");
1142 // [dart_DottedPolylineMapObject_setRepeatGroup]
1143
1144 // [dart_DottedPolylineMapObject_setSize]
1145 // Set size
1146 bool sizeSuccess = _dottedPolylineMapObject!.setSize(16.0, 16.0);
1147 print("Set dotted polyline size to 16x16: $sizeSuccess");
1148 // [dart_DottedPolylineMapObject_setSize]
1149
1150 // [dart_DottedPolylineMapObject_setVisible]
1151 // Set visibility
1152 bool visibleSuccess = _dottedPolylineMapObject!.setVisible(true);
1153 print("Set dotted polyline visibility to true: $visibleSuccess");
1154 // [dart_DottedPolylineMapObject_setVisible]
1155
1156 // [dart_DottedPolylineMapObject_getMapObjectType]
1157 // Get map object type
1158 MapObjectType objectType = _dottedPolylineMapObject!.mapObjectType;
1159 print("Dotted polyline map object type: $objectType");
1160 // [dart_DottedPolylineMapObject_getMapObjectType]
1161
1162 // [dart_MapObject_setAlpha_4]
1163 // Set alpha transparency
1164 bool alphaSuccess = _dottedPolylineMapObject!.setAlpha(0.7);
1165 print("Set dotted polyline alpha to 0.7: $alphaSuccess");
1166 // [dart_MapObject_setAlpha_4]
1167
1168 // [dart_MapObject_setInteractive_4]
1169 // Set interactive mode
1170 bool interactiveSuccess = _dottedPolylineMapObject!.setInteractive(true);
1171 print("Set dotted polyline interactive to true: $interactiveSuccess");
1172 // [dart_MapObject_setInteractive_4]
1173
1174 // [dart_MapObject_setTitle_4]
1175 // Set title
1176 bool titleSuccess = _dottedPolylineMapObject!.setTitle(
1177 "Dotted Polyline Object",
1178 );
1179 print(
1180 "Set dotted polyline title to 'Dotted Polyline Object': $titleSuccess",
1181 );
1182 // [dart_MapObject_setTitle_4]
1183
1184 // [dart_MapObject_setData_4]
1185 // Set custom data
1186 Map<String, dynamic> customData = {"key": "value", "number": 42};
1187 bool dataSuccess = _dottedPolylineMapObject!.setData(customData);
1188 print("Set dotted polyline custom data: $dataSuccess");
1189 // [dart_MapObject_setData_4]
1190
1191 // [dart_MapObject_getId_4]
1192 // Get object ID
1193 int objectId = _dottedPolylineMapObject!.id;
1194 print("Dotted polyline object ID: $objectId");
1195 // [dart_MapObject_getId_4]
1196
1197 // [dart_MapObject_getType_4]
1198 // Get object type
1199 String objectTypeString = _dottedPolylineMapObject!.type;
1200 print("Dotted polyline object type: $objectTypeString");
1201 // [dart_MapObject_getType_4]
1202
1203 // [dart_MapObject_getData_4]
1204 // Get custom data
1205 Map<String, dynamic> retrievedData = _dottedPolylineMapObject!.data;
1206 print("Dotted polyline custom data: $retrievedData");
1207 // [dart_MapObject_getData_4]
1208 }
1209
1210 // [dart_LocationWindow_removeDottedPolylineMapObject]
1211 // Remove dotted polyline map object
1212 if (_dottedPolylineMapObject != null) {
1213 bool removed = _locationWindow!.removeDottedPolylineMapObject(
1215 );
1216 print("Removed dotted polyline map object: $removed");
1218 }
1219 // [dart_LocationWindow_removeDottedPolylineMapObject]
1220
1221 // Test multiple dotted polyline objects
1222 List<DottedPolylineMapObject> dottedPolylines = [];
1223 for (int i = 0; i < 2; i++) {
1224 DottedPolylineMapObject dottedPolyline =
1225 _locationWindow!.addDottedPolylineMapObject();
1226 if (dottedPolyline != null) {
1227 List<Point> points = [
1228 Point(i * 40.0, i * 40.0 + 100.0),
1229 Point((i + 1) * 40.0, (i + 1) * 40.0 + 100.0),
1230 ];
1231 Polyline poly = Polyline(points);
1232 LocationPolyline locPoly = LocationPolyline(poly, 1, 0);
1233 dottedPolyline.setPolyLine(locPoly);
1234 dottedPolyline.setWidth(1.5);
1235 dottedPolyline.setColor(1.0, 0.0, 1.0, 0.6);
1236 dottedPolylines.add(dottedPolyline);
1237 print("Created dotted polyline $i");
1238 }
1239 }
1240
1241 for (int i = 0; i < dottedPolylines.length; i++) {
1242 _locationWindow!.removeDottedPolylineMapObject(dottedPolylines[i]);
1243 print("Removed dotted polyline $i");
1244 }
1245 }
1246
1250 void _demonstrateClusterMapObjects() {
1251 print("--- Cluster map objects ---");
1252
1253 if (_locationWindow == null) {
1254 print("LocationWindow not available");
1255 return;
1256 }
1257
1258 // [dart_LocationWindow_addClusterMapObjectController]
1259 _clusterMapObjectController = _locationWindow!.addClusterMapObjectController();
1260 print("Added cluster map object controller");
1261 // [dart_LocationWindow_addClusterMapObjectController]
1262
1263 final controller = _clusterMapObjectController;
1264 if (controller == null) {
1265 return;
1266 }
1267
1268 final clusterIcon1 = _locationWindow!.addIconMapObject();
1269 final clusterIcon2 = _locationWindow!.addIconMapObject();
1270 clusterIcon1?.setPosition(LocationPoint(100.0, 100.0));
1271 clusterIcon2?.setPosition(LocationPoint(105.0, 102.0));
1272
1273 // [dart_ClusterMapObjectController_addIconMapObject]
1274 final added1 = controller.addIconMapObject(clusterIcon1);
1275 final added2 = controller.addIconMapObject(clusterIcon2);
1276 print("Registered icons for clustering: $added1, $added2");
1277 // [dart_ClusterMapObjectController_addIconMapObject]
1278
1279 // [dart_ClusterMapObjectController_setEnabled]
1280 controller.setEnabled(true);
1281 print("Clustering enabled");
1282 // [dart_ClusterMapObjectController_setEnabled]
1283
1284 // [dart_ClusterMapObjectController_isEnabled]
1285 final clusteringEnabled = controller.isEnabled;
1286 print("Clustering is enabled: $clusteringEnabled");
1287 // [dart_ClusterMapObjectController_isEnabled]
1288
1289 // [dart_ClusterMapObjectController_setRadius]
1290 controller.setRadius(40.0);
1291 print("Set cluster radius to 40 px");
1292 // [dart_ClusterMapObjectController_setRadius]
1293
1294 // [dart_ClusterMapObjectController_getRadius]
1295 final clusterRadius = controller.getRadius();
1296 print("Cluster radius: $clusterRadius");
1297 // [dart_ClusterMapObjectController_getRadius]
1298
1299 // [dart_ClusterMapObjectController_setInteractive]
1300 final interactiveSuccess = controller.setInteractive(true);
1301 print("Set cluster markers interactive: $interactiveSuccess");
1302 // [dart_ClusterMapObjectController_setInteractive]
1303
1304 // [dart_ClusterMapObjectController_setClusterSize]
1305 final sizeSuccess = controller.setClusterSize(32.0, 32.0);
1306 print("Set default cluster icon size: $sizeSuccess");
1307 // [dart_ClusterMapObjectController_setClusterSize]
1308
1309 _clusterMapObjectControllerListener = DemoClusterMapObjectControllerListener();
1310
1311 // [dart_ClusterMapObjectController_addListener]
1312 controller.addListener(_clusterMapObjectControllerListener!);
1313 print("Added cluster map object listener");
1314 // [dart_ClusterMapObjectController_addListener]
1315
1316 // [dart_ClusterMapObjectController_getClusters]
1317 final clusters = controller.getClusters();
1318 print("Visible clusters: ${clusters.length}");
1319 // [dart_ClusterMapObjectController_getClusters]
1320
1321 if (clusters.isNotEmpty) {
1322 final cluster = clusters.first;
1323 // [dart_ClusterMapObject_setBitmap]
1324 final clusterBitmap = ImageProvider.fromFile("/path/to/cluster.png");
1325 final bitmapSuccess = cluster.setBitmap(clusterBitmap);
1326 print("Set cluster bitmap from ImageProvider: $bitmapSuccess");
1327 // [dart_ClusterMapObject_setBitmap]
1328 }
1329
1330 // [dart_ClusterMapObjectController_removeListener]
1331 controller.removeListener(_clusterMapObjectControllerListener!);
1332 print("Removed cluster map object listener");
1333 // [dart_ClusterMapObjectController_removeListener]
1334
1335 if (clusterIcon1 != null) {
1336 // [dart_ClusterMapObjectController_removeIconMapObject]
1337 final removed = controller.removeIconMapObject(clusterIcon1);
1338 print("Removed icon from cluster controller: $removed");
1339 // [dart_ClusterMapObjectController_removeIconMapObject]
1340 _locationWindow!.removeIconMapObject(clusterIcon1);
1341 }
1342 if (clusterIcon2 != null) {
1343 _locationWindow!.removeIconMapObject(clusterIcon2);
1344 }
1345
1346 // [dart_ClusterMapObjectController_clear]
1347 controller.clear();
1348 print("Cleared cluster controller");
1349 // [dart_ClusterMapObjectController_clear]
1350
1351 // [dart_LocationWindow_removeClusterMapObjectController]
1352 final controllerRemoved =
1353 _locationWindow!.removeClusterMapObjectController(controller);
1354 print("Removed cluster map object controller: $controllerRemoved");
1355 // [dart_LocationWindow_removeClusterMapObjectController]
1356
1359 }
1360
1361 void _demonstrateRemoveAllMapObjects() {
1362 print("--- Remove All Map Objects ---");
1363
1364 if (_locationWindow == null) {
1365 print("LocationWindow not available yet");
1366 return;
1367 }
1368
1369 // Create various map objects
1370 CircleMapObject circle = _locationWindow!.addCircleMapObject();
1371 IconMapObject icon = _locationWindow!.addIconMapObject();
1372 PolygonMapObject polygon = _locationWindow!.addPolygonMapObject();
1373 PolylineMapObject polyline = _locationWindow!.addPolylineMapObject();
1374 DottedPolylineMapObject dottedPolyline =
1375 _locationWindow!.addDottedPolylineMapObject();
1376
1377 print("Created 5 map objects");
1378
1379 // [dart_LocationWindow_removeAllMapObjects]
1380 // Remove all map objects
1381 _locationWindow!.removeAllMapObjects();
1382 print("Removed all map objects");
1383 // [dart_LocationWindow_removeAllMapObjects]
1384 }
1385
1389 void _cleanup() {
1390 if (_circleMapObject != null) {
1391 _locationWindow?.removeCircleMapObject(_circleMapObject!);
1392 _circleMapObject = null;
1393 }
1394 if (_iconMapObject != null) {
1395 _locationWindow?.removeIconMapObject(_iconMapObject!);
1396 _iconMapObject = null;
1397 }
1398 if (_polygonMapObject != null) {
1399 // Polygon objects are removed automatically when LocationWindow is destroyed
1400 _polygonMapObject = null;
1401 }
1402 if (_polylineMapObject != null) {
1403 _locationWindow?.removePolylineMapObject(_polylineMapObject!);
1404 _polylineMapObject = null;
1405 }
1406 if (_dottedPolylineMapObject != null) {
1407 _locationWindow?.removeDottedPolylineMapObject(_dottedPolylineMapObject!);
1409 }
1410 if (_modelMapObject != null) {
1411 _locationWindow?.removeModelMapObject(_modelMapObject!);
1412 _modelMapObject = null;
1413 }
1414 print("LocationWindowMapObjects example cleanup completed");
1415 }
1416}
1417
1418class DemoClusterMapObjectControllerListener implements ClusterMapObjectControllerListener {
1419 final DemoClusterMapObjectListener _clusterChangeListener = DemoClusterMapObjectListener();
1420 ClusterMapObject? _activeCluster;
1421
1422 // [dart_ClusterMapObjectControllerListener_onClusterCreated]
1423 @override
1424 void onClusterCreated(ClusterMapObjectController controller, ClusterMapObject cluster) {
1425 // [dart_ClusterMapObject_addListener]
1426 cluster.addListener(_clusterChangeListener);
1427 print('Added cluster change listener, initial count: ${cluster.count}');
1428 // [dart_ClusterMapObject_addListener]
1429 _activeCluster = cluster;
1430 }
1431 // [dart_ClusterMapObjectControllerListener_onClusterCreated]
1432
1433 // [dart_ClusterMapObjectControllerListener_onClusterDestroyed]
1434 @override
1435 void onClusterDestroyed(ClusterMapObjectController controller, int clusterId) {
1436 final cluster = _activeCluster;
1437 if (cluster != null && cluster.id == clusterId) {
1438 // [dart_ClusterMapObject_removeListener]
1439 cluster.removeListener(_clusterChangeListener);
1440 print('Removed cluster change listener');
1441 // [dart_ClusterMapObject_removeListener]
1442 _activeCluster = null;
1443 }
1444 print('Cluster destroyed, id: $clusterId');
1445 }
1446 // [dart_ClusterMapObjectControllerListener_onClusterDestroyed]
1447}
1448
1449class DemoClusterMapObjectListener implements ClusterMapObjectListener {
1450 // [dart_ClusterMapObjectListener_onClusterChanged]
1451 @override
1452 void onClusterChanged(ClusterMapObject cluster) {
1453 final memberCount = cluster.getCount();
1454 print("Cluster changed, member count: $memberCount");
1455 }
1456 // [dart_ClusterMapObjectListener_onClusterChanged]
1457}
1458
1459// Main function