解决思路:
1、创建一个不可移动的图层 : layer
2、设置不可拖动的节点node 的图层为 layer
见代码:
var box = new twaver.ElementBox(); var network = new twaver.vector.Network(box); function init() { initNetwork(); initLayer(); } function initNetwork() { var view = network.getView(); document.body.appendChild(view); network.adjustBounds({x: 0, y: 0, 1300, height: 600}); twaver.Styles.setStyle('select.color', '#57ab9a'); network.setEditInteractions(); } function initLayer() { var layerBox = box.getLayerBox(); var layer1 = new twaver.Layer('unmovable', 'unmovable layer'); // 创建一个不可移动的图层 layerBox.add(layer1); createNode(layer1, 'circle', 300, 100, 200, 200, '#57ab9a'); } function createNode(layer, shape, x, y, width, height, fillColor) { var node = new twaver.Node(); node.setLayerId(layer.getId()); // 设置节点的图层,指向不可移动的图层 node.setName('layer-' + layer.getId()); node.setStyle('body.type', 'vector'); node.setStyle('vector.fill.alpha', 0.7); node.setStyle('vector.shape', shape); node.setSize(width, height); node.setLocation(x, y); node.setStyle('vector.fill.color', fillColor); box.add(node); return node; }