From d3eb230d4cf05a66c50883ab795f1d31f8aacbf7 Mon Sep 17 00:00:00 2001 From: SongWei Date: Sun, 16 Feb 2020 17:09:27 +1100 Subject: [PATCH] coord --- c/lib.c | 4 ++++ front/index.js | 62 ++++++++++++++++++++++++++++++++++---------------- server.lisp | 24 ++++++++++++++++--- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/c/lib.c b/c/lib.c index bf587f0..a72c25b 100644 --- a/c/lib.c +++ b/c/lib.c @@ -47,6 +47,10 @@ int RVExtensionArgs(char *output, int outputSize, /* Now specify the POST data */ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, output_string); + struct curl_slist *headers = NULL; + headers = curl_slist_append(headers, "Expect:"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ diff --git a/front/index.js b/front/index.js index bf43506..ed64f06 100644 --- a/front/index.js +++ b/front/index.js @@ -1,32 +1,56 @@ import L from 'leaflet'; import 'leaflet/dist/leaflet.css'; +import * as marker from './marker.js'; let map = L.map('map', { - crs: L.CRS.Simple, - minZoom: -4 + crs: L.CRS.Simple, + minZoom: -4 }); let bounds = [[0,0], [15360, 15360]]; let image = L.imageOverlay('./maps/Tanoa.png', bounds).addTo(map); map.fitBounds(bounds); -function makeIcon() { - let markerIcon = L.icon({ - iconSize: [30, 30], - iconAnchor: [15, 15], - iconUrl: './marker/dot.png' - }); - return markerIcon; + +// let marker1 = marker.makeMarker([0, 0], +// 'loc_blue', +// "测试"); +// marker1.addTo(map); +// let marker2= marker.makeMarker([1000, 2000], +// 'loc_red', +// "测试2"); +// marker2.addTo(map); + +let UNITS_POS_MARKER = []; + +function update_units_pos () { + let sideToType = { + "WEST": "blue", + "EAST": "red", + "GUER": "green", + "CIV": "purple" + }; + + fetch('/units-pos') + .then((response) => { + return response.json(); + }) + .then((units_pos_array) => { + for(let marker of UNITS_POS_MARKER) { + map.removeLayer(marker); + } + UNITS_POS_MARKER = []; + + for(let u of units_pos_array) { + let pos_marker = marker.makeUnitPos( + u.position, + sideToType[u.side] + ); + UNITS_POS_MARKER.push(pos_marker); + pos_marker.addTo(map); + } + }); } -function makeMarker(coord, text) { - let [x, y] = coord; - let marker = L.marker(L.latLng(y, x), {icon: makeIcon(text)}); - // https://gis.stackexchange.com/questions/59571/how-to-add-text-only-labels-on-leaflet-map-with-no-icon - marker.bindTooltip(text, {permanent: true, offset: [15, 0]}); - return marker; -} - -let marker1 = makeMarker([0, 0], "测试aaaaaaaaaaaaaaaaa bbbbbbbbbb cccc"); -marker1.addTo(map); +setInterval(update_units_pos, 1000); diff --git a/server.lisp b/server.lisp index 76e206b..1edb637 100644 --- a/server.lisp +++ b/server.lisp @@ -41,12 +41,29 @@ (let* ((decoded-stream (flex:make-flexi-stream (getf env :raw-body) :external-format :utf-8)) (body (read-string-stream decoded-stream))) - (format t "~&post body:~A~%" body) + ;;(format t "~&post body:~A~%" body) (let ((parsed (json:decode-json-from-string body))) - (setf *marker-info* parsed) - (print parsed)) + (setf *marker-info* (nth 0 parsed)) + (setf *units-info* (nth 1 parsed))) + ;; (print parsed)) (route-hello-world nil))) +(defparameter *units-info* + '(("WEST" (1000.0 1000.0 0.0)) + ("EAST" (2222.0 1555.0 0.0)))) + +(defun route-units-pos (env) + (declare (ignore env)) + (let* ((tagged-units-pos + (mapcar (lambda (u) + (destructuring-bind (side position) u + `(("side" . ,side) + ("position" . ,position)))) + *units-info*)) + (json (json:encode-json-to-string tagged-units-pos))) + `(200 (:content-type "application/json") + (,json)))) + (defun dispatch (request-path dispatch-table) ;; path: request url ;; dispatch-table: '(matcher function) @@ -65,6 +82,7 @@ (defparameter +dispatch-table+ `(("^/$" ,#'route-hello-world) ("^/post-test$" ,#'route-display-post) + ("^/units-pos$" ,#'route-units-pos) (,(concatenate 'string "^" +static-prefix+ ".*$") ,#'serve-static-file) (nil ,#'route-not-found)))