Leaflet.PolylineOffset icon indicating copy to clipboard operation
Leaflet.PolylineOffset copied to clipboard

Add leaflel polyline offset in Angular

Open baarbaracrr opened this issue 2 years ago • 4 comments

Hello! How can I add this plugin to Angular? I have some problems. I did:

  1. npm install leaflet-polylinedecorator --force
  2. in angular.json, inside "scripts", i added: "node_modules/leaflet-polylineoffset/leaflet.polylineoffset.js"

thanks in advance!

baarbaracrr avatar Nov 08 '22 10:11 baarbaracrr

Hello @baarbaracrr ,

Did you get solution of your problem? Actually I'm also trying to integrate this plugin into my angular application.

anubkumar avatar Feb 24 '23 06:02 anubkumar

Hello @baarbaracrr ,

Did you get solution of your problem? Actually I'm also trying to integrate this plugin into my angular application.

Hello!

Sorry but no :( I searched for this but didn't try it due to lack of time

To add a Leaflet polyline offset in Angular, you can use the Leaflet polyline offset plugin which provides an easy way to create an offset polyline. Here are the steps you can follow:

  1. Install the Leaflet polyline offset plugin by running the following command in your Angular project directory: npm install leaflet-polylineoffset --save
  2. Import the leaflet-polylineoffset library in your component: import 'leaflet-polylineoffset';
  3. Create a polyline using the L.polyline method: const polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
  4. Set the polyline offset by calling the setOffset method on the polyline object: polyline.setOffset(10); The value 10 in the example above sets the offset to 10 pixels. You can adjust the offset value to your desired value.
  5. Finally, you can update the offset value by calling the setOffset method again: polyline.setOffset(20); This updates the offset value to 20 pixels.

Note: Make sure you have imported the Leaflet library and initialized the map before using the Leaflet polyline offset plugin.

baarbaracrr avatar Feb 24 '23 07:02 baarbaracrr

Thanks @baarbaracrr for your prompt response. I tried as you suggested but in this plugin type definition file is missing. Even I also generated type declaration files using npx but still It gives me following error. Property 'setOffset' does not exist on type 'Polyline<LineString | MultiLineString, any>'.ts

Could you please help for the same?

anubkumar avatar Feb 24 '23 07:02 anubkumar

Hello @baarbaracrr , Did you get solution of your problem? Actually I'm also trying to integrate this plugin into my angular application.

Hello!

Sorry but no :( I searched for this but didn't try it due to lack of time

To add a Leaflet polyline offset in Angular, you can use the Leaflet polyline offset plugin which provides an easy way to create an offset polyline. Here are the steps you can follow:

1. Install the Leaflet polyline offset plugin by running the following command in your Angular project directory: `npm install leaflet-polylineoffset --save`

2. Import the leaflet-polylineoffset library in your component: `import 'leaflet-polylineoffset';`

3. Create a polyline using the L.polyline method: `const polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);`

4. Set the polyline offset by calling the setOffset method on the polyline object: `polyline.setOffset(10);`
   The value 10 in the example above sets the offset to 10 pixels. You can adjust the offset value to your desired value.

5. Finally, you can update the offset value by calling the setOffset method again: `polyline.setOffset(20);`
   This updates the offset value to 20 pixels.

Note: Make sure you have imported the Leaflet library and initialized the map before using the Leaflet polyline offset plugin.

This work for me! I only add a type "any" in the const to prevent error with typescript

const polyline: any = L.polyline(LatLng, { color: '#0059a1', }).addTo(map);

jyacot avatar Jan 29 '24 00:01 jyacot