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

_clearPath() leaves line on the map #31

Closed
Beamer92 opened this issue Dec 19, 2019 · 3 comments
Closed

_clearPath() leaves line on the map #31

Beamer92 opened this issue Dec 19, 2019 · 3 comments

Comments

@Beamer92
Copy link

Beamer92 commented Dec 19, 2019

When I call .clear() on my terrain profiler, the graph clears out but the line get's left on the map. I can see where _clearPath() goes and removes class names from the <path> element, but this doesn't appear to affect the line on the map at all. So I'm unsure what the objective is.

I would expect the polyline that's drawn when I load in data to disappear (if not remove the g->svg->path elements altogether).

If this is expected behavior, I'd like to remove the line when I clear the profile data in preparation to display a new profile and line. I found that I can remove the graph from the map entirely with .remove(), but the line persists.

@Raruto
Copy link
Owner

Raruto commented Dec 19, 2019

Hi Brendan,
have you already tried to do something like this? #13 (comment)

@Beamer92
Copy link
Author

Beamer92 commented Dec 19, 2019

I'm sure I looked through old issues before asking... Yes that worked for me! I danced around it for so long yesterday.

The solution for me is to use .remove() in two places:

terrainProfile.addTo(theMap);
terrainProfile.load(geoJsonData);

...stuff happens....

terrainProfile.layer.remove() //removes line from map
terrainProfile.remove(); //removes graph 

Thanks!

@Raruto
Copy link
Owner

Raruto commented Dec 20, 2019

Ok, good to know,
this is necessary because the load / loadGeoJSON functions can be actually considered a shorthand for the following:

var chart = L.control.elevation();
var layer = L.geoJson( jsonData, {
                onEachFeature: chart.addData.bind( chart ) // populate graph with elevation data
            });

...

chart.addTo(map); // add graph to map
layer.addTo(map); // add line to map

...

layer.remove() // remove line from map
chart.remove(); // remove graph from map

Source code:

loadGeoJSON: function(data) {

Have a nice day,
Raruto

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

2 participants