OSM: Are there any plans to allow waypoint dragging on routes?
Jamie Guthrie
jamie.guthrie at gmail.com
Wed Feb 14 16:55:42 UTC 2018
Does that mean that having coords in the directions boxes is not always a
must-avoid situation?
I assumed that for user functionality, it would always be best to have a
physical location name in the boxes, but if the target of the site is for
more mapping enthusiasts then I could be wrong, and accuracy is valued over
looking-good.
I did have a look at the code in reference to the reverse_directions
functionality though, and how it alway deletes the location and puts coords
in the directions boxes, and its to do with the endpoint.setValue(*value*,
*LatLng*) method..
```
endpoint.setValue = function(value, latlng) {
endpoint.value = value;
delete endpoint.latlng;
input.val(value);
if (latlng) {
endpoint.setLatLng(latlng);
} else {
endpoint.getGeocode();
}
};
```
My initial thoughts are that this should set the value of the endpoint
inner variables, as well as set the endpoint input value to the value
passed in.
Sure enough, you can see that the inner endpoint.value variable is set, and
then the input.val() is also set to value. And you can see when going
through with a debugger, that the input's value changes in the HTML.
But, the next step is to either go into the setLatLng() or getGeocode()
methods. When reversing directions, the router passes both the value and
the LatLng coords into this method, so the code goes into setLatLng(), but
in setLatLng() the input.val() value is overwritten with the LatLng coords,
which to me, seems like unwarranted behaviour.
```
endpoint.setLatLng = function (ll) {
var precision = OSM.zoomPrecision(map.getZoom());
input.val(ll.lat.toFixed(precision) + ", " +
ll.lng.toFixed(precision));
endpoint.hasGeocode = true;
endpoint.latlng = ll;
endpoint.marker
.setLatLng(ll)
.addTo(map);
};
```
So either the input.val(value) assignment in setValue() is completely
redundant, as the input val is overwritten in both setLatLng() and
getGeocode(), (and can therefore be removed), or setLatLng() should not
concern itself with the setting of the input box values..
One way to sort of leave it remaining as it is as well as to set the input
box value as the actual passed in value, would be to put the
input.val(value) assignment after the call to setLatLng()
i.e.
```
endpoint.setValue = function(value, latlng) {
endpoint.value = value;
delete endpoint.latlng;
if (latlng) {
endpoint.setLatLng(latlng);
input.val(value);
} else {
endpoint.getGeocode();
}
};
```
So now setLatLng()'s behaviour is not affected so nothing will break
elsewhere, and setValue() actually sets the input value to the value that
was passed in, which is surely the expected behaviour?
Jamie
On 14 February 2018 at 07:10, Tom Hughes <tom at compton.nu> wrote:
> On 14/02/18 02:04, Jamie Guthrie wrote:
>
> Or rather, is there any objection if I start working on being able to drag
>> routes from any point along the route to create way points? (i.e. similar
>> to how its possible in Google and Bing maps)
>>
>> It would require some work to allow OSM.Directions to handle more than
>> just the two Endpoints, but I can't see it being too excessively difficult
>> to implement..
>>
>
> The only thing I'd say is to bear in mind that we're not trying to
> reimplement Google Maps and provided a full featured end-user mapping
> experience.
>
> Routing exists because it's useful for mappers to check connectivity
> issues - the question is does adding waypoints help with that?
>
> Tom
>
> --
> Tom Hughes (tom at compton.nu)
> http://compton.nu/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20180214/e903ed5f/attachment.html>
More information about the rails-dev
mailing list