perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.08k stars 350 forks source link

Read the global configuration, not the local one #456

Open efranqueiro opened 6 years ago

efranqueiro commented 6 years ago

Local options contains the waypoint list, but geometryOnly is in the global options object

efranqueiro commented 6 years ago

Hi. What I'm trying to do is not show the "legend", as seen here

image

This is the code I'm using

            var directions_provider = L.Routing.control({
                waypoints: waypoints,
                router: new L.Routing.TomTom(options.routing_apikey, options),
                // geometryOnly: true,     // don't show the legend
                lineOptions: {
                    styles: [
                        {color: 'black', opacity: 0.15, weight: 9},
                        {color: 'white', opacity: 0.8, weight: 6},
                        {color: 'blue', opacity: 0.5, weight: 2}
                    ]
                }
            });
            directions_provider.addTo(options.map);     // before calling route()

            directions_provider.route(waypoints, function(context, result) {
                if (result && success_callback) {
                    success_callback(...);
                }
            }, {}, { geometryOnly: true });

If I pass geometryOnly: true in the options to the route() method, I get the image above, which is not what I want. With this change, it doesn't show the legend, as desired. With the code above, the option is being ignored.

Perhaps I'm mistaken in the way to hide the legend?

Thanks!

perliedman commented 6 years ago

Alright, it's interesting to note that you can achieve that using geometryOnly this way; I wasn't aware of that.

If I understand correctly, you should look at #20 for techniques to hide the itinerary.

efranqueiro commented 6 years ago

I tried hide(), but it hides the itinerary and also the route and waypoints. Then I tried the CSS approach by putting it in a file and including that in my html (I tried before and after the Leaflet CSS). But that didn't work either. Is that the way to use it? So, for now, geometryOnly still works for me.

In any case, I tried passing it as you suggested and it didn't work, which takes me back to this PR :)

perliedman commented 6 years ago

The thing is, as it is now, this PR breaks the original purpose of the geometryOnly option, since it will be disregarded when passed to the route method. So it will not fly.

I know hiding the itinerary isn't ideally implemented as it is now, but I don't see this PR as the way forward to improve that.

Using a CSS rule is probably the easiest, and it definitely does work as long as you put the rule in the correct place and use the correct specificity.

Other than that, improving the functionality offered by hide would be the best way to improve the situation.

efranqueiro commented 6 years ago

Agreed that this is not the right way to do what I want, So I worked around that in my code.

For the CSS approach, what would the correct place be?

In my tests, passing geometryOnly in the options for the route() method doesn't seem to work. So unless I'm mistaken, currently, there's no way to pass that option. So either we pass it in the constructor, with this PR, or the other scenario should be fixed. Perhaps just doing if (options.geometryOnly || this.options.geometryOnly) would be a suitable workaround?

Lweaver5051 commented 6 years ago

Hello everyone, I have made a post but not getting any responses. Im new to leaflet and dont know whats going on or why. I believe I added everything the documents say to add but I'm still getting the error.

_

_ import L from 'leaflet'; ### ERROR TypeError: Cannot read property 'control' of undefined My Code where --> **var polylineRouteB = L.Routing.control**({**