Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the anchor point is out of bounds, the whole marker widget disappears #230

Closed
aytunch opened this issue Feb 18, 2019 · 12 comments
Closed
Assignees
Labels
feature This issue requests a new feature

Comments

@aytunch
Copy link
Contributor

aytunch commented Feb 18, 2019

simulator screen shot - iphone xr - 2019-02-18 at 23 45 19
simulator screen shot - iphone xr - 2019-02-18 at 23 45 28

You can see from the second image that left marker is lost with the slightest pan. The moment the little triangle of marker leaves out of any side of the screen, the whole widget disappears. Is there a way to keep it on the map like a safe area or setting a margin for marker?

@aytunch
Copy link
Contributor Author

aytunch commented Feb 19, 2019

I had a chance to experience this issue in a real device using hand gestures instead of the mouse and it really bothers me alot to see a bunch of disappearing markers on the screen. Very buggy feeling. I hope there is already a solution or a quick fix. The reason I switched from flutter google maps to flutter maps and mapbox was mainly the power of using custom widget markers(many thanks). And i assume most people will use markers that has a good amount of width like the ones i have instead of default location markers.

@johnpryan
Copy link
Collaborator

I think this is an easy fix, thanks for the feedback.

@johnpryan johnpryan self-assigned this Feb 24, 2019
@aytunch
Copy link
Contributor Author

aytunch commented Mar 18, 2019

@johnpryan John, were you able to look into this problem? It would be great to have that working:)

@aytunch
Copy link
Contributor Author

aytunch commented Apr 26, 2019

I think this is an easy fix, thanks for the feedback.

@johnpryan Sorry for reminding. I am sure you are very busy. I am reminding again since you said this requires an easy fix. I want my big markers not to disappear:D

@aytunch
Copy link
Contributor Author

aytunch commented May 17, 2019

@johnpryan Do you think wrapping FlutterMap inside of an SizedBox which is larger than the screen size or just wrapping it in a container with margin/padding would solve this issue? And also would it have any side effects in terms of for i.e. performance?

@johnpryan johnpryan added the feature This issue requests a new feature label May 17, 2019
@johnpryan
Copy link
Collaborator

I have not found time to think about the approach. If you have any ideas I would be happy to review a pull request.

@aytunch
Copy link
Contributor Author

aytunch commented May 17, 2019

Unfortunately all the ideas I have involve higher level solutions instead of deeper level ones. So more like workarounds. Which build function is responsible for drawing markers? Can you send a link for the exact line? Also I wonder how a similar situation with CircleLayer, PolylineLayer, PolygonLayer, OverlayImageLayer works just out of the box? Or do they? I never used those however I assume if we have a PolygonLayer, it doesn't disappear totally if the center of the polygon is out of the screen bounds. Right?

@aytunch
Copy link
Contributor Author

aytunch commented May 17, 2019

I found the place: marker_layer.dart

class MarkerLayer extends StatelessWidget {
  final MarkerLayerOptions markerOpts;
  final MapState map;
  final Stream<Null> stream;

  MarkerLayer(this.markerOpts, this.map, this.stream);

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<int>(
      stream: stream, // a Stream<int> or null
      builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
        var markers = <Widget>[];
        for (var markerOpt in markerOpts.markers) {
          var pos = map.project(markerOpt.point);
          pos = pos.multiplyBy(map.getZoomScale(map.zoom, map.zoom)) -
              map.getPixelOrigin();

          var pixelPosX =
              (pos.x - (markerOpt.width - markerOpt.anchor.left)).toDouble();
          var pixelPosY =
              (pos.y - (markerOpt.height - markerOpt.anchor.top)).toDouble();
          // --==== I think in these three lines, we are omitting the offscreen markers ====--
          if (!map.bounds.contains(markerOpt.point)) {
            continue;
          }
          // --====                                                                     ====-- 
          markers.add(
            Positioned(
              width: markerOpt.width,
              height: markerOpt.height,
              left: pixelPosX,
              top: pixelPosY,
              child: markerOpt.builder(context),
            ),
          );
        }
        return Container(
          child: Stack(
            children: markers,
          ),
        );
      },
    );
  }
}

Instead of using map.bounds in if (!map.bounds.contains(markerOpt.point)) {...}, we need to use a new bounds which is extended by half of the markers width in x direction and half of the markers height in y direction. I also know that by the power of your library, we can have many different types of marker widgets with different width and height. So it would only make sense to extend map.bounds by user defined widthextend and heightextend.

If you can tell me how to extend a mapBounds with screen pixel values, I will be happy to try it out and make a PR for you to review.

@aytunch
Copy link
Contributor Author

aytunch commented May 17, 2019

@johnpryan Also in addition to new mapBounds, I believe that we might need to update the

return Container(
          child: Stack(
            children: markers,
          ),
        );

with Stacks property overflow: Overflow.visible
These two additions might fix this issue, hopefully:)

@johnpryan
Copy link
Collaborator

fixed by #313

@aytunch
Copy link
Contributor Author

aytunch commented Jun 8, 2019

@johnpryan @lpongetti I am using flutter_map 0.5.4 with Flutter 1.5 stable. And this fix #313 does not seem to accomplish its duty. containsPartialBounds and _boundsContainsMarker must have something omitted. I hope you guys can give it another look and fix this. And @johnpryan can you open this issue again?

@aytunch
Copy link
Contributor Author

aytunch commented Jun 8, 2019

I upgraded to 0.5.5+2 and it works now:)thanks guys. In pub.dev it says under 0.5.4 that marker disappearing is resolved which was misleading. we need to change that to 0.5.5+2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue requests a new feature
Projects
None yet
Development

No branches or pull requests

2 participants