@@ -275,7 +275,7 @@ function add_text() {
275
275
}
276
276
window . add_text = add_text ;
277
277
278
- function add_floorplan_object ( top , left , width , height , unit , fill , rotation , object_id , object_name , object_type , status ) {
278
+ function add_floorplan_object ( top , left , width , height , unit , fill , rotation , object_id , object_name , object_type , status , image ) {
279
279
var object_width ;
280
280
var object_height ;
281
281
if ( ! width || ! height || ! unit ) {
@@ -300,44 +300,89 @@ function add_floorplan_object(top, left, width, height, unit, fill, rotation, ob
300
300
console . log ( object_height )
301
301
}
302
302
document . getElementById ( `object_${ object_type } _${ object_id } ` ) . remove ( ) ;
303
- var rect = new fabric . Rect ( {
304
- top : top ,
305
- name : "rectangle" ,
306
- left : left ,
307
- width : object_width ,
308
- height : object_height ,
309
- fill : fill ,
310
- opacity : 0.8 ,
311
- lockRotation : false ,
312
- originX : "center" ,
313
- originY : "center" ,
314
- cornerSize : 15 ,
315
- hasRotatingPoint : true ,
316
- perPixelTargetFind : true ,
317
- minScaleLimit : 1 ,
318
- maxWidth : canvasWidth ,
319
- maxHeight : canvasHeight ,
320
- centeredRotation : true ,
321
- custom_meta : {
322
- "object_type" : object_type ,
323
- "object_id" : object_id ,
324
- "object_name" : object_name ,
325
- "object_url" : "/dcim/" + object_type + "s/" + object_id + "/" ,
326
- } ,
327
- } ) ;
303
+ /* if we have an image, we display the text below, otherwise we display the text within */
304
+ var rect , text_offset = 0 ;
305
+ if ( ! image ) {
306
+ rect = new fabric . Rect ( {
307
+ top : top ,
308
+ name : "rectangle" ,
309
+ left : left ,
310
+ width : object_width ,
311
+ height : object_height ,
312
+ fill : fill ,
313
+ opacity : 0.8 ,
314
+ lockRotation : false ,
315
+ originX : "center" ,
316
+ originY : "center" ,
317
+ cornerSize : 15 ,
318
+ hasRotatingPoint : true ,
319
+ perPixelTargetFind : true ,
320
+ minScaleLimit : 1 ,
321
+ maxWidth : canvasWidth ,
322
+ maxHeight : canvasHeight ,
323
+ centeredRotation : true ,
324
+ custom_meta : {
325
+ "object_type" : object_type ,
326
+ "object_id" : object_id ,
327
+ "object_name" : object_name ,
328
+ "object_url" : "/dcim/" + object_type + "s/" + object_id + "/" ,
329
+ } ,
330
+ } ) ;
331
+ } else {
332
+ object_height = object_width ;
333
+ text_offset = object_height / 2 + 4 ;
334
+ rect = new fabric . Image ( null , {
335
+ top : top ,
336
+ name : "rectangle" ,
337
+ left : left ,
338
+ width : object_width ,
339
+ height : object_height ,
340
+ opacity : 1 ,
341
+ lockRotation : false ,
342
+ originX : "center" ,
343
+ originY : "center" ,
344
+ cornerSize : 15 ,
345
+ hasRotatingPoint : true ,
346
+ perPixelTargetFind : true ,
347
+ minScaleLimit : 1 ,
348
+ maxWidth : canvasWidth ,
349
+ maxHeight : canvasHeight ,
350
+ centeredRotation : true ,
351
+ shadow : new fabric . Shadow ( {
352
+ color : "red" ,
353
+ blur : 15 ,
354
+ } ) ,
355
+ custom_meta : {
356
+ "object_type" : object_type ,
357
+ "object_id" : object_id ,
358
+ "object_name" : object_name ,
359
+ "object_url" : "/dcim/" + object_type + "s/" + object_id + "/" ,
360
+ } ,
361
+ } ) ;
362
+ rect . setSrc ( "/media/" + image , function ( img ) {
363
+ img . scaleX = object_width / img . width ;
364
+ img . scaleY = object_height / img . height ;
365
+ canvas . renderAll ( ) ;
366
+ } ) ;
367
+ }
328
368
329
- var text = new fabric . IText ( object_name , {
369
+ var text = new fabric . Textbox ( object_name , {
330
370
fontFamily : "Courier New" ,
331
371
fontSize : 16 ,
372
+ splitByGrapheme : text_offset ? null : true ,
332
373
fill : "#FFFF" ,
374
+ width : object_width ,
333
375
textAlign : "center" ,
334
376
originX : "center" ,
335
377
originY : "center" ,
336
378
left : left ,
337
- top : top ,
379
+ top : top + text_offset ,
338
380
excludeFromExport : false ,
339
381
includeDefaultValues : true ,
340
382
centeredRotation : true ,
383
+ stroke : "#000" ,
384
+ strokeWidth : 2 ,
385
+ paintFirst : 'stroke' ,
341
386
custom_meta : {
342
387
"text_type" : "name" ,
343
388
}
@@ -352,10 +397,14 @@ function add_floorplan_object(top, left, width, height, unit, fill, rotation, ob
352
397
originX : "center" ,
353
398
originY : "center" ,
354
399
left : left ,
355
- top : top + 16 ,
400
+ top : top + text_offset + 16 ,
356
401
excludeFromExport : false ,
357
402
includeDefaultValues : true ,
358
403
centeredRotation : true ,
404
+ shadow : text_offset ? new fabric . Shadow ( {
405
+ color : '#FFF' ,
406
+ blur : 1
407
+ } ) : null ,
359
408
custom_meta : {
360
409
"text_type" : "status" ,
361
410
}
0 commit comments