VJMAP logoVJMAP
CAD · WebGIS
中

Related Examples

Updated 2026-03-07~ 24 min read
.md

Add Marker to Map

Add a point at CAD coordinates [725.32,18969.19] to the map sys_hello

let marker = new vjmap.Marker();
let lngLat = map.toLngLat([725.32,18969.19]);
marker.setLngLat(lngLat);
marker.addToMap()
Runs in a sandbox against the VJMAP public demo service


Get CAD Coordinates of Marker

// Get rendering longitude/latitude coordinates of Marker
let lngLat = marker.getLngLat();
// Convert rendering longitude/latitude to CAD geometric coordinates
let pt = map.fromLngLat(lngLat)
Runs in a sandbox against the VJMAP public demo service


Create Polygon from CAD Coordinate Sequence

Given several CAD GeoJSON coordinate sequences and property values, create polygons and add them to the map. Use map.toLngLat(data) to convert CAD GeoJSON geometric coordinates to rendering longitude/latitude.

let data = {
    "type": "FeatureCollection",
    "features": [
        {
            "id": "1",
            "type": "Feature",
            "properties": {
                "name": "polygon1",
                "color": "#00ffff"
            },
            "geometry": {
                "coordinates": [
                    [
                        [
                            3006.0952985307595,
                            15198.972934052355
                        ],
                        [
                            12606.64046359223,
                            9285.59366571666
                        ],
                        [
                            4745.324495099878,
                            3720.060236694666
                        ],
                        [
                            3006.0952985307595,
                            15198.972934052355
                        ]
                    ]
                ],
                "type": "Polygon"
            }
        },
        {
            "id": "2",
            "type": "Feature",
            "properties": {
                "name": "polygon2",
                "color": "#ff00ff"
            },
            "geometry": {
                "coordinates": [
                    [
                        [
                            19841.833921319492,
                            13807.589576796912
                        ],
                        [
                            19841.833921319492,
                            4207.0444117340885
                        ],
                        [
                            26172.62819683108,
                            4207.0444117340885
                        ],
                        [
                            26172.62819683108,
                            13807.589576796912
                        ],
                        [
                            19841.833921319492,
                            13807.589576796912
                        ]
                    ]
                ],
                "type": "Polygon"
            }
        }
    ]
}
let polygon = new vjmap.Polygon({
    data: map.toLngLat(data), // Convert CAD geometric coordinates to rendering longitude/latitude
    fillColor: ['case', ['to-boolean', ['feature-state', 'hover']], 'red', ['get', 'color']],
    fillOpacity: 0.8,
    fillOutlineColor: "#f00",
    isHoverPointer: true,
    isHoverFeatureState: true
});
polygon.addTo(map);
Runs in a sandbox against the VJMAP public demo service


Get CAD Coordinates of Drawing Layer

Use map.fromLngLat to convert the drawing layer's GeoJSON to CAD geometric coordinates.

// Get rendering longitude/latitude of the drawing object
let lngLatJson = draw.getAll();
// Convert rendering longitude/latitude to CAD geometric coordinates
let cadJson = map.fromLngLat(lngLatJson);
Runs in a sandbox against the VJMAP public demo service


Get Current Mouse Position Coordinates

Runs in a sandbox against the VJMAP public demo service


Was this page helpful?