Skip to content

Make custom model box work with dragging markers, changing vehicle, adding points etc. - #2301

Merged
easbar merged 3 commits into
masterfrom
maps_custom_request
May 2, 2021
Merged

easbar merged 3 commits into
masterfrom
maps_custom_request

Conversation

@easbar

@easbar easbar commented Apr 28, 2021 •

Copy link
Copy Markdown
Member

This is my attempt to better integrate the custom model box in the web client. I think it 'works', but for example it kind of breaks the url history as we cannot store the custom model via the url parameters.

@easbar easbar added the web label Apr 28, 2021
$("#custom-model-search-button").prop('disabled', !valid);
};
$("#custom-model-button").click(function() {
ghRequest.cmEditor = cmEditor;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ghRequest now keeps a reference to the custom model editor. rather hacky, but it 'works' :)

ghRequest.cmEditorActive = false;
$("#custom-model-button").click(function () {
$("#custom-model-box").toggle();
ghRequest.cmEditorActive = !ghRequest.cmEditorActive;

@easbar easbar Apr 28, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we simply keep track whether or not the custom model box is opened or not. if it is we will later send a custom request, otherwise we ignore the custom model box and send the same request we did before.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this idea and solution! Then it is also easy to see what is changed due to the custom model.

cmEditor.cm.focus();
cmEditor.cm.setCursor(cmEditor.cm.lineCount())
cmEditor.cm.setCursor(cmEditor.cm.lineCount());
sendCustomData();

@easbar easbar Apr 28, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it is helpful to also update the route whenever we open/close the custom model box

Comment on lines -123 to -124
var sendCustomData = function() {
mapLayer.clearElevation();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clicking the custom model search button now triggers just a normal search, but before we send the request we check whether it should be custom or not.

Comment on lines +133 to +136
var sendCustomDataIgnoreErrors = function () {
ghRequest.ignoreCustomErrors = true;
mySubmit();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might be useful to ignore errors when pressing ctrl-enter, so this way we can force sending the request even when the custom model box reports an invalid custom model.

Comment on lines +862 to +867
if (request.cmEditorActive) {
doCustomRequest(request, routeResultsDiv);
} else {
var urlForAPI = request.createURL();
request.doRequest(urlForAPI, createRouteCallback(request, routeResultsDiv, urlForHistory, doZoom));
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we finally check whether the custom box was active or not and send either the custom or the standard request. Since this logic is now down here, we can use the custom model box when we drag markers, change the marker order, change the vehicle, add/delete points etc.

@easbar easbar Apr 28, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should not run the code block above that starts with if (!doQuery && History.enabled) { when the custom model editor is active? -> Hm not sure, I'll leave it as is for now.

@karussell karussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - works for me :D

@easbar
easbar merged commit 0e23280 into master May 2, 2021
@easbar
easbar deleted the maps_custom_request branch May 2, 2021 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants