0

I am trying to use polylines on ngx-leaflet but i'm having some issues. First of all, I try to declare a polyline by passing a hardcoded latlng value it all works, but if I try to pass a variable ti gives me the following error:

   bubu = [[39.838128, 15.480699]];
    route= polyline([[39.838128, 15.480699]]); // ok
    routes= polyline(this.bubu); /*Argument of type 'number[][]' is not assignable to parameter of type 'LatLngExpression[]'.
    Type 'number[]' is not assignable to type 'LatLngExpression'.
    Type 'number[]' is not assignable to type 'LatLngLiteral'.
    Property 'lat' is missing in type 'number[]'.*/

I've also tried to use the setLatLngs method to update the coordinates dynamically but it does not accept Marker[] as coordinates:

    markers: Marker[] = [];
    marker.push(/*a valid marker*/);
    marker.push(/*a valid marker*/);
    route= polyline( markers); /*: Argument of type 'Marker<any>[]' is not assignable to parameter of type 'LatLngExpression[]'.
    Type 'Marker<any>' is not assignable to type 'LatLngExpression'.
    Type 'Marker<any>' is not assignable to type 'LatLngLiteral'.
    Property 'lat' is missing in type 'Marker<any>'.
*/

So I can I dynamically create a polyline and update with the library? The final purpose i'm trying to build is that the final user has the feature of creating markers and link them with polylines.

I want to make clear that i'm using only the standard 'ngx-leaflet' lib and not the others plugin.

kboul
  • 13,836
  • 5
  • 42
  • 53
Thecave3
  • 762
  • 12
  • 27
  • You must pass `this.budu` by type: `LatLngExpression`. Please share `LatLngExpression` interface – Karabah Apr 26 '18 at 16:01
  • It is not an interface that i've built, but is an internal interface built in ngx-leaflet – Thecave3 Apr 26 '18 at 16:04
  • Click over this type it will moved you to declaration of this type. Check this and if you can share structure – Karabah Apr 26 '18 at 16:10
  • Can you explain what are you saying? – Thecave3 Apr 26 '18 at 16:14
  • What IDE do you use? Try find `LatLngExpression` – Karabah Apr 26 '18 at 17:55
  • I think what they're trying to say is make sure you're typing the `this.budu` variable properly to be of type `LatLngExpression`. Your declaration of the variable should look like: `budu: LatLngExpression = [[39.838128, 15.480699]];`. You'll also need to import that type from leaflet. – reblace Apr 26 '18 at 21:47
  • Ok, but what if I have a Marker [ ] type and I need to get lat and lng from that array? Btw I am using Webstorm. – Thecave3 Apr 26 '18 at 23:34
  • I have also found out a workaround to this problem but I want to wait for a better solution (tomorrow I am going to write the answer) – Thecave3 Apr 26 '18 at 23:35

0 Answers0