Skip to content
On this page

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/MxCadConfig

Interface: MxCadConfig

2d.MxCadConfig

Parameter configuration for creating MxCad

Example

ts
createMxCad({
    canvas: "#mxcad",
    locateFile: (fileName) => new URL(`/node_modules/mxcad/dist/wasm/2d/${fileName}`, import.meta.url).href,
//Please note that when providing the file to be opened/ Assets/test.mxweb is the file address in the relative path,
//In Vite, the correct network address of the file can be obtained through this method
    fileUrl: new URL("../assets/test.mxweb", import.meta.url).href,
//Provide the directory path for loading fonts
    fontspath: new URL("node_modules/mxcad/dist/fonts", import.meta.url).href, 
viewBackgroundColor:{red:0,green:0,blue:0}, // Black background
middlePan:false, // Disable middle mouse button operation
multipleSelect: true, //  Enable multiple selection
    onOpenFileComplete:()=>{
Console.log (successfully opened file! ")
    }
  })

Table of contents

Properties

Properties

authorized_service

Optional authorized_service: string

Authorized Services


browse

Optional browse: number | boolean

True or 1, enable browsing mode, CAD objects cannot be selected /*2. Enable browsing mode, CAD objects can be selected, but grip editing is not possible


canvas

Optional canvas: string | HTMLCanvasElement

When the current mxDraw instance is not found through MxFun.getCurrentDraw, It will create an mxdraw instance through the canvas attribute (the value can be a CSS selector string or a canvas element) If you want to obtain this mxDraw instance, you only need to call the MxFun.getCurrentDraw method exported from the mxdraw package If the canvas variable is not used in GIS mode, mapbox's canvas will be automatically used


enableIntelliSelect

Optional enableIntelliSelect: boolean

Whether to enable the selection function, default is to use


enableUndo

Optional enableUndo: boolean

Whether to enable 'undo', it is not enabled by default


fileUrl

Optional fileUrl: string

Need to initialize the URL path of the opened file


fontspath

Optional fontspath: string

Font file loading path, default is fonts


locateFile

Optional locateFile: (fileName: string, base?: string | URL) => string

Type declaration

▸ (fileName, base?): string

Retrieve the path location for loading wasm related files (wasm/js/worker. js)

Parameters
NameTypeDescription
FileNameStringWasm related file names
base? string | [URL]( https://developer.mozilla.org/docs/Web/API/URL )Absolute path of HTTP URL relative to JS call location
Returns

string

FilePath defaults to using base+fileName

Abstract

Essentially, the locateFile configuration function returns the location of wasm related files on its own server The files under 'node_rodules/mxcad/dist/wasm/2d/' in the npm package are the relevant wasm files that support 2D


map

Optional map: any

Map module


middlePan

Optional middlePan: number | boolean

iMethod = 0, Middle button does not move the viewport, left button moves iMethod = 1, Middle button moves the viewport, left button does not move iMethod = 2, Middle click to move the viewport, left click to move the viewport


multipleSelect

Optional multipleSelect: boolean

Multiple choice mode, default value is false


networkFonts

Optional networkFonts: string[]

List of fonts available for loading on the server


onInit

Optional onInit: Function

Callback for initialization of mxdraw and mxcad core code loading completion The default value function of onInit is shown in the following example (please modify it according to your business needs)

Example

js
import { MxFun } from "mxdraw"
onInit() {
 MxFun.setIniset({
//Enable object selection function
     EnableIntelliSelect: true,
//Select type
     IntelliSelectType: 1,
//Do you want to enable multiple selections
     multipleSelect: false,
  });
}

onOpenFileComplete

Optional onOpenFileComplete: Function

Monitor successful file opening callback event


openParameter

Optional openParameter: object

Open file parameter settings, such as not using cache when opening files:


registdata

Optional registdata: string

Registration data


registfile

Optional registfile: string

Registration documents


viewBackgroundColor

Optional viewBackgroundColor: Object

Visual area background color

Type declaration

NameType
bluenumber
greennumber
rednumber

wasmBinary

Optional wasmBinary: ArrayBuffer

WebAssembly module binary files do not require configuration by default*


webgl1

Optional webgl1: boolean

Do you want to start using WebGL1 mode