OwnWeb / flutter_map_tappable_polyline

A tappable Polyline plugin for flutter_map
https://pub.dev/packages/flutter_map_tappable_polyline
MIT License
54 stars 44 forks source link

Detect which polyline was tapped #57

Closed jdevo2004 closed 11 months ago

jdevo2004 commented 1 year ago

Is there a way to detect which polyline from a list was tapped and open a popup window?

HugoHeneault commented 11 months ago

Hello @jdevo2004

Yes, as seen on example, you can add tags to your polylines then open a popup (have a look at https://api.flutter.dev/flutter/material/showDialog.html):

TappablePolylineLayer(
              // Will only render visible polylines, increasing performance
              polylineCulling: true,
              pointerDistanceTolerance: 20,
              polylines: [
                TaggedPolyline(
                  tag: 'My Polyline',
                  // An optional tag to distinguish polylines in callback
                  points: getPoints(0),
                  color: Colors.red,
                  strokeWidth: 9.0,
                ),
                TaggedPolyline(
                  tag: 'My 2nd Polyline',
                  // An optional tag to distinguish polylines in callback
                  points: getPoints(1),
                  color: Colors.black,
                  strokeWidth: 3.0,
                ),
                TaggedPolyline(
                  tag: 'My 3rd Polyline',
                  // An optional tag to distinguish polylines in callback
                  points: getPoints(0),
                  color: Colors.blue,
                  strokeWidth: 3.0,
                ),
              ],
// you have to change here so you open dialog when one polyline has been tapped
              onTap: (polylines, tapPosition) => print('Tapped: ' +
                  polylines.map((polyline) => polyline.tag).join(',') +
                  ' at ' +
                  tapPosition.globalPosition.toString()),
              onMiss: (tapPosition) {
                print('No polyline was tapped at position ' +
                    tapPosition.globalPosition.toString());
              })