coord
This commit is contained in:
parent
e8db70c628
commit
d3eb230d4c
4
c/lib.c
4
c/lib.c
|
@ -47,6 +47,10 @@ int RVExtensionArgs(char *output, int outputSize,
|
||||||
/* Now specify the POST data */
|
/* Now specify the POST data */
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, output_string);
|
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 */
|
/* Perform the request, res will get the return code */
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
/* Check for errors */
|
/* Check for errors */
|
||||||
|
|
|
@ -1,32 +1,56 @@
|
||||||
import L from 'leaflet';
|
import L from 'leaflet';
|
||||||
import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
import * as marker from './marker.js';
|
||||||
|
|
||||||
let map = L.map('map', {
|
let map = L.map('map', {
|
||||||
crs: L.CRS.Simple,
|
crs: L.CRS.Simple,
|
||||||
minZoom: -4
|
minZoom: -4
|
||||||
});
|
});
|
||||||
|
|
||||||
let bounds = [[0,0], [15360, 15360]];
|
let bounds = [[0,0], [15360, 15360]];
|
||||||
let image = L.imageOverlay('./maps/Tanoa.png', bounds).addTo(map);
|
let image = L.imageOverlay('./maps/Tanoa.png', bounds).addTo(map);
|
||||||
map.fitBounds(bounds);
|
map.fitBounds(bounds);
|
||||||
|
|
||||||
function makeIcon() {
|
|
||||||
let markerIcon = L.icon({
|
// let marker1 = marker.makeMarker([0, 0],
|
||||||
iconSize: [30, 30],
|
// 'loc_blue',
|
||||||
iconAnchor: [15, 15],
|
// "测试");
|
||||||
iconUrl: './marker/dot.png'
|
// marker1.addTo(map);
|
||||||
});
|
// let marker2= marker.makeMarker([1000, 2000],
|
||||||
return markerIcon;
|
// '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) {
|
setInterval(update_units_pos, 1000);
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
24
server.lisp
24
server.lisp
|
@ -41,12 +41,29 @@
|
||||||
(let* ((decoded-stream
|
(let* ((decoded-stream
|
||||||
(flex:make-flexi-stream (getf env :raw-body) :external-format :utf-8))
|
(flex:make-flexi-stream (getf env :raw-body) :external-format :utf-8))
|
||||||
(body (read-string-stream decoded-stream)))
|
(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)))
|
(let ((parsed (json:decode-json-from-string body)))
|
||||||
(setf *marker-info* parsed)
|
(setf *marker-info* (nth 0 parsed))
|
||||||
(print parsed))
|
(setf *units-info* (nth 1 parsed)))
|
||||||
|
;; (print parsed))
|
||||||
(route-hello-world nil)))
|
(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)
|
(defun dispatch (request-path dispatch-table)
|
||||||
;; path: request url
|
;; path: request url
|
||||||
;; dispatch-table: '(matcher function)
|
;; dispatch-table: '(matcher function)
|
||||||
|
@ -65,6 +82,7 @@
|
||||||
(defparameter +dispatch-table+
|
(defparameter +dispatch-table+
|
||||||
`(("^/$" ,#'route-hello-world)
|
`(("^/$" ,#'route-hello-world)
|
||||||
("^/post-test$" ,#'route-display-post)
|
("^/post-test$" ,#'route-display-post)
|
||||||
|
("^/units-pos$" ,#'route-units-pos)
|
||||||
(,(concatenate 'string "^" +static-prefix+ ".*$") ,#'serve-static-file)
|
(,(concatenate 'string "^" +static-prefix+ ".*$") ,#'serve-static-file)
|
||||||
(nil ,#'route-not-found)))
|
(nil ,#'route-not-found)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue