ibrierley / flutter_map_line_editor

A basic line/poly editor that works with flutter_map and dragmarkers.
MIT License
44 stars 25 forks source link

Question about color withOpacity #4

Closed zozeei closed 3 years ago

zozeei commented 3 years ago

When I drag the marker, the transparency of the shape changed to opaque. I want it to keep transparent as it is. How can I fix this problem?

untitled

ibrierley commented 3 years ago

Hi, I don't think that could be related to the editor, as it doesn't know (or care) about the shape (iirc, it's a while since I did it), it just edits a list of points. So I'm unsure that it could be related to it, unless there's something I'm missing.

Maybe it's worth showing the code...are you sure you aren't repeatedly redrawing the shape multiple times or something ?

zozeei commented 3 years ago

i am sure ,i aren't repeatedly redrawing the shape multiple times

ibrierley commented 3 years ago

Feel free to post the code, I'm not sure what else it could be. As I said, the line editor doesn't know anything about shapes...the only other thing I can think of, is if its duplicating a lot of points on the shape, so its added multiple times. Maybe dump out the list of points each build, see if there's just 3, or a lot more.

On Tue, Sep 1, 2020 at 11:52 AM zozeei notifications@github.com wrote:

i am sure ,i aren't repeatedly redrawing the shape multiple times

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ibrierley/flutter_map_line_editor/issues/4#issuecomment-684765017, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YN5IJFWUPHNJZSTFBKKTSDTG5PANCNFSM4QRR55ZA .

zozeei commented 3 years ago

my code

class _RequestDrawScreenState extends State<RequestDrawScreen> {
  final MapController mapController = MapController();
  final List<Marker> userLocationMarkers = <Marker>[];
  PolyEditor polyEditor;
  List<Polygon> polygons = [];

  var testPolygon =
      new Polygon(color: Colors.deepOrange.withOpacity(0.1), points: []);

  @override
  void initState() {
    super.initState();

    polyEditor = new PolyEditor(
        points: testPolygon.points,
        pointIcon: Icon(
          Icons.crop_square,
          size: 23,
        ),
        intermediateIcon: Icon(Icons.lens, size: 15, color: Colors.grey),
        callbackRefresh: () => {this.setState(() {})});
  }

  @override
  Widget build(BuildContext context) {
    polygons.add(testPolygon);
    return Scaffold(
        body: SafeArea(
      child: Stack(
        children: [
          FlutterMap(
            mapController: mapController,
            options: MapOptions(
              onTap: (latLog) {
                polyEditor.add(testPolygon.points, latLog);
                print(latLog);
              },
              plugins: <MapPlugin>[
                // USAGE NOTE 2: Add the plugin
                LocationPlugin(),
                DragMarkerPlugin(),
              ],
              center: LatLng(45.5231, -122.6765),
              zoom: 6.4,
            ),
            layers: <LayerOptions>[
              TileLayerOptions(
                urlTemplate:
                    'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
                subdomains: <String>['a', 'b', 'c'],
              ),
              // USAGE NOTE 3: Add the layer for the marker
              MarkerLayerOptions(markers: userLocationMarkers),
              PolygonLayerOptions(polygons: polygons),
              DragMarkerPluginOptions(markers: polyEditor.edit()),

            ],
          ),
          Positioned(
              right: 10.0,
              bottom: 100.0,
              child: Column(children: <Widget>[
                IconButton(
                  iconSize: 30.0,
                  icon: const Icon(Icons.map),
                  tooltip: "Map Type",
                  onPressed: null,
                ),
              ])),
        ],
      ),
    ));
  }
}
ibrierley commented 3 years ago

I haven't run it, but it looks like you're not resetting your polygons list every build, so as mentioned you're readding it every build, so you will end up with a list of repeated testpolygons. Try adding in polygons = [] as first line in build method.

zozeei commented 3 years ago

Thanks for the answer, it works. @ibrierley