In the example, we add some more buttons to show some automation code.
<!-- add some buttons associated with above editor. --> <!-- generation of code is now implemented using the MapForce automation --> <!-- interface to select a target folder without prompting the user. --> <p> <input type="button" value="New File" onclick="BtnNewFile(objDoc1)"> <input type="button" value="Save File" onclick="BtnSaveFile(objDoc1)"> <input type="text" title="Path" id="strPath" width="150"> <input type="button" value="Open MarketingExpenses" onclick="BtnOpenMEFile(objDoc1)"> <input type="button" value="Open MapForce Sample Project" onclick="BtnOpenProjectFile(objDoc1)"> </p> |
The corresponding JavaScript looks like this:
// ------------------------------------------------------------------- // open a new empty document in the specified document control window. function BtnNewFile(objDocCtrl) { objDocCtrl.OpenDocument(""); objDocCtrl.setActive(); } // ------------------------------------------------------------------- // Saves the current file in the specified document control window. function BtnSaveFile(objDocCtrl) { if(objDocCtrl.Path.length > 0) objDocCtrl.SaveDocument(); else { if(strPath.value.length > 0) { objDocCtrl.Path = strPath.value; objDocCtrl.SaveDocument(); } else { alert("Please set path for the document first!"); strPath.focus(); } } objDocCtrl.setActive(); } // --------------------------------------------------------- // open a document in the specified document control window. function BtnOpenMEFile(objDocCtrl) { // do not use MapForceX.Application.OpenDocument(...) to open a document, // since then MapForceControl wouldn't know a control window to show // the document in. Instead: var strPath = MakeAbsolutePath("MarketingExpenses.mfd"); var objDoc = objDocCtrl.OpenDocument(strPath); if (objDoc != null) { objDocCtrl.setActive(); msgtext.innerText = "Opened mapping: " + strPath; } else alert("Unable to open " + strPath); } |