ADD: add possibility to add and delete entities
This commit is contained in:
@@ -49,29 +49,44 @@ class App extends Component {
|
|||||||
|
|
||||||
if(dataFromServer.Data === "COP")
|
if(dataFromServer.Data === "COP")
|
||||||
{
|
{
|
||||||
|
if(dataFromServer.Entities === undefined)
|
||||||
|
{
|
||||||
|
dataFromServer.Entities = [];
|
||||||
|
}
|
||||||
// console.log(this.state.EntityOnFocus);
|
// console.log(this.state.EntityOnFocus);
|
||||||
var tmp = []
|
let tmp = new Array(); ;
|
||||||
if(this.state.Entities.length !== 0){
|
|
||||||
|
|
||||||
|
if(this.state.Entities !== undefined && this.state.Entities.length !== 0){
|
||||||
|
|
||||||
|
if(dataFromServer.Entities.length > 0)
|
||||||
|
{
|
||||||
dataFromServer.Entities.forEach((elementFromWS, indexWS) => {
|
dataFromServer.Entities.forEach((elementFromWS, indexWS) => {
|
||||||
|
|
||||||
|
if (this.isStored(elementFromWS.id) !== true)
|
||||||
|
{
|
||||||
|
tmp.push(elementFromWS);
|
||||||
|
}
|
||||||
this.state.Entities.forEach((elementStored, indexStore) => {
|
this.state.Entities.forEach((elementStored, indexStore) => {
|
||||||
if(elementFromWS.id === elementStored.id)
|
if(elementFromWS.id === elementStored.id)
|
||||||
{
|
{
|
||||||
|
// console.log(elementStored);
|
||||||
|
|
||||||
if(elementStored.onFocus !==true | elementStored.onFocus === undefined)
|
if(elementStored.onFocus !==true | elementStored.onFocus === undefined)
|
||||||
{
|
{
|
||||||
tmp.push(elementFromWS);
|
tmp.push(elementFromWS);
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
tmp.push(elementStored);
|
tmp.push(elementStored);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
// console.log(elementFromWS);
|
||||||
|
// tmp.push(elementFromWS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
tmp = dataFromServer.Entities;
|
tmp = dataFromServer.Entities;
|
||||||
}
|
}
|
||||||
@@ -95,6 +110,21 @@ class App extends Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
isStored(id) {
|
||||||
|
var found = false;
|
||||||
|
this.state.Entities.forEach((elementStored, indexStore) => {
|
||||||
|
if (id === elementStored.id)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return found;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
updateEntities()
|
updateEntities()
|
||||||
{
|
{
|
||||||
var msg =
|
var msg =
|
||||||
@@ -193,7 +223,7 @@ class App extends Component {
|
|||||||
|
|
||||||
<Controls Functions= {this.Functions} Client= {client} Entities= {this.state.Entities} updateEntities = {this.updateEntities} EntityOnFocus = {this.state.EntityOnFocus} PositionClicked = {this.state.PositionClicked} />
|
<Controls Functions= {this.Functions} Client= {client} Entities= {this.state.Entities} updateEntities = {this.updateEntities} EntityOnFocus = {this.state.EntityOnFocus} PositionClicked = {this.state.PositionClicked} />
|
||||||
|
|
||||||
<OpenSeaMap Entities= {this.state.Entities} updateEntities = {this.updateEntities} setEntityOnFocus = {this.setEntityOnFocus.bind(this)} setFocusPosition = {this.setFocusPosition.bind(this)}/>
|
<OpenSeaMap Entities= {this.state.Entities} Client= {client} updateEntities = {this.updateEntities} setEntityOnFocus = {this.setEntityOnFocus.bind(this)} setFocusPosition = {this.setFocusPosition.bind(this)}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,28 @@ class OpenSeaMap extends Component {
|
|||||||
// console.log("hello world");
|
// console.log("hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markerOnClick(e) {
|
||||||
|
console.log(e);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setOnFocus(e)
|
||||||
|
{
|
||||||
|
console.log(e.relatedTarget);
|
||||||
|
e.relatedTarget.dragging.enable();
|
||||||
|
e.relatedTarget.options.draggable = true;
|
||||||
|
var Ent = {
|
||||||
|
EntityID : e.relatedTarget.options.data,
|
||||||
|
NewPos : undefined
|
||||||
|
}
|
||||||
|
this.setState((state) =>({
|
||||||
|
EntityOnFocus: Ent
|
||||||
|
}))
|
||||||
|
this.props.setEntityOnFocus(Ent)
|
||||||
|
// this.draggable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
makeIcon(index, entity,props,state)
|
makeIcon(index, entity,props,state)
|
||||||
@@ -51,6 +73,7 @@ class OpenSeaMap extends Component {
|
|||||||
var isOnFocus = false;
|
var isOnFocus = false;
|
||||||
if(this.state.EntityOnFocus !== undefined){
|
if(this.state.EntityOnFocus !== undefined){
|
||||||
// console.log(entity.id+ " " , this.state.EntityOnFocus);
|
// console.log(entity.id+ " " , this.state.EntityOnFocus);
|
||||||
|
// console.log(props+ " " , this.state.EntityOnFocus);
|
||||||
|
|
||||||
if(entity.id === this.state.EntityOnFocus.EntityID)
|
if(entity.id === this.state.EntityOnFocus.EntityID)
|
||||||
{
|
{
|
||||||
@@ -63,6 +86,7 @@ class OpenSeaMap extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var icon;
|
var icon;
|
||||||
icon = createIcon(entity.Type,entity.Side)
|
icon = createIcon(entity.Type,entity.Side)
|
||||||
return (
|
return (
|
||||||
@@ -74,23 +98,30 @@ class OpenSeaMap extends Component {
|
|||||||
contextmenuItems={[{
|
contextmenuItems={[{
|
||||||
text:"Edit",
|
text:"Edit",
|
||||||
index:0,
|
index:0,
|
||||||
callback: function() {
|
callback: this.setOnFocus.bind(this),
|
||||||
// this.setState({
|
},{
|
||||||
// EntityOnFocus:entity.id
|
|
||||||
// })
|
|
||||||
var Ent = {
|
|
||||||
EntityID : entity.id,
|
|
||||||
NewPos : undefined
|
|
||||||
}
|
|
||||||
state.EntityOnFocus = Ent;
|
|
||||||
props.setEntityOnFocus(Ent)
|
|
||||||
// console.log(state.EntityOnFocus);
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
text:"Delete",
|
text:"Delete",
|
||||||
|
index: 1,
|
||||||
|
callback: function() {
|
||||||
|
var msg =
|
||||||
|
{
|
||||||
|
Data: "Entity",
|
||||||
|
Type: "Delete",
|
||||||
|
ID: entity.id,
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(msg));
|
||||||
|
state.EntityOnFocus = undefined;
|
||||||
|
props.setEntityOnFocus(undefined)
|
||||||
|
|
||||||
|
props.Client.send(JSON.stringify(msg))
|
||||||
|
},
|
||||||
// separator: true,
|
// separator: true,
|
||||||
index: 1
|
|
||||||
}, {
|
}, {
|
||||||
|
text:"Test",
|
||||||
|
callback: this.markerOnClick.bind(this),
|
||||||
|
// separator: true,
|
||||||
|
index: 2
|
||||||
|
}, {
|
||||||
text:"Exit",
|
text:"Exit",
|
||||||
callback: function()
|
callback: function()
|
||||||
{
|
{
|
||||||
@@ -98,7 +129,7 @@ class OpenSeaMap extends Component {
|
|||||||
props.setEntityOnFocus(undefined);
|
props.setEntityOnFocus(undefined);
|
||||||
},
|
},
|
||||||
// separator: true,
|
// separator: true,
|
||||||
index: 2
|
index: 3
|
||||||
}]}
|
}]}
|
||||||
// contextmenuItems: [{
|
// contextmenuItems: [{
|
||||||
// text: 'Circle 1',
|
// text: 'Circle 1',
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function EntityControl(props)
|
|||||||
const [PositionDragged, setPositionDragged] = useState(false);
|
const [PositionDragged, setPositionDragged] = useState(false);
|
||||||
// const [Speed, setSpeed] = useState();
|
// const [Speed, setSpeed] = useState();
|
||||||
|
|
||||||
const [formData, setFormData] = useState({name: "",course: "" ,speed: 0,position: [0,0],height:0});
|
const [formData, setFormData] = useState({name: "",course: 0 ,speed: 0,position: [0,0],height:0});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ const handleClick = (e) => {
|
|||||||
{
|
{
|
||||||
props.Entity.onFocus = undefined;
|
props.Entity.onFocus = undefined;
|
||||||
}
|
}
|
||||||
setFormData({name:'',course:'',speed:'',position:['','']})
|
setFormData({name:'',course:0,speed:0,position:[0,0],height:0})
|
||||||
setEntity(undefined)
|
setEntity(undefined)
|
||||||
props.Functions.resetEntityOnFocus();
|
props.Functions.resetEntityOnFocus();
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import round from '../../Utils';
|
|||||||
|
|
||||||
class Tracklist extends React.Component
|
class Tracklist extends React.Component
|
||||||
{
|
{
|
||||||
|
|
||||||
render()
|
render()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ state = {
|
|||||||
// console.log('reply', dataFromServer);
|
// console.log('reply', dataFromServer);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if (this.props.Entities == undefined)
|
||||||
|
{
|
||||||
|
this.props.Entities = new Array();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user