osm_flutter icon indicating copy to clipboard operation
osm_flutter copied to clipboard

drawRoadManually doesn't seem to work

Open gcsaba2 opened this issue 3 years ago • 12 comments

Please see example code below. When I use drawRoad() the road is drawn, however the problem is that it tries to find the path by calling Openstreetmap's API. I don't want to use the API, I just want to connect the dots and draw lines.

I have tried using drawRoadManually but it doesn't do anything. As you can see on this screenshot, no roads are drawn:

manual

When using drawRoad on the same geopoints, I get this:

drawRoad

POC to reproduce:

import 'package:flutter/material.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';

class ShowRouteScreen extends StatelessWidget {

  late final MapController _mapController;

  ShowRouteScreen({Key? key}) : super(key: key) {
    _mapController = MapController(
      areaLimit: BoundingBox(west: 15.477983, north: 48.742105, east: 23.441823,  south: 45.394864)
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("Test"),
        ),
        body: OSMFlutter(
          controller: _mapController,
          trackMyPosition: false,
          initZoom: 17,
          minZoomLevel: 10,
          maxZoomLevel: 19,
          stepZoom: 1.0,
          onMapIsReady: mapIsReady,
        )
    );
  }

  @override
  Future<void> mapIsReady(bool isReady) async {
    List<GeoPoint> road = [
      GeoPoint(latitude: 46.41389666666667, longitude: 20.345705),
      GeoPoint(latitude: 46.412905,         longitude: 20.346606666666666),
      GeoPoint(latitude: 46.41366,          longitude: 20.34851666666667),
      GeoPoint(latitude: 46.41432499999999, longitude: 20.35004),
      GeoPoint(latitude: 46.413675,         longitude: 20.350489999999997),
      GeoPoint(latitude: 46.41321666666666, longitude: 20.349396666666667),
      GeoPoint(latitude: 46.41244666666667, longitude: 20.34956833333333)
    ];
    
    await _mapController.drawRoadManually(road, Colors.red, 15);

    /*  // example with drawRoad
    var start = road.first;
    var end = road.last;
    road.removeLast();
    road.removeAt(0);

    await _mapController.drawRoad(
        start,
        end,
        intersectPoint: road,
        roadType: RoadType.foot,
        roadOption: RoadOption(roadColor: Colors.red, roadWidth: 15));
     */
  }
}

gcsaba2 avatar Dec 27 '21 20:12 gcsaba2

i will check that

liodali avatar Dec 27 '21 20:12 liodali

the method drawRoadManually built to replace drawRoad that use osm routing api, so you can use it if you have an external routing api theoretically you cannot build road with only 5 geo point

liodali avatar Dec 29 '21 20:12 liodali

Thanks. Could you please add a method drawLine which would draw a line between two points?

gcsaba2 avatar Jan 01 '22 19:01 gcsaba2

i will add that but in 0.29+

liodali avatar Jan 04 '22 15:01 liodali

Isn't the problem in ExtGeoPoint.toListNum ?

It is simply exchanging latitude to longitude, usually latitude is the first...

extension ExtGeoPoint on GeoPoint {
  List<num> toListNum() {
    return [
      this.longitude,
      this.latitude,
    ];
  }
}

agostonhalaszykiss avatar Mar 30 '22 13:03 agostonhalaszykiss

i will check it but usually like i told the purpose of drawRoadManually if you have your own routing service or any other third party that do the same as osrm api

liodali avatar Mar 30 '22 13:03 liodali

Yeah, unfortunately osrm can't do horses and kayaking :D But Thanks anyway

agostonhalaszykiss avatar Mar 30 '22 14:03 agostonhalaszykiss

i will add that but in 0.29+

Downloaded 0.4 today and it seems drawLine is missing... is it actually implemented and just private in some way?

WriteCodeEveryday avatar Oct 29 '22 04:10 WriteCodeEveryday

can you show me the full error message

liodali avatar Oct 29 '22 15:10 liodali

@liodali I'm replying that you said drawLine would exist in 0.29 but I don't see it in 0.4.

image

WriteCodeEveryday avatar Oct 29 '22 15:10 WriteCodeEveryday

yeah i didnt yet impl that because i need t re-aline the web impl with android and ios and then will start refactoring draw road sorry for this lazyness from my side but i will make sure to make web impl stable soon

liodali avatar Oct 29 '22 16:10 liodali

this is for Android.

WriteCodeEveryday avatar Oct 29 '22 18:10 WriteCodeEveryday