Position of shapes/tools initially at the click of icon


#1

Hi.I want to know whether we can set the default position for the initialization of shapes and tools in bpmn. Let me explain.I want shapes to appear in the middle of the canvas when clicking the any shape icon on the palette.Currently when clicking any icon in the palette whether it is custom or default shape,user has to drag the shape from the palette onto the canvas.Can it be possible that if user clicks the icon,the shape automatically appears on the canvas,some point visible not behind the palette ?if you so,kindly let me know

Thanks


#2

I guess you’d have to create a custom palette.

Try the example for custom shapes, where a custom palette is used.

You can copy the code from BPMNjs’ palette in your custom palette and change what you want. So you could change the default placing.


#3

thanks for your reply.Actually i have gone through the custom Palette code and in function `

createAction(type, group, className, title, options) 
  { 
      function createListener(event,className) 
      {
        var shape = elementFactory.createShape(assign({ type: type }, options));

        if (options) {
          shape.businessObject.di.isExpanded = options.isExpanded;
        }

        create.start(event, shape);
      }

    var shortType = type.replace(/^bpmn:/, '');
    return {
      group: group,
      className: className,
      title: title || 'Create ' + shortType,
      action: {
        dragstart: createListener,
        click: createListener
      }
    };}

`
there are no attributes which are assigning the x and y co-ordinates of any tool.Moreover i have also gone through the code in ElementFactory.js and have not found any clue
Thanks


#4

You’d have to specify a different click function that doesn’t call create.start but instead calls something like modeling.createShape with the default position specified. Have a look at how the modeling API works.


#5

can you kindly send me the references for the modeling API working ?


#6

Yes.can you tell me in which file create.start is being defined?


#8

here you can find the Modeling#createShape method. You have to use this to specify a default position.