Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.4.0"
clock:
dependency: transitive
description:
Expand All @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.1"
dart_earcut:
dependency: transitive
description:
Expand All @@ -66,10 +66,10 @@ packages:
dependency: "direct main"
description:
name: flutter_map
sha256: ead3532d99548140346684cf737a4c0a6f59f02f62ee4e406597f8364afbf1a2
sha256: "82786b8e1ffbff079487eeeed59a34e8a0b09896dd7713d8e1dc193d673496b5"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
version: "8.0.0"
flutter_map_marker_popup:
dependency: "direct main"
description:
Expand Down Expand Up @@ -137,18 +137,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.16.0"
mgrs_dart:
dependency: transitive
description:
Expand Down Expand Up @@ -201,7 +201,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -267,5 +267,5 @@ packages:
source: hosted
version: "2.0.0"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.10.0"
dart: ">=3.7.0-0 <4.0.0"
flutter: ">=3.27.0"
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_map_marker_popup_example
description: Example for Flutter Map Marker Popups.
publish_to: 'none'
publish_to: "none"

environment:
sdk: ">=3.0.0 <4.0.0"
Expand All @@ -11,7 +11,7 @@ dependencies:
sdk: flutter

latlong2: ^0.9.0
flutter_map: ^7.0.0
flutter_map: ^8.0.0
flutter_map_marker_popup:
path: ../

Expand Down
25 changes: 13 additions & 12 deletions lib/src/layout/popup_calculations.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:math';
import 'dart:ui';

import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_marker_popup/src/popup_spec.dart';
Expand Down Expand Up @@ -58,43 +59,43 @@ abstract class PopupCalculations {

static double mapLeftToPointX(
MapCamera mapCamera,
Point<num> point,
Offset point,
) {
return point.x.toDouble();
return point.dx.toDouble();
}

static double mapRightToPointX(
MapCamera mapCamera,
Point<num> point,
Offset point,
) {
return -(mapCamera.size.x - point.x).toDouble();
return -(mapCamera.size.width - point.dx).toDouble();
}

static double mapCenterToPointX(
MapCamera mapCamera,
Point<num> point,
Offset point,
) {
return -(mapCamera.size.x / 2 - point.x).toDouble();
return -(mapCamera.size.width / 2 - point.dx).toDouble();
}

static double mapTopToPointY(
MapCamera mapCamera,
Point<num> point,
Offset point,
) {
return point.y.toDouble();
return point.dy.toDouble();
}

static double mapBottomToPointY(
MapCamera mapCamera,
Point<num> point,
Offset point,
) {
return -(mapCamera.size.y - point.y).toDouble();
return -(mapCamera.size.height - point.dy).toDouble();
}

static double mapCenterToPointY(
MapCamera mapCamera,
Point<num> point,
Offset point,
) {
return -(mapCamera.size.y / 2 - point.y).toDouble();
return -(mapCamera.size.height / 2 - point.dy).toDouble();
}
}
36 changes: 13 additions & 23 deletions lib/src/layout/popup_container_translate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ abstract class PopupContainerTransform {
final markerPoint = _markerPoint(mapCamera, popupSpec);

return Matrix4.translationValues(
PopupCalculations.mapRightToPointX(mapCamera, markerPoint) +
PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapCenterToPointY(mapCamera, markerPoint) +
PopupCalculations.centerOffsetY(popupSpec),
PopupCalculations.mapRightToPointX(mapCamera, markerPoint) + PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapCenterToPointY(mapCamera, markerPoint) + PopupCalculations.centerOffsetY(popupSpec),
0.0,
)
..rotateZ(-mapCamera.rotationRad)
Expand Down Expand Up @@ -77,10 +75,8 @@ abstract class PopupContainerTransform {
final markerPoint = _markerPoint(mapCamera, popupSpec);

return Matrix4.translationValues(
PopupCalculations.mapCenterToPointX(mapCamera, markerPoint) +
PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapBottomToPointY(mapCamera, markerPoint) +
PopupCalculations.centerOffsetY(popupSpec),
PopupCalculations.mapCenterToPointX(mapCamera, markerPoint) + PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapBottomToPointY(mapCamera, markerPoint) + PopupCalculations.centerOffsetY(popupSpec),
0.0,
)
..rotateZ(-mapCamera.rotationRad)
Expand Down Expand Up @@ -115,10 +111,8 @@ abstract class PopupContainerTransform {
final markerPoint = _markerPoint(mapCamera, popupSpec);

return Matrix4.translationValues(
PopupCalculations.mapLeftToPointX(mapCamera, markerPoint) +
PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapCenterToPointY(mapCamera, markerPoint) +
PopupCalculations.centerOffsetY(popupSpec),
PopupCalculations.mapLeftToPointX(mapCamera, markerPoint) + PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapCenterToPointY(mapCamera, markerPoint) + PopupCalculations.centerOffsetY(popupSpec),
0.0,
)
..rotateZ(-mapCamera.rotationRad)
Expand Down Expand Up @@ -152,10 +146,8 @@ abstract class PopupContainerTransform {
final markerPoint = _markerPoint(mapCamera, popupSpec);

return Matrix4.translationValues(
PopupCalculations.mapCenterToPointX(mapCamera, markerPoint) +
PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapTopToPointY(mapCamera, markerPoint) +
PopupCalculations.centerOffsetY(popupSpec),
PopupCalculations.mapCenterToPointX(mapCamera, markerPoint) + PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapTopToPointY(mapCamera, markerPoint) + PopupCalculations.centerOffsetY(popupSpec),
0.0,
)
..rotateZ(-mapCamera.rotationRad)
Expand Down Expand Up @@ -190,19 +182,17 @@ abstract class PopupContainerTransform {
final markerPoint = _markerPoint(mapCamera, popupSpec);

return Matrix4.translationValues(
PopupCalculations.mapCenterToPointX(mapCamera, markerPoint) +
PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapCenterToPointY(mapCamera, markerPoint) +
PopupCalculations.centerOffsetY(popupSpec),
PopupCalculations.mapCenterToPointX(mapCamera, markerPoint) + PopupCalculations.centerOffsetX(popupSpec),
PopupCalculations.mapCenterToPointY(mapCamera, markerPoint) + PopupCalculations.centerOffsetY(popupSpec),
0.0,
)..rotateZ(-mapCamera.rotationRad);
}

static Point<num> _markerPoint(
static Offset _markerPoint(
MapCamera mapCamera,
PopupSpec popupSpec,
) {
return mapCamera.project(popupSpec.markerPoint) -
mapCamera.pixelOrigin.toDoublePoint();
final pxPoint = mapCamera.projectAtZoom(popupSpec.markerPoint);
return Offset(pxPoint.dx - mapCamera.pixelOrigin.dx, pxPoint.dy - mapCamera.pixelOrigin.dy);
}
}
11 changes: 5 additions & 6 deletions lib/src/layout/snap_to_map_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ abstract class SnapToMapLayout {
return _layoutWith(
contentAlignment: Alignment.centerLeft,
mapRotationRad: mapCamera.rotationRad,
translateX: _sizeChangeDueToRotation(mapCamera).x / 2,
translateX: _sizeChangeDueToRotation(mapCamera).dx / 2,
);
}

static PopupLayout top(MapCamera mapCamera) {
return _layoutWith(
contentAlignment: Alignment.topCenter,
mapRotationRad: mapCamera.rotationRad,
translateY: _sizeChangeDueToRotation(mapCamera).y / 2,
translateY: _sizeChangeDueToRotation(mapCamera).dy / 2,
);
}

static PopupLayout right(MapCamera mapCamera) {
return _layoutWith(
contentAlignment: Alignment.centerRight,
mapRotationRad: mapCamera.rotationRad,
translateX: -_sizeChangeDueToRotation(mapCamera).x / 2,
translateX: -_sizeChangeDueToRotation(mapCamera).dx / 2,
);
}

static PopupLayout bottom(MapCamera mapCamera) {
return _layoutWith(
contentAlignment: Alignment.bottomCenter,
mapRotationRad: mapCamera.rotationRad,
translateY: -_sizeChangeDueToRotation(mapCamera).y / 2,
translateY: -_sizeChangeDueToRotation(mapCamera).dy / 2,
);
}

Expand All @@ -45,8 +45,7 @@ abstract class SnapToMapLayout {
);
}

static Point<double> _sizeChangeDueToRotation(MapCamera mapCamera) =>
mapCamera.size - mapCamera.nonRotatedSize;
static Offset _sizeChangeDueToRotation(MapCamera mapCamera) => Offset(mapCamera.size.width - mapCamera.nonRotatedSize.width, mapCamera.size.height - mapCamera.nonRotatedSize.height);

static PopupLayout _layoutWith({
required Alignment contentAlignment,
Expand Down
31 changes: 13 additions & 18 deletions lib/src/marker_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class MarkerLayer extends StatefulWidget {
State<MarkerLayer> createState() => _MarkerLayerState();
}

class _MarkerLayerState extends State<MarkerLayer>
with SingleTickerProviderStateMixin {
class _MarkerLayerState extends State<MarkerLayer> with SingleTickerProviderStateMixin {
late AnimationController _centerMarkerController;
void Function()? _animationListener;

Expand Down Expand Up @@ -64,32 +63,28 @@ class _MarkerLayerState extends State<MarkerLayer>
children: (List<Marker> markers) sync* {
for (final m in markers) {
// Resolve real alignment
final left =
0.5 * m.width * ((m.alignment ?? Alignment.center).x + 1);
final top =
0.5 * m.height * ((m.alignment ?? Alignment.center).y + 1);
final left = 0.5 * m.width * ((m.alignment ?? Alignment.center).x + 1);
final top = 0.5 * m.height * ((m.alignment ?? Alignment.center).y + 1);
final right = m.width - left;
final bottom = m.height - top;

// Perform projection
final pxPoint = map.project(m.point);
final pxPoint = map.projectAtZoom(m.point);

final width = (pxPoint.dx + left) - (pxPoint.dx - right);
final height = (pxPoint.dy + top) - (pxPoint.dy - bottom);

// Cull if out of bounds
if (!map.pixelBounds.containsPartialBounds(
Bounds(
Point(pxPoint.x + left, pxPoint.y - bottom),
Point(pxPoint.x - right, pxPoint.y + top),
),
)) continue;
if (!map.pixelBounds.contains(Offset(width, height))) {
continue;
Copy link

@JekaNS JekaNS Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marker always out of bounds ((
After calculation in rows 74,75 width always equals m.width and height always equals m.height
That corresponds just size of marker, but not a position

Fix here PR#88

}

// Apply map camera to marker position
final pos = Point(pxPoint.x - map.pixelOrigin.x, pxPoint.y - map.pixelOrigin.y);
final pos = Point(pxPoint.dx - map.pixelOrigin.dx, pxPoint.dy - map.pixelOrigin.dy);

var markerChild = m.child;
if (widget.layerOptions.selectedMarkerBuilder != null &&
widget.popupState.isSelected(m)) {
markerChild =
widget.layerOptions.selectedMarkerBuilder!(context, m);
if (widget.layerOptions.selectedMarkerBuilder != null && widget.popupState.isSelected(m)) {
markerChild = widget.layerOptions.selectedMarkerBuilder!(context, m);
}
final markerWithGestureDetector = GestureDetector(
onTap: () {
Expand Down
Loading