Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<h2>4DMapper API Example Code</h2>
  <p>This example will create a project then upload selected files to that project in your 4dmapper account. Once uploaded, you can turn them to 3D pointclouds!</p>
    <label>Project name to create:</label>
  <input type="text" id="projectName" value="MyNewProject">
 <p><label>Select files to upload: </label>
  <input type="file" id="imageUploads" accept=".jpg, .jpeg" multiple>
   <p><button class="uploadButton">Start Uploading</button>
<button class="processButton" disabled >Start 3D Processing</button></p>

  <div class="status">
    </div>
 <div id="status">
    </div>


              
            
!

CSS

              
                
              
            
!

JS

              
                import {
    getToken,
    createProject,
    startUploading,
    PhotoTo3D
} from 'https://klau.org/4DMapper/4dm.js';
//get your 4DMapper account clientID and clientSecret from https://app.4dmapper.com/app/admin/apis 
const myClientID = "";
const myClientSecret = "";
const serverName = "https://app.4dmapper.com"; //you can update this if using 4DMapper on-premises version

document.querySelector(".uploadButton").addEventListener("click", prepareToUpload);
document.querySelector(".processButton").addEventListener("click", start3Dprocessing);

function prepareToUpload() {
    if (myClientID == 0) {
        alert("Invalid SDK Credentials, visit https://app.4dmapper.com/app/admin/apis to get your SDK credentials");
        return;
    };
    const status = document.querySelector('.status');
    var token;
    // not that token is valid for one hour, if upload takes over an hour you should refresh the token

    getToken(myClientID, myClientSecret, serverName)
        .then(myToken => token = myToken)
        .then(() => {
            var projectName = document.getElementById("projectName").value;
            createProject(projectName, token, serverName)
                .then(() => {
                    const input = document.querySelector("input[type=file]");
                    const curFiles = input.files;
                    if (curFiles.length === 0) {
                        status.textContent = 'No files selected for upload, only the project name will be created.';
                    } else {
                        status.textContent = 'Uploading...';
                        for (const file of curFiles) {
                            stratUploading(file, file.name, token, file.size, projectName, serverName)
                                .then(res => {
                                    status.textContent = res.payload.name + " uploaded.";
                                    document.querySelector(".processButton").disabled = false;
                                })

                        }
                    }
                })
        })
}


function start3Dprocessing() {
    var token;
    getToken(myClientID, myClientSecret, serverName)
        .then(myToken => token = myToken)
        .then(() => {
            var projectName = document.getElementById("projectName").value;
            PhotoTo3D(projectName, token, serverName);
            document.querySelector(".processButton").disabled = true;
        })
}
              
            
!
999px

Console