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
1 change: 1 addition & 0 deletions flutter_map/flutter_map.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/../fleaflet/.pub" />
<excludeFolder url="file://$MODULE_DIR$/../fleaflet/build" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/../leaflet_flutter/.pub" />
Expand Down
62 changes: 57 additions & 5 deletions flutter_map/lib/src/layer/marker_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,69 @@ class MarkerLayerOptions extends LayerOptions {
MarkerLayerOptions({this.markers = const []});
}

class Anchor {
final double left;
final double top;

Anchor(this.left, this.top);

Anchor._(double width, double height, AnchorPos anchor)
: left = _leftOffset(width, anchor),
top = _topOffset(width, anchor);

static double _leftOffset(double width, AnchorPos anchor) {
switch (anchor) {
case AnchorPos.left:
return 0.0;
case AnchorPos.right:
return width;
case AnchorPos.top:
case AnchorPos.bottom:
case AnchorPos.center:
default:
return width / 2;
}
}

static double _topOffset(double height, AnchorPos anchor) {
switch (anchor) {
case AnchorPos.top:
return 0.0;
case AnchorPos.bottom:
return height;
case AnchorPos.left:
case AnchorPos.right:
case AnchorPos.center:
default:
return height / 2;
}
}
}

enum AnchorPos {
left,
right,
top,
bottom,
center,
}

class Marker {
final LatLng point;
final WidgetBuilder builder;
final double width;
final double height;
final List<double> anchor;
final Anchor _anchor;

Marker({
this.point,
this.builder,
this.width = 30.0,
this.height = 30.0,
this.anchor = const [15.0, 15.0]
});
AnchorPos anchor,
Anchor anchorOverride,
}) : this._anchor =
anchorOverride ?? new Anchor._(width, height, anchor);
}

class MarkerLayer extends StatelessWidget {
Expand All @@ -42,8 +92,10 @@ class MarkerLayer extends StatelessWidget {
new Positioned(
width: markerOpt.width,
height: markerOpt.height,
left: (pos.x - (markerOpt.width - markerOpt.anchor[0])).toDouble(),
top: (pos.y - (markerOpt.height - markerOpt.anchor[1])).toDouble(),
left: (pos.x - (markerOpt.width - markerOpt._anchor.left))
.toDouble(),
top: (pos.y - (markerOpt.height - markerOpt._anchor.top))
.toDouble(),
child: markerOpt.builder(context),
),
);
Expand Down
1 change: 1 addition & 0 deletions flutter_map_example/flutter_map_example.iml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/../leaflet_flutter_example/.pub" />
Expand Down
Loading