%%PageItemTitle%%

VectorDraw Web Library

JsPropertiesExtractor Send comments on this topic.
MergeDocument Method
See Also  Example
vdWebLibrary Namespace > vdrawObj Class : MergeDocument Method
filename
Required. A filename url
finishCallback
Optional. If present and not is null represents a user function callback to be fired when merge finished
mergeFlags
Optional. If present must be one of MERGEFLAGS_DEFAULT , MERGEFLAGS_REPLACE_EXISITING. Represents FLags that control how the merge is done.If not present MERGEFLAGS_DEFAULT is used.
blobstr
Optional.If present and not is null represents the contents of filename that used to be loaded instead of downlonding the paseed filename.
Merge the model entities of the passed document to this selected document

Syntax

JScript 
public function MergeDocument( 
   filename : String,
   finishCallback : MergeDocumentFinshedDelegate,
   mergeFlags : int,
   blobstr : String
);

Parameters

filename
Required. A filename url
finishCallback
Optional. If present and not is null represents a user function callback to be fired when merge finished
mergeFlags
Optional. If present must be one of MERGEFLAGS_DEFAULT , MERGEFLAGS_REPLACE_EXISITING. Represents FLags that control how the merge is done.If not present MERGEFLAGS_DEFAULT is used.
blobstr
Optional.If present and not is null represents the contents of filename that used to be loaded instead of downlonding the paseed filename.

Example

User add a new layer and a new line and we and merge them later on a basic drawing.

You can open the drawing 'basic.vds' (The layer 'user' is empty)

Add some entities to layer 'user'

Partial save only the entities from layer 'user' (using entity.excludeFromSave = true; to all other entities) as 'user.vds'

Then

Open the drawing 'basic.vds' (The layer 'user' is empty)

Call the vdcanvas.MergeDocument('user.vds',mergedocumentfinished, vdConst.MERGEFLAGS_DEFAULT, partialSavedFileData);

The entities of Model of the 'user.vds' will be added to existing document Model entities.

This method will only work for entities that come from a Document A and are going to be loaded to Document A again.

It will not work for entities from a Different drawing.

Suppose that in the HTML page we have five buttons.

Button 1.OpenBasic -> Load a basic.vds file which contains a circle,an ellipse,a text,a rectangle and a spline.

Button 2.Line -> Creates a new layer and a new line.

Button 3.Save -> Save the new layer and line in a virtual user.vds which is actually not exists

Button 4.reOpenBasic -> Reopens the basic.vds without the new layer and new line.

Button 5.Merge -> Merge the basic.vds with the user.vds where we previous added some new entities.

C#Copy Code
var vdcanvas;         
function _onprompt(sender, msg) { 
   printInfo('info', msg); 

this.printInfo = function (infoId, text) { 
 
   if (text === undefined || text === null) return; 
   var info = document.getElementById(infoId); 
   if (info == undefined) return; 
   info.innerHTML = ":" + text; 
}        
function printInfo(text) {  
   document.getElementById("info").innerHTML = ":" + text; 
}        
 
var partialSavedFileData; 
function vdrawInitPageLoad() { 
                 
                   vdcanvas = vdmanager.AttachCanvas("canvas");     
   vdcanvas.vdAfterOpenDocument = _vdAfterOpenDocument; //defines the function that will be fire when a web control document loaded. 
   vdcanvas.vdAfterSaveDocument = _vdAfterSaveDocument; //defines the function that will be fire when a web control document data saved completed. 
    

 
function OpenBasic() { // Here we open the main document 
   setTimeout(vdcanvas.SelectDocument("basic.vds")); 
                   vdcanvas.vdPrompt = _onprompt; 

function _vdAfterOpenDocument() {}//fire when basic.vds document loaded. 
 
 function line() { // We add a new layer and a new line  
   vdcanvas.SetActiveLayer( vdcanvas.AddLayer('user')); 
   vdcanvas.scriptCommand.line(); 

 
function save() { //We save the layer and the line that we previous added 
    vdcanvas.SaveDocument(); 

function _vdAfterSaveDocument(saveData) { 
 // Developer can also save the datastream in a server url 
    partialSavedFileData = saveData.dataStream; 

 
function reOpenBasic(){ //We reopen the basic drawing 
   vdcanvas.SelectDocument("basic.vds"); 

 
function merge(){ //We merge the user.vds with the basic.vds 
  // Merge the documents 
   vdcanvas.vdAfterOpenDocument = _vdAfterOpenDocumentForMerge; 
   vdcanvas.SelectDocument("basic.vds"); 

function _vdAfterOpenDocumentForMerge() { 
 
   vdcanvas.MergeDocument('user.vds',mergedocumentfinished, vdConst.MERGEFLAGS_DEFAULT, partialSavedFileData); 
   vdcanvas.vdAfterOpenDocument =_vdAfterOpenDocument; 

function mergedocumentfinished(mergeargs){ 
  //you can get the following properties from passed mergeargs 
  var canvasreference = mergeargs.vdcanvas; 
  var mergeFlags = mergeargs.mergeFlags; 
  var mergedocument = mergeargs.mergedoc; 
  //for example get the number of model entities of merged document 
  var nents = mergedocument.Model.Entities.Items.length; 
}        

Remarks

The passed document must have been saved using the parsial save using excludeFromSave add the currently selected document must be the same as the document when partial save of passed document done.

This is useful to use a main drawing as background. Let the user add some 'annotation' entities on specific layer, then partial save only entities of that layer.

Later you can open the background drawing and use the MergeDocument with previous partial saved document to show the user annotation entities over the background drawing.

See Also