This is the definition of palette:
myPalette = //modello dei quadrati (go.Palette, "myPaletteSmall",
{
nodeTemplate: myDiagram.nodeTemplate,
layout: (go.GridLayout)
});
Can i trigger in some way the click event on the grid and add a new palette on it?
Are you seeking to allow the user to add a Node at a particular place in the Diagram by having the user click there? If so, use the ClickCreatingTool. You can read its documentation and find examples of it in the sample apps.
Basically you need to set ClickCreatingTool.archetypeNodeData.
If you want to make sure the new node is aligned to the grid, you probably want to override ClickCreatingTool | GoJS API to create the part and then align it to the grid.
Uhm, with the nearest point there are some “bugs”, i try to expain this with an image:
If i click on the blue point, the nearest point on the grid coincide whit the square red filled, but i want to fill the square where i clicked.
OK, I misunderstood the purpose of what you are trying to accomplish. So indeed you don’t want the “nearest” grid point, but the one that is at the “floor”, always the top-left corner.
Are you sure you should be calling parseInt? In general one should avoid unnecessary conversions from numbers to strings or vice-versa. Just call Math.floor.
Also, it might be easier if you didn’t set Node.locationSpot at all, so that the location would just be at the top-left corner, and so that the location and the position are the same value.
Oh, you’re right! Thanks!
I’ve used parseInt to convert the float to int because the division (/) usually return a float instead of int, and this give me wrong coordinates to set the point.