ADD: added function for the dynamic creation of entities
This commit is contained in:
@@ -14,12 +14,10 @@ class App extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
name: " ",
|
Entities: [
|
||||||
History: [],
|
// { id: 1, name: "Apple", position: [51.505, -0.10],Type: "Friend" },
|
||||||
Position: [
|
// { id: 2, name: "Oranges", position: [51.505, -0.11],Type: "Hostile"},
|
||||||
{ id: 1, name: "Apple", position: [51.505, -0.10],Type: "Friend" },
|
// { id: 3, name: "Grapes", position: [51.505, -0.12],Type: "Friend"}
|
||||||
{ id: 2, name: "Oranges", position: [51.505, -0.11],Type: "Hostile"},
|
|
||||||
{ id: 3, name: "Grapes", position: [51.505, -0.12],Type: "Friend"}
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
@@ -32,15 +30,34 @@ class App extends Component {
|
|||||||
|
|
||||||
connect((msg) => {
|
connect((msg) => {
|
||||||
console.log("New Message")
|
console.log("New Message")
|
||||||
console.log(msg)
|
console.log(msg.data)
|
||||||
|
var jsonMSG;
|
||||||
|
try {
|
||||||
|
jsonMSG = JSON.parse(msg.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
if(jsonMSG["Type"] == "COP"){
|
||||||
|
var Entities = Array.from(jsonMSG["Entities"])
|
||||||
|
if(Array.isArray(Entities))
|
||||||
|
{
|
||||||
|
this.setState({
|
||||||
|
Entities:Entities
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// this.state.Entities = jsonMSG
|
||||||
|
// var jsonmsg = JSON.parse(msg);
|
||||||
this.setState(prevState => ({
|
this.setState(prevState => ({
|
||||||
chatHistory: [...this.state.History, msg]
|
// chatHistory: [...this.state.History, msg]
|
||||||
|
// chatHistory: [...this.state.History, msg]
|
||||||
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
console.log(this.state);
|
console.log(this.state.Entities);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// send() {
|
// send() {
|
||||||
// console.log("hello");
|
// console.log("hello");
|
||||||
@@ -63,7 +80,7 @@ class App extends Component {
|
|||||||
{name}
|
{name}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<OpenSeaMap Positions= {this.state.Position} parentCallback = {this.handleCallback}/>
|
<OpenSeaMap Entities= {this.state.Entities} parentCallback = {this.handleCallback}/>
|
||||||
|
|
||||||
|
|
||||||
<button onClick={this.send}>Hit</button>
|
<button onClick={this.send}>Hit</button>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// import { useMapEvents } from 'react-leaflet/hooks'
|
// import { useMapEvents } from 'react-leaflet/hooks'
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { MapContainer, TileLayer,Marker, Popup } from 'react-leaflet'
|
import { MapContainer, TileLayer,Marker, Popup } from 'react-leaflet'
|
||||||
import { friend,Hostile, iconShip } from "./icon";
|
import { friend,Hostile, iconShip,createIcon } from "./icon";
|
||||||
import "./OpenSeaMap.scss"
|
import "./OpenSeaMap.scss"
|
||||||
|
|
||||||
|
|
||||||
@@ -13,18 +13,19 @@ class OpenSeaMap extends Component {
|
|||||||
makeIcon(index, entity)
|
makeIcon(index, entity)
|
||||||
{
|
{
|
||||||
var icon;
|
var icon;
|
||||||
switch (entity.Type)
|
// switch (entity.Side)
|
||||||
{
|
// {
|
||||||
case "Friend":
|
// case "Friend":
|
||||||
icon = friend;
|
// icon = friend;
|
||||||
break;
|
// break;
|
||||||
case "Hostile":
|
// case "Hostile":
|
||||||
icon = Hostile;
|
// icon = Hostile;
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
|
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
icon = createIcon(entity.Type,entity.Side)
|
||||||
return (
|
return (
|
||||||
<Marker name={"test"} key={index} icon={icon} position={entity.position} >
|
<Marker name={"test"} key={index} icon={icon} position={entity.position} >
|
||||||
<Popup>
|
<Popup>
|
||||||
@@ -51,7 +52,7 @@ class OpenSeaMap extends Component {
|
|||||||
<TileLayer
|
<TileLayer
|
||||||
url="https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png" />
|
url="https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png" />
|
||||||
{/* {positions} */}
|
{/* {positions} */}
|
||||||
{this.props.Positions.map((pos, index) => (
|
{this.props.Entities.map((pos, index) => (
|
||||||
this.makeIcon(index,pos)
|
this.makeIcon(index,pos)
|
||||||
// <Marker name={"test"} key={index} icon={friend} position={pos.position} >
|
// <Marker name={"test"} key={index} icon={friend} position={pos.position} >
|
||||||
// <Popup>
|
// <Popup>
|
||||||
|
|||||||
@@ -8,26 +8,68 @@ const iconShip = new Icon({
|
|||||||
popupAnchor: [-25, -40],
|
popupAnchor: [-25, -40],
|
||||||
});
|
});
|
||||||
|
|
||||||
const iconSize = {
|
const HostileLetter = "H";
|
||||||
"Team/Crew": 5,
|
const FriendLetter = "F";
|
||||||
"Squad": 10,
|
const NeutralLetter = "N";
|
||||||
"Section": 15,
|
|
||||||
"Platoon/detachment": 20,
|
const AirLetter = "A";
|
||||||
"Company/battery/troop": 25,
|
const SurfaceLetter = "S";
|
||||||
"Battalion/squadron": 30,
|
const SubsurfaceLetter = "U";
|
||||||
"Regiment/group": 35,
|
|
||||||
"Brigade": 40,
|
const Size = 25;
|
||||||
"Division": 45,
|
|
||||||
"Corps/MEF": 50,
|
function createIcon(Type , Side )
|
||||||
"Army": 55,
|
{
|
||||||
"Army Group/front": 60,
|
var TypeLetter = "S";
|
||||||
"Region/Theater": 65,
|
var SideLetter = "N";
|
||||||
"Command": 70
|
switch (Side) {
|
||||||
};
|
case "Hostile":
|
||||||
|
SideLetter = HostileLetter;
|
||||||
|
break;
|
||||||
|
case "Friend":
|
||||||
|
SideLetter = FriendLetter;
|
||||||
|
break;
|
||||||
|
case "Neutral":
|
||||||
|
SideLetter = NeutralLetter;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
SideLetter = "N";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (Type) {
|
||||||
|
case "Air":
|
||||||
|
TypeLetter = AirLetter;
|
||||||
|
break;
|
||||||
|
case "Surface":
|
||||||
|
TypeLetter = SurfaceLetter;
|
||||||
|
break;
|
||||||
|
case "Subsurface":
|
||||||
|
TypeLetter = SubsurfaceLetter;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
SideLetter = "N";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var IconS = new ms.Symbol(
|
||||||
|
"S"+SideLetter+TypeLetter+"*"+"--------"
|
||||||
|
)
|
||||||
|
IconS = IconS.setOptions({ size: 25 });
|
||||||
|
|
||||||
|
var Symbol = new Icon({
|
||||||
|
iconUrl: IconS.toDataURL(),
|
||||||
|
iconAnchor: [IconS.getAnchor().x, IconS.getAnchor().y],
|
||||||
|
})
|
||||||
|
|
||||||
|
return Symbol
|
||||||
|
}
|
||||||
|
|
||||||
var Friend = new ms.Symbol(
|
var Friend = new ms.Symbol(
|
||||||
"SFP---------", {
|
"SFS*--------", {
|
||||||
uniqueDesignation: "Friend"
|
// uniqueDesignation: "Friend"
|
||||||
})
|
})
|
||||||
// Now that we have a symbol we can ask for the echelon and set the symbol size
|
// Now that we have a symbol we can ask for the echelon and set the symbol size
|
||||||
Friend = Friend.setOptions({ size: 25 });
|
Friend = Friend.setOptions({ size: 25 });
|
||||||
@@ -39,7 +81,7 @@ const friend = new Icon({
|
|||||||
|
|
||||||
|
|
||||||
var hostile = new ms.Symbol(
|
var hostile = new ms.Symbol(
|
||||||
"SHP---------", {
|
"SHU*---------", {
|
||||||
uniqueDesignation: "Hostile"
|
uniqueDesignation: "Hostile"
|
||||||
})
|
})
|
||||||
// Now that we have a symbol we can ask for the echelon and set the symbol size
|
// Now that we have a symbol we can ask for the echelon and set the symbol size
|
||||||
@@ -50,4 +92,4 @@ const Hostile = new Icon({
|
|||||||
iconAnchor: [hostile.getAnchor().x, hostile.getAnchor().y],
|
iconAnchor: [hostile.getAnchor().x, hostile.getAnchor().y],
|
||||||
});
|
});
|
||||||
|
|
||||||
export { iconShip, friend,Hostile };
|
export { iconShip, friend,Hostile,createIcon };
|
||||||
@@ -1,12 +1,31 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import './controls.css'
|
import './controls.css'
|
||||||
|
import { sendMsg } from '../api';
|
||||||
|
|
||||||
class Controls extends React.Component
|
class Controls extends React.Component
|
||||||
{
|
{
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.ws = props.ws;
|
||||||
|
|
||||||
|
// This binding is necessary to make `this` work in the callback
|
||||||
|
}
|
||||||
|
getMessage()
|
||||||
|
{
|
||||||
|
var msg =
|
||||||
|
{
|
||||||
|
Type: "Request",
|
||||||
|
Data: "COP"
|
||||||
|
|
||||||
|
}
|
||||||
|
sendMsg(JSON.stringify(msg));
|
||||||
|
console.log("test");
|
||||||
|
|
||||||
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="controls">
|
<div className="controls">
|
||||||
My Application!
|
<button onClick={this.getMessage}> click me!</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user