Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corridor.setLatLng #5

Open
luquezsantiago86 opened this issue Feb 2, 2021 · 1 comment
Open

corridor.setLatLng #5

luquezsantiago86 opened this issue Feb 2, 2021 · 1 comment

Comments

@luquezsantiago86
Copy link

Hello, I am new in LeafletJs and this plugin is really helpful.
I am trying to display a Corridor in realTime. For that, I update the coordinates using setLatLng.

My code is working with Polylines and Polygons, but when I try to use setLatLng I have an error:
L.corridor.setLatLngs is not a function

Looking at the source code of leaflet-corridor, I realized that there is no function existing for this feature.

It is possible to have an aproach of how to write it myself?

@luquezsantiago86
Copy link
Author

luquezsantiago86 commented Feb 3, 2021

For future readers, I could resolve this by moving and modifying the functions to the main js file, and calling directly to the polyline.setLatLngs atributte:

var lineRed = L.polyline([ [40.702222, -73.979378], [41.702222, -73.979378] ], { color: 'red' }).addTo(map); function updateWeight() { const buffer = 1 currentZoom = map.getZoom(); // getMetersPerPixel var centerLatLng = map.getCenter(); // get map center var pointC = map.latLngToContainerPoint(centerLatLng); // convert to containerpoint (pixels) var pointX = L.point(pointC.x + 10, pointC.y); // add 10 pixels to x // convert containerpoints to latlng's var latLngX = map.containerPointToLatLng(pointX); var resultado = centerLatLng.distanceTo(latLngX) / 10; // calculate distance between c and x (latitude) buffer_new = buffer * 2 / resultado return buffer_new } map.on('zoomend', function() { currentZoom = map.getZoom(); console.log('zoom:', currentZoom) if (currentZoom !== 0) { updateWeight() console.log('new buffer:', buffer_new) lineRed.setStyle({ 'weight': buffer_new }); } }); lineRed.setLatLngs(latlng)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant