50class LocationWindowMapObjectsExample {
61 LocationWindowMapObjectsExample() {
62 _demonstrateLocationWindowMapObjectsMethods();
68 void _demonstrateLocationWindowMapObjectsMethods() {
69 print(
"=== LocationWindowMapObjects Example ===");
71 _demonstrateLocationScopedGeometryRecords();
73 _demonstrateCircleMapObjects();
74 _demonstrateIconMapObjects();
75 _demonstrateClusterMapObjects();
76 _demonstrateModelMapObjects();
77 _demonstratePolygonMapObjects();
78 _demonstratePolylineMapObjects();
79 _demonstrateDottedPolylineMapObjects();
80 _demonstrateRemoveAllMapObjects();
87 void _demonstrateLocationScopedGeometryRecords() {
88 print(
"--- LocationPolygon / LocationPolyline records ---");
91 List<GlobalPoint> ring = [
92 GlobalPoint(55.751, 37.617),
93 GlobalPoint(55.752, 37.618),
94 GlobalPoint(55.751, 37.619),
96 List<List<GlobalPoint>> holes = [
98 GlobalPoint(55.7512, 37.6174),
99 GlobalPoint(55.7514, 37.6176),
100 GlobalPoint(55.7512, 37.6178),
103 LocationPolygon locationPolygon = LocationPolygon(ring, 7, holes);
105 "LocationPolygon: sublocation ${locationPolygon.sublocationId}, vertices ${locationPolygon.points.length}, holes ${locationPolygon.innerRings.length}",
112 PointSprite(GlobalPoint(55.751, 37.617), 0, Color(0xCCFF8000), 5),
113 PointSprite(GlobalPoint(55.752, 37.618), 90, Color(0xCC0080FF), 5),
115 int? hit = batch.
hitTest(math.Point<
double>(12, 8), 8);
116 print(
"PointBatch hit $hit");
120 String 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]]}}]}';
122 print(
"GeoJSON polygons ${imported.polygons.length}, lines ${imported.polylines.length}");
126 List<GlobalPoint> linePts = [
127 GlobalPoint(55.751, 37.617),
128 GlobalPoint(55.753, 37.620),
130 LocationPolyline locationPolyline = LocationPolyline(linePts, 7);
131 print(
"LocationPolyline points ${locationPolyline.points.length}");
138 void _demonstrateCircleMapObjects() {
139 print(
"--- Circle Map Objects ---");
142 print(
"LocationWindow not available yet");
148 GlobalPoint center = GlobalPoint(10.0, 20.0);
151 "Created circle map object with center (${center.latitude}, ${center.longitude}) and radius 5.0",
158 print(
"Circle radius: $radius");
164 print(
"Added circle map object");
170 GlobalPoint centerPoint = GlobalPoint(100.0, 200.0);
173 "Set circle position to (${centerPoint.latitude}, ${centerPoint.longitude}): $success",
179 GlobalPoint animatedPoint = GlobalPoint(150.0, 250.0);
180 bool animatedSuccess =
_circleMapObject!.setPositionAnimated(animatedPoint, 7, 2.0, AnimationType.LINEAR, );
182 "Set circle position with animation to (${animatedPoint.latitude}, ${animatedPoint.longitude}): $animatedSuccess",
189 print(
"Set position offset to (2.0, 3.0) pixels: $offsetSuccess");
194 bool outlineColorSuccess =
_circleMapObject!.setOutlineColor(
const Color(0xFF0000FF));
195 print(
"Set circle outline color to blue: $outlineColorSuccess");
201 print(
"Set circle outline alpha to 0.5: $outlineAlphaSuccess");
207 print(
"Set circle outline radius to 2.0: $outlineRadiusSuccess");
213 print(
"Set circle color to red with 80% opacity: $colorSuccess");
219 print(
"Set circle radius to 10.0 meters: $radiusSuccess");
225 print(
"Enabled collision detection for circle: $collisionSuccess");
231 print(
"Set collision buffer to 5x5 pixels: $bufferSuccess");
237 print(
"Set rendering priority to 1: $prioritySuccess");
243 print(
"Set circle visibility to true: $visibleSuccess");
249 print(
"Circle map object type: $objectType");
255 print(
"Set circle alpha to 0.7: $alphaSuccess");
261 print(
"Set circle interactive to true: $interactiveSuccess");
267 print(
"Set circle title to 'Circle Object': $titleSuccess");
271 TitleStyle titleStyle = TitleStyle(
274 outlineColor:
"#FFFFFF",
275 anchor: TitleAnchor.TOP,
282 bool titleStyleSuccess =
284 print(
"Set circle title with style: $titleStyleSuccess");
289 Map<String, dynamic> customData = {
"key":
"value",
"number": 42};
291 print(
"Set circle custom data: $dataSuccess");
297 print(
"Circle object ID: $objectId");
303 print(
"Circle object type: $objectTypeString");
309 print(
"Circle custom data: $retrievedData");
317 print(
"Removed circle map object: $removed");
323 List<CircleMapObject> circles = [];
324 for (
int i = 0; i < 3; i++) {
326 if (circle !=
null) {
327 circle.
setPosition(GlobalPoint(50.0 * i, 100.0 * i));
328 circle.
setColor(
const Color(0x9900FF00));
332 "Created circle $i at (${50.0 * i}, ${100.0 * i}) with radius ${5.0 + i * 2.0}",
337 for (
int i = 0; i < circles.length; i++) {
339 print(
"Removed circle $i");
346 void _demonstrateIconMapObjects() {
347 print(
"--- Icon Map Objects ---");
350 print(
"LocationWindow not available yet");
356 GlobalPoint position = GlobalPoint(30.0, 40.0);
358 print(
"Created icon map object at (${position.latitude}, ${position.longitude})");
364 print(
"Added icon map object");
370 GlobalPoint iconPoint = GlobalPoint(200.0, 300.0);
372 print(
"Set icon position to (${iconPoint.latitude}, ${iconPoint.longitude}): $success");
377 GlobalPoint animatedIconPoint = GlobalPoint(250.0, 350.0);
378 bool animatedSuccess =
_iconMapObject!.setPositionAnimated(animatedIconPoint, 7, 1.5, AnimationType.CUBIC, );
380 "Set icon position with animation to (${animatedIconPoint.latitude}, ${animatedIconPoint.longitude}): $animatedSuccess",
387 print(
"Set icon size to 32x32 pixels: $sizeSuccess");
393 print(
"Set icon rotation angle to π/4: $angleSuccess");
404 "Set icon rotation with animation to π/2: $angleAnimatedSuccess",
410 bool collisionSuccess =
_iconMapObject!.setCollisionEnabled(
true);
411 print(
"Enabled collision detection for icon: $collisionSuccess");
417 print(
"Set collision buffer to 10x10 pixels: $bufferSuccess");
423 print(
"Set position offset to (0.0, -16.0) pixels: $offsetSuccess");
429 print(
"Set rendering priority to 2: $prioritySuccess");
435 print(
"Set icon visibility to true: $visibleSuccess");
441 print(
"Icon map object type: $objectType");
446 ImageProvider iconProvider = ImageProvider.fromImageProvider(
447 const AssetImage(
'assets/icon.png'),
451 print(
"Set icon from ImageProvider: $bitmapSuccess");
457 print(
"Set icon flat mode to true: $flatSuccess");
463 print(
"Set icon alpha to 0.7: $alphaSuccess");
469 print(
"Set icon interactive to true: $interactiveSuccess");
475 print(
"Set icon title to 'Icon Object': $titleSuccess");
480 Map<String, dynamic> customData = {
"key":
"value",
"number": 42};
482 print(
"Set icon custom data: $dataSuccess");
488 print(
"Icon object ID: $objectId");
494 print(
"Icon object type: $objectTypeString");
500 print(
"Icon custom data: $retrievedData");
508 print(
"Removed icon map object: $removed");
514 List<IconMapObject> icons = [];
515 ImageProvider loopIcon = ImageProvider.fromImageProvider(
516 const AssetImage(
'assets/icon.png'),
519 for (
int i = 0; i < 3; i++) {
522 icon.
setPosition(GlobalPoint(100.0 * i, 150.0 * i));
528 "Created icon $i at (${100.0 * i}, ${150.0 * i}) with angle ${i * math.pi / 6}",
533 for (
int i = 0; i < icons.length; i++) {
535 print(
"Removed icon $i");
542 void _demonstrateModelMapObjects() {
543 print(
"--- Model Map Objects ---");
546 print(
"LocationWindow not available yet");
552 print(
"Added model map object: ${_modelMapObject != null}");
561 bool posOk = m.
setPosition(GlobalPoint(12.0, 34.0));
562 print(
"Model setPosition: $posOk");
568 print(
"Model setPositionAnimated: $posAnimOk");
572 ImageProvider texture = ImageProvider.fromImageProvider(
573 const AssetImage(
'assets/model_texture.png'),
576 ModelProvider modelProvider = ModelProvider(
578 onModelRequest: () async {
579 final bytes = await File(
'/path/to/model.obj').readAsBytes();
580 return ByteData.sublistView(bytes);
583 bool modelOk = m.
setModel(modelProvider);
584 print(
"Model setModel: $modelOk");
588 bool sizeOk = m.
setSize(64.0, 64.0);
589 print(
"Model setSize: $sizeOk");
594 print(
"Model setCollisionEnabled: $collOk");
598 bool angleOk = m.
setAngle(math.pi / 4);
599 print(
"Model setAngle: $angleOk");
603 bool angleAnimOk = m.
setAngleAnimated(math.pi / 2, 0.5, AnimationType.QUINT);
604 print(
"Model setAngleAnimated: $angleAnimOk");
609 print(
"Model setBuffer: $bufOk");
614 print(
"Model setPriority: $priOk");
619 print(
"Removed model map object: $removed");
627 void _demonstratePolygonMapObjects() {
628 print(
"--- Polygon Map Objects ---");
631 print(
"LocationWindow not available yet");
638 print(
"Added polygon map object");
644 List<GlobalPoint> points = [
645 GlobalPoint(100.0, 200.0),
646 GlobalPoint(150.0, 250.0),
647 GlobalPoint(200.0, 200.0),
648 GlobalPoint(150.0, 150.0),
650 LocationPolygon polygon = LocationPolygon(points, 0, []);
652 print(
"Set polygon with ${points.length} points: $success");
658 print(
"Set polygon color to green with 70% opacity: $colorSuccess");
663 bool outlineColorSuccess =
_polygonMapObject!.setOutlineColor(
const Color(0xFF0000FF));
664 print(
"Set polygon outline color to blue: $outlineColorSuccess");
670 print(
"Set polygon outline width to 2.0 pixels: $outlineWidthSuccess");
676 print(
"Set polygon outline alpha to 0.8: $outlineAlphaSuccess");
682 print(
"Set polygon outline order to 1: $outlineOrderSuccess");
688 print(
"Set polygon rendering order to 2: $orderSuccess");
694 print(
"Set polygon visibility to true: $visibleSuccess");
700 print(
"Polygon map object type: $objectType");
706 print(
"Set polygon alpha to 0.7: $alphaSuccess");
712 print(
"Set polygon interactive to true: $interactiveSuccess");
718 print(
"Set polygon title to 'Polygon Object': $titleSuccess");
723 Map<String, dynamic> customData = {
"key":
"value",
"number": 42};
725 print(
"Set polygon custom data: $dataSuccess");
731 print(
"Polygon object ID: $objectId");
737 print(
"Polygon object type: $objectTypeString");
743 print(
"Polygon custom data: $retrievedData");
753 print(
"Removed polygon map object: $removed");
759 List<PolygonMapObject> polygons = [];
760 for (
int i = 0; i < 3; i++) {
762 if (polygon !=
null) {
763 List<GlobalPoint> points = [
764 GlobalPoint(300.0 + i * 50, 400.0 + i * 50),
765 GlobalPoint(350.0 + i * 50, 450.0 + i * 50),
766 GlobalPoint(400.0 + i * 50, 400.0 + i * 50),
767 GlobalPoint(350.0 + i * 50, 350.0 + i * 50),
769 LocationPolygon polygonGeometry = LocationPolygon(points, 0, []);
771 polygon.
setColor(
const Color(0x800000FF));
772 polygons.add(polygon);
773 print(
"Created polygon $i with ${points.length} points");
777 for (
int i = 0; i < polygons.length; i++) {
779 print(
"Removed polygon $i");
786 void _demonstratePolylineMapObjects() {
787 print(
"--- Polyline Map Objects ---");
790 print(
"LocationWindow not available yet");
796 List<GlobalPoint> points = [
797 GlobalPoint(100.0, 110.0),
798 GlobalPoint(105.0, 115.0),
799 GlobalPoint(110.0, 120.0),
800 GlobalPoint(115.0, 125.0),
802 LocationPolyline locationPolyline = LocationPolyline(points, 0);
804 print(
"Created polyline map object with ${points.length} points");
810 print(
"Polyline has ${polylineShape.polyline.points.length} points");
816 print(
"Added polyline map object");
822 List<GlobalPoint> polylinePoints = [
823 GlobalPoint(0.0, 0.0),
824 GlobalPoint(50.0, 50.0),
825 GlobalPoint(100.0, 0.0),
826 GlobalPoint(150.0, 50.0),
828 LocationPolyline locationPolyline = LocationPolyline(polylinePoints, 0);
830 print(
"Set polyline geometry: $success");
838 bool grew =
_polylineMapObject!.setDrawnFractionAnimated(1, 1.0, AnimationType.LINEAR);
839 print(
"Polyline grow started: $grew");
843 print(
"Drawn fraction: ${_polylineMapObject!.drawnFraction()}");
849 print(
"Set polyline width to 3.0 pixels: $widthSuccess");
855 print(
"Set polyline color to orange with 90% opacity: $colorSuccess");
861 print(
"Set polyline dash length: $dashSuccess");
867 print(
"Polyline dash length: $dashLength");
873 print(
"Set polyline gap length: $gapSuccess");
879 print(
"Polyline gap length: $gapLength");
885 print(
"Set rendering order to 2: $orderSuccess");
891 print(
"Set cap type to ROUND: $capSuccess");
897 print(
"Set join type to ROUND: $joinSuccess");
903 print(
"Set miter limit to 5.0: $miterSuccess");
909 print(
"Set polyline outline width to 1.0: $outlineWidthSuccess");
914 bool outlineColorSuccess =
_polylineMapObject!.setOutlineColor(
const Color(0xFF000000));
915 print(
"Set polyline outline color to black: $outlineColorSuccess");
921 print(
"Set polyline outline alpha to 0.8: $outlineAlphaSuccess");
927 print(
"Set polyline outline order to 1: $outlineOrderSuccess");
935 print(
"Set polyline outline cap type to ROUND: $outlineCapSuccess");
943 print(
"Set polyline outline join type to ROUND: $outlineJoinSuccess");
949 print(
"Set polyline outline miter limit to 3.0: $outlineMiterSuccess");
955 print(
"Set polyline visibility to true: $visibleSuccess");
961 print(
"Polyline map object type: $objectType");
967 print(
"Set polyline alpha to 0.7: $alphaSuccess");
973 print(
"Set polyline interactive to true: $interactiveSuccess");
979 print(
"Set polyline title to 'Polyline Object': $titleSuccess");
984 Map<String, dynamic> customData = {
"key":
"value",
"number": 42};
986 print(
"Set polyline custom data: $dataSuccess");
992 print(
"Polyline object ID: $objectId");
998 print(
"Polyline object type: $objectTypeString");
1004 print(
"Polyline custom data: $retrievedData");
1014 print(
"Removed polyline map object: $removed");
1020 List<PolylineMapObject> polylines = [];
1021 for (
int i = 0; i < 3; i++) {
1023 if (polyline !=
null) {
1024 List<GlobalPoint> points = [
1025 GlobalPoint(i * 30.0, i * 30.0),
1026 GlobalPoint((i + 1) * 30.0, (i + 1) * 30.0),
1028 LocationPolyline locPoly = LocationPolyline(points, 0);
1031 polyline.
setColor(
const Color(0xCC00FFFF));
1032 polylines.add(polyline);
1033 print(
"Created polyline $i with width ${2.0 + i}");
1037 for (
int i = 0; i < polylines.length; i++) {
1039 print(
"Removed polyline $i");
1046 void _demonstrateDottedPolylineMapObjects() {
1047 print(
"--- Dotted Polyline Map Objects ---");
1050 print(
"LocationWindow not available yet");
1056 List<GlobalPoint> points = [
1057 GlobalPoint(160.0, 170.0),
1058 GlobalPoint(165.0, 175.0),
1059 GlobalPoint(170.0, 180.0),
1060 GlobalPoint(175.0, 185.0),
1062 LocationPolyline locationPolyline = LocationPolyline(points, 0);
1064 print(
"Created dotted polyline map object with ${points.length} points");
1069 LocationPolyline dottedPolylineShape =
1072 "Dotted polyline has ${dottedPolylineShape.polyline.points.length} points",
1079 print(
"Added dotted polyline map object");
1085 List<GlobalPoint> dottedPoints = [
1086 GlobalPoint(0.0, 100.0),
1087 GlobalPoint(50.0, 150.0),
1088 GlobalPoint(100.0, 100.0),
1089 GlobalPoint(150.0, 150.0),
1091 LocationPolyline locationDottedPolyline = LocationPolyline(dottedPoints, 0);
1093 locationDottedPolyline,
1095 print(
"Set dotted polyline geometry: $success");
1101 print(
"Set dotted polyline width to 2.0 pixels: $widthSuccess");
1108 "Set dotted polyline color to purple with 80% opacity: $colorSuccess",
1115 print(
"Set rendering order to 3: $orderSuccess");
1124 "Enabled collision detection for dotted polyline: $collisionSuccess",
1133 print(
"Set dotted polyline placement to center: $placementSuccess");
1141 print(
"Set dotted polyline placement min ratio to 0.5: $minRatioSuccess");
1147 print(
"Set dotted polyline placement spacing to 10.0: $spacingSuccess");
1153 print(
"Set dotted polyline rendering priority to 1: $prioritySuccess");
1162 "Set dotted polyline repeat distance to 20.0: $repeatDistanceSuccess",
1169 print(
"Set dotted polyline repeat group to 1: $repeatGroupSuccess");
1175 print(
"Set dotted polyline size to 16x16: $sizeSuccess");
1181 print(
"Set dotted polyline visibility to true: $visibleSuccess");
1187 print(
"Dotted polyline map object type: $objectType");
1193 print(
"Set dotted polyline alpha to 0.7: $alphaSuccess");
1199 print(
"Set dotted polyline interactive to true: $interactiveSuccess");
1205 "Dotted Polyline Object",
1208 "Set dotted polyline title to 'Dotted Polyline Object': $titleSuccess",
1214 Map<String, dynamic> customData = {
"key":
"value",
"number": 42};
1216 print(
"Set dotted polyline custom data: $dataSuccess");
1222 print(
"Dotted polyline object ID: $objectId");
1228 print(
"Dotted polyline object type: $objectTypeString");
1234 print(
"Dotted polyline custom data: $retrievedData");
1244 print(
"Removed dotted polyline map object: $removed");
1250 List<DottedPolylineMapObject> dottedPolylines = [];
1251 for (
int i = 0; i < 2; i++) {
1252 DottedPolylineMapObject dottedPolyline =
1254 if (dottedPolyline !=
null) {
1255 List<GlobalPoint> points = [
1256 GlobalPoint(i * 40.0, i * 40.0 + 100.0),
1257 GlobalPoint((i + 1) * 40.0, (i + 1) * 40.0 + 100.0),
1259 LocationPolyline locPoly = LocationPolyline(points, 0);
1261 dottedPolyline.setWidth(1.5);
1262 dottedPolyline.
setColor(
const Color(0x99FF00FF));
1263 dottedPolylines.add(dottedPolyline);
1264 print(
"Created dotted polyline $i");
1268 for (
int i = 0; i < dottedPolylines.length; i++) {
1270 print(
"Removed dotted polyline $i");
1277 void _demonstrateClusterMapObjects() {
1278 print(
"--- Cluster map objects ---");
1281 print(
"LocationWindow not available");
1287 print(
"Added cluster map object controller");
1291 if (controller ==
null) {
1297 clusterIcon1?.setPosition(GlobalPoint(100.0, 100.0));
1298 clusterIcon2?.setPosition(GlobalPoint(105.0, 102.0));
1301 final added1 = controller.addIconMapObject(clusterIcon1);
1302 final added2 = controller.addIconMapObject(clusterIcon2);
1303 print(
"Registered icons for clustering: $added1, $added2");
1307 controller.setEnabled(
true);
1308 print(
"Clustering enabled");
1312 final clusteringEnabled = controller.isEnabled;
1313 print(
"Clustering is enabled: $clusteringEnabled");
1317 controller.setRadius(40.0);
1318 print(
"Set cluster radius to 40 px");
1322 final clusterRadius = controller.getRadius();
1323 print(
"Cluster radius: $clusterRadius");
1327 final interactiveSuccess = controller.setInteractive(
true);
1328 print(
"Set cluster markers interactive: $interactiveSuccess");
1332 final sizeSuccess = controller.setClusterSize(32.0, 32.0);
1333 print(
"Set default cluster icon size: $sizeSuccess");
1340 print(
"Added cluster map object listener");
1344 final clusters = controller.getClusters();
1345 print(
"Visible clusters: ${clusters.length}");
1348 if (clusters.isNotEmpty) {
1349 final cluster = clusters.first;
1351 final clusterBitmap = ImageProvider.fromFile(
"/path/to/cluster.png");
1352 final bitmapSuccess = cluster.setBitmap(clusterBitmap);
1353 print(
"Set cluster bitmap from ImageProvider: $bitmapSuccess");
1359 print(
"Removed cluster map object listener");
1362 if (clusterIcon1 !=
null) {
1364 final removed = controller.removeIconMapObject(clusterIcon1);
1365 print(
"Removed icon from cluster controller: $removed");
1369 if (clusterIcon2 !=
null) {
1375 print(
"Cleared cluster controller");
1379 final controllerRemoved =
1381 print(
"Removed cluster map object controller: $controllerRemoved");
1388 void _demonstrateRemoveAllMapObjects() {
1389 print(
"--- Remove All Map Objects ---");
1392 print(
"LocationWindow not available yet");
1401 DottedPolylineMapObject dottedPolyline =
1404 print(
"Created 5 map objects");
1409 print(
"Removed all map objects");
1441 print(
"LocationWindowMapObjects example cleanup completed");