Browse Source

recode la remote control josm

master
vincent 2 months ago
parent
commit
493b193779
6 changed files with 67 additions and 69 deletions
  1. +12
    -55
      assets/controllers/josm_controller.js
  2. +15
    -0
      src/Controller/MapController.php
  3. +28
    -2
      src/Controller/TaskController.php
  4. +5
    -0
      src/Entity/Project.php
  5. +6
    -0
      templates/partials/_overpass-element-popup.html.twig
  6. +1
    -12
      templates/task/show.html.twig

+ 12
- 55
assets/controllers/josm_controller.js View File

@ -2,70 +2,27 @@ import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static values = {
imagery: String,
importurl: String,
layername: String,
sendosm: Boolean,
bottom: Number,
top: Number,
left: Number,
right: Number,
comment: String,
source: String,
hashtags: String,
commands: String,
}
remoteControl() {
// cf <https://josm.openstreetmap.de/wiki/Help/RemoteControlCommands>
const baseurl = 'http://localhost:8111';
const _this = this;
var url = baseurl + '/version';
fetch(url)
.then(function (response) {
return response.json();
})
.then(function (json) {
console.log('JOSM v' + json.version);
url = baseurl + '/imagery?' + (new URLSearchParams({
'id': _this.imageryValue,
}));
fetch(url)
const _this = this, commands = JSON.parse(this.commandsValue);
for (var command in commands) {
var url = baseurl + '/' + command, params = new URLSearchParams();
for (var name in commands[command]) {
params.append(name, commands[command][name]);
}
if (Array.from(params.length > 0)) {
url += '?' + params.toString();
}
fetch(url)
.then(function (response) {
return response.text();
})
.then(function (text) {
console.log('JOSM imagery ' + text);
});
if (_this.sendosmValue) {
url = baseurl + '/import?' + (new URLSearchParams({
'new_layer': true,
'layer_name': _this.layernameValue,
'url': _this.importurlValue,
}));
fetch(url)
.then(function (response) {
return response.text();
})
.then(function (text) {
console.log('JOSM import ' + text);
});
}
url = baseurl + '/zoom?' + (new URLSearchParams({
'bottom': _this.bottomValue,
'top': _this.topValue,
'left': _this.leftValue,
'right': _this.rightValue,
'changeset_comment': _this.commentValue,
'changeset_source': _this.sourceValue,
'changeset_hashtags': _this.hashtagsValue,
}));
fetch(url)
.then(function (response) {
return response.text();
})
.then(function (text) {
console.log('JOSM zoom ' + text);
});
});
}
}
}

+ 15
- 0
src/Controller/MapController.php View File

@ -14,8 +14,23 @@ class MapController extends AbstractController
public function popup(Request $request): Response
{
$element = json_decode($request->query->get('element'), true);
$josmCommands = [
'imagery' => [
'id' => 'osmfr',
],
'load_and_zoom' => [
'bottom' => $element['bounds']['minlat'],
'top' => $element['bounds']['maxlat'],
'left' => $element['bounds']['minlon'],
'right' => $element['bounds']['maxlon'],
'select' => sprintf('%s%d', $element['type'], $element['id']),
],
];
return $this->render('partials/_overpass-element-popup.html.twig', [
'element' => $element,
'josmCommands' => json_encode($josmCommands),
]);
}
}

+ 28
- 2
src/Controller/TaskController.php View File

@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Workflow\WorkflowInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
#[Route('/task')]
class TaskController extends AbstractController
@ -91,6 +92,7 @@ class TaskController extends AbstractController
return $this->redirect($request->headers->get('Referer'));
}
$project = $task->getProject();
$nextTask = $repository->findNextOne($task);
$comment = new Comment();
@ -104,12 +106,36 @@ class TaskController extends AbstractController
$geom = \geoPHP::load($task->getGeojson(), 'json');
$bbox = $geom->getBBox();
$josmCommands = [
'imagery' => [
'id' => $project->hasImagery() ? $project->getImagery() : 'osmfr',
],
'import' => [
'new_layer' => true,
'layer_name' => $task->getName(),
'url' => $this->generateUrl(
'app_task_osm',
['slug' => $task->getSlug()],
UrlGeneratorInterface::ABSOLUTE_URL
),
],
'zoom' => [
'bottom' => $bbox['miny'],
'top' => $bbox['maxy'],
'left' => $bbox['minx'],
'right' => $bbox['maxx'],
'changeset_comment' => sprintf('%s %s', $project->getName(), $task->getName()),
'changeset_source' => $project->getSource(),
'changeset_hashtags' => $project->getHashtags(),
],
];
return $this->render('task/show.html.twig', [
'task' => $task,
'project' => $task->getProject(),
'project' => $project,
'commentForm' => $commentForm,
'nextTask' => $nextTask,
'bbox' => $bbox,
'josmCommands' => json_encode($josmCommands),
]);
}


+ 5
- 0
src/Entity/Project.php View File

@ -204,6 +204,11 @@ class Project
return $this;
}
public function hasImagery(): bool
{
return !empty($this->imagery);
}
public function getImagery(): ?string
{
return $this->imagery;


+ 6
- 0
templates/partials/_overpass-element-popup.html.twig View File

@ -4,6 +4,12 @@
{% if element.type == 'relation' and element.tags and element.tags.route and element.tags.route == 'hiking' %}
<br/>sur <a href="https://hiking.waymarkedtrails.org/#route?id={{ element.id }}&type=relation" target="_blank">WayMarkedTrails</a>
{% endif %}
<br/>dans <button class="btn btn-link" style="--bs-btn-padding-x:0;--bs-btn-padding-y:0;"
type="button"
data-controller="josm"
data-action="click->josm#remoteControl"
data-josm-commands-value="{{ josmCommands|escape('html_attr') }}"
>JOSM</button>
<table><tbody>
{% for key, value in element.tags %}
<tr><th>{{ key }}</th><td>{{ value }}</td></tr>


+ 1
- 12
templates/task/show.html.twig View File

@ -41,18 +41,7 @@
type="button"
data-controller="josm"
data-action="click->josm#remoteControl"
data-josm-imagery-value="{{ project.imagery is not empty ? project.imagery : 'osmfr' }}"
data-josm-importurl-value="{{ url('app_task_osm', {'slug': task.slug}) }}"
data-josm-layername-value="{{ task.name }}"
data-josm-sendosm-value="{{ task.osm is not empty }}"
data-josm-bottom-value="{{ bbox.miny }}" {# Minimum latitude 43.923196020314 #}
data-josm-top-value="{{ bbox.maxy }}" {# Maximum latitude 43.94450663651 #}
data-josm-left-value="{{ bbox.minx }}" {# Minimum longitude 4.3220213108728 #}
data-josm-right-value="{{ bbox.maxx }}" {# Maximum longitude 4.37742111766 #}
data-josm-comment-value="{{ project.name }} {{ task.name }}"
data-josm-source-value="{{ project.source }}"
data-josm-hashtags-value="{{ project.hashtags }}"
data-josm-commands-value="{{ josmCommands|escape('html_attr') }}"
>Télécommande JOSM</button>
{% endif %}
{% endif %}


Loading…
Cancel
Save