Calculating node position updated

This commit is contained in:
piotrpekala7
2020-05-04 12:35:44 +02:00
parent 9594e397e5
commit 6b6ac2f312
2 changed files with 28 additions and 11 deletions

View File

@ -7,6 +7,7 @@ import { Template } from '../../models/template';
import { Project } from '../../models/project'; import { Project } from '../../models/project';
import { TemplateService } from '../../services/template.service'; import { TemplateService } from '../../services/template.service';
import { MapScaleService } from '../../services/mapScale.service'; import { MapScaleService } from '../../services/mapScale.service';
import { SymbolService } from '../../services/symbol.service';
@Component({ @Component({
selector: 'app-template', selector: 'app-template',
@ -27,10 +28,14 @@ export class TemplateComponent implements OnInit {
movementX: number; movementX: number;
movementY: number; movementY: number;
startX: number;
startY: number;
constructor( constructor(
private dialog: MatDialog, private dialog: MatDialog,
private templateService: TemplateService, private templateService: TemplateService,
private scaleService: MapScaleService private scaleService: MapScaleService,
private symbolService: SymbolService
) {} ) {}
ngOnInit() { ngOnInit() {
@ -38,6 +43,7 @@ export class TemplateComponent implements OnInit {
this.filteredTemplates = listOfTemplates; this.filteredTemplates = listOfTemplates;
this.templates = listOfTemplates; this.templates = listOfTemplates;
}); });
this.symbolService.list(this.server);
} }
filterTemplates(event) { filterTemplates(event) {
@ -55,20 +61,27 @@ export class TemplateComponent implements OnInit {
dragStart(ev) { dragStart(ev) {
let elemRect = (event.target as HTMLElement).getBoundingClientRect(); let elemRect = (event.target as HTMLElement).getBoundingClientRect();
this.startX = (event as MouseEvent).clientX;
this.startY = (event as MouseEvent).clientY;
this.movementY = elemRect.top - (event as MouseEvent).clientY; this.movementY = elemRect.top - (event as MouseEvent).clientY;
this.movementX = elemRect.left - (event as MouseEvent).clientX; this.movementX = elemRect.left - (event as MouseEvent).clientX;
} }
dragEnd(ev, template) { dragEnd(ev, template: Template) {
let scale = this.scaleService.getScale(); this.symbolService.raw(this.server, template.symbol.substring(1)).subscribe((symbolSvg: string) => {
let nodeAddedEvent: NodeAddedEvent = { let width = +symbolSvg.split("width=\"")[1].split("\"")[0];
template: template, let scale = this.scaleService.getScale();
server: 'local',
numberOfNodes: 1, let nodeAddedEvent: NodeAddedEvent = {
x: ((event as MouseEvent).clientX - this.project.scene_width/2 + window.scrollX + this.movementX) * scale, //template.width template: template,
y: ((event as MouseEvent).clientY - this.project.scene_height/2 + window.scrollY + this.movementY) * scale server: 'local',
}; numberOfNodes: 1,
this.onNodeCreation.emit(nodeAddedEvent); x: this.startX + ev.x - this.project.scene_width/2 - (width/2) + window.scrollX ,
y: this.startY + ev.y - this.project.scene_height/2 + window.scrollY
};
this.onNodeCreation.emit(nodeAddedEvent);
});
} }
openDialog() { openDialog() {

View File

@ -19,6 +19,10 @@ export class SymbolService {
return this.symbols.getValue().find((symbol: Symbol) => symbol.symbol_id === symbol_id); return this.symbols.getValue().find((symbol: Symbol) => symbol.symbol_id === symbol_id);
} }
getByFilename(symbol_filename: string) {
return this.symbols.getValue().find((symbol: Symbol) => symbol.filename === symbol_filename);
}
add(server: Server, symbolName: string, symbol: string) { add(server: Server, symbolName: string, symbol: string) {
this.cache = null; this.cache = null;
return this.httpServer.post(server, `/symbols/${symbolName}/raw`, symbol) return this.httpServer.post(server, `/symbols/${symbolName}/raw`, symbol)