Newer
Older
task-bldg / src / main / resources / templates / meshes.html
@yuuhayashi yuuhayashi on 7 Oct 2023 8 KB add : [return] botton
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org"
  3. xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  4. layout:decorate="~{layout/layout}">
  5. <head>
  6. <meta charset="UTF-8" th:remove="tag">
  7. <script th:inline="javascript">
  8. const meshes = /*[[${meshes}]]*/"meshes";
  9. console.log(meshes);
  10. const city = /*[[${city}]]*/"city";
  11. console.log(city);
  12.  
  13. var __map = null;
  14. var __markerLayer = null;
  15. var __lineLayer = null;
  16.  
  17. function loadMap() {
  18.  
  19. // ICON のスタイル
  20. style = new ol.style.Style({
  21. image: new ol.style.Icon({
  22. src: '/task-bldg/img/osm_200x200.png',
  23. anchor: [0.5, 0.5],
  24. scale: 0.2
  25. }),
  26. stroke: new ol.style.Stroke({color: '#ff33ff', width: 10})
  27. });
  28. var status1 = new ol.style.Style({
  29. image: new ol.style.Icon({
  30. src: '/task-bldg/img/PREPARATION.png',
  31. anchor: [0.5, 0.5],
  32. scale: 1
  33. })
  34. });
  35. var status2 = new ol.style.Style({
  36. image: new ol.style.Icon({
  37. src: '/task-bldg/img/ACCEPTING.png',
  38. anchor: [0.5, 0.5],
  39. scale: 1
  40. })
  41. });
  42. var status3 = new ol.style.Style({
  43. image: new ol.style.Icon({
  44. src: '/task-bldg/img/RESERVED.png',
  45. anchor: [0.5, 0.5],
  46. scale: 1
  47. })
  48. });
  49. var status4 = new ol.style.Style({
  50. image: new ol.style.Icon({
  51. src: '/task-bldg/img/EDITING.png',
  52. anchor: [0.5, 0.5],
  53. scale: 1
  54. })
  55. });
  56. var status5 = new ol.style.Style({
  57. image: new ol.style.Icon({
  58. src: '/task-bldg/img/NG.png',
  59. anchor: [0.5, 0.5],
  60. scale: 1
  61. })
  62. });
  63. var status6 = new ol.style.Style({
  64. image: new ol.style.Icon({
  65. src: '/task-bldg/img/OK.png',
  66. anchor: [0.5, 0.5],
  67. scale: 1
  68. })
  69. });
  70. // マップの作成
  71. __map = new ol.Map({
  72. target: 'map',
  73. layers: [
  74. new ol.layer.Tile({
  75. source: new ol.source.OSM()
  76. })
  77. ],
  78. view: new ol.View({
  79. center: ol.proj.fromLonLat([Number(city.lng),Number(city.lat)]),
  80. zoom: 12
  81. })
  82. });
  83. var title = document.getElementById("title");
  84. title.innerHTML = "PLATEAU OSMデータ : " + city.citycode + " " + city.cityname;
  85.  
  86. // 表示するためのレイヤーを作成する
  87. __markerLayer = new ol.layer.Vector({
  88. source: new ol.source.Vector()
  89. });
  90. __map.addLayer(__markerLayer);
  91. // ポップアップを表示するためのオーバーレイを作成する
  92. __overlay = new ol.Overlay({
  93. element: document.getElementById('popup'),
  94. positioning: 'bottom-center'
  95. });
  96. {
  97. $(meshes).each(function() {
  98. // Icon
  99. var feature = new ol.Feature({
  100. geometry: new ol.geom.Point(ol.proj.fromLonLat([Number(this.lng),Number(this.lat)])),
  101. code: this.meshcode
  102. });
  103. feature.information = this;
  104. if (this.status == "PREPARATION") {
  105. feature.setStyle(status1);
  106. }
  107. else if (this.status == "ACCEPTING") {
  108. feature.setStyle(status2);
  109. }
  110. else if (this.status == "RESERVED") {
  111. feature.setStyle(status3);
  112. }
  113. else if (this.status == "EDITING") {
  114. feature.setStyle(status4);
  115. }
  116. else if (this.status == "NG") {
  117. feature.setStyle(status5);
  118. }
  119. else if (this.status == "OK") {
  120. feature.setStyle(status6);
  121. }
  122. else {
  123. feature.setStyle(style);
  124. }
  125.  
  126. __markerLayer.getSource().addFeature(feature);
  127. __map.getView().setCenter(ol.proj.fromLonLat([Number(this.lng),Number(this.lat)]));
  128. // LineString
  129. if (this.line != null) {
  130. var lineString = JSON.parse(this.line);
  131. var points = lineString.coordinates;
  132. console.log(points);
  133. drawPolygon([points]);
  134. }
  135. });
  136. // 地図のクリックイベントを設定
  137. __map.on('click', function (evt) {
  138. var feature = __map.forEachFeatureAtPixel(
  139. evt.pixel,
  140. function (feature) {
  141. return feature;
  142. }
  143. );
  144. if (feature) {
  145. var coordinates = feature.getGeometry().getCoordinates();
  146. var info = feature.information;
  147. var element = __overlay.getElement();
  148. var descriptionHTML =
  149. "<div>" + info.citycode +" : "+ info.cityname + "</div>" +
  150. "<div>code: " + info.meshcode + "</div>" +
  151. "<div>file: " + info.path + "</div>" +
  152. "<div>version: " + info.version + "</div>" +
  153. "<div>status: " + info.status + "</div>" +
  154. "<div><a href='/task-bldg/tasks?citycode=" + city.citycode + "&meshcode=" + info.meshcode +"'>タスク</a></div>";
  155. element.innerHTML = descriptionHTML;
  156. __overlay.setPosition(coordinates);
  157. __map.addOverlay(__overlay);
  158. } else {
  159. __map.removeOverlay(__overlay);
  160. }
  161. });
  162. };
  163. }
  164.  
  165. /**
  166. * ポリゴンを描画する
  167. */
  168. function drawPolygon(coordinates) {
  169. // ジオメトリの作成
  170. var polygon = new ol.geom.Polygon([]);
  171. polygon.setCoordinates(coordinates);
  172.  
  173. // 地物オブジェクトの作成 〜 レイヤーの作成
  174. var feature = new ol.Feature(
  175. polygon.transform('EPSG:4326', 'EPSG:3857')
  176. );
  177. feature.setId('tokyotower');
  178.  
  179. var vector = new ol.source.Vector({
  180. features: [feature]
  181. });
  182. var routeLayer = new ol.layer.Vector({
  183. source: vector,
  184. style: new ol.style.Style({
  185. stroke: new ol.style.Stroke({ color: '#000000', width: 2 })
  186. //fill: new ol.style.Fill({ color: [0, 0, 0, 0.2] })
  187. })
  188. });
  189.  
  190. // 作成したポリゴンをレイヤーにのせる
  191. __map.addLayer(routeLayer);
  192. }
  193. </script>
  194. </head>
  195. <body onload='loadMap()'>
  196. <input type="hidden" id="city" th:value="${city}" />
  197.  
  198. <!-- サイドバーの表示 -->
  199. <div layout:fragment="sidebar" th:replace="~{fragments/sidebar :: sidebar}">
  200. </div>
  201.  
  202. <!-- コンテンツの表示 -->
  203. <div layout:fragment="content">
  204. <main class="offcanvas-outside bg-light">
  205. <div class="container-fluid">
  206. <!-- トグルボタン -->
  207. <div th:replace="~{fragments/sidebar :: toggler}">
  208. </div>
  209.  
  210. <div class="row">
  211. <div class="col">
  212.  
  213. <div class="card shadow">
  214. <div class="card-header">
  215. <h6 class="text-navy my-2" id='title'></h6>
  216. </div>
  217. <div class="card-body">
  218.  
  219. <!-- マップ -->
  220. <div id="wrap">
  221. <div class="header">
  222. <div id='map'></div>
  223. </div>
  224. <!-- ポップアップ -->
  225. <div id='popup' class='ol-popup'>
  226. <a href='#' id='popup-closer' class='ol-popup-closer'></a>
  227. <div id='popup-content'></div>
  228. </div>
  229. </div>
  230. <table class="table table-bordered">
  231. <tbody th:object="${mesh}">
  232. <tr>
  233. <td>
  234. <a th:text="#{return}" th:href="@{/}" class="btn btn-navy">
  235. </a>
  236. </td>
  237. </tr>
  238. </tbody>
  239. </table>
  240.  
  241. <table class="table table-bordered">
  242. <thead>
  243. <tr>
  244. <th th:text="#{status}"></th>
  245. <th th:text="#{meshcode}"></th>
  246. <th>version</th>
  247. <th th:text="#{path}"></th>
  248. <th th:text="#{editor}"></th>
  249. <th th:text="#{operation}"></th>
  250. </tr>
  251. </thead>
  252. <tbody>
  253. <tr th:each="mesh : ${meshes}" th:object="${mesh}">
  254. <td><img th:alt="*{status}" th:src="@{/img/{status}.png(status=*{status})}"></img></td>
  255. <td th:text="*{meshcode}"></td>
  256. <td th:text="*{version}"></td>
  257. <td th:text="*{path}"></td>
  258. <td><a th:text="*{username}" th:href="@{https://www.openstreetmap.org/user/{user}(user=*{username})}"></a></td>
  259. <td>
  260. <a th:text="#{download}" th:href="@{{site}{folder}/bldg/{path}(site=*{city.site},folder=*{city.folder},path=*{path})}" class="btn btn-navy">
  261. </a>
  262.  
  263. <a th:href="@{/tasks?citycode={city.citycode}&meshcode={meshcode}(city.citycode=*{city.citycode},meshcode=*{meshcode})}" class="btn btn-navy">
  264. <i class="bi bi-pencil-square" th:text="#{operation}"></i>
  265. </a>
  266. </td>
  267. </tr>
  268. </tbody>
  269. </table>
  270. </div>
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. </main>
  276. </div>
  277.  
  278. </body>
  279. </html>