🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@maptalks/transform-control

Package Overview
Dependencies
Maintainers
1
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maptalks/transform-control

a plugin to control model's translate、rotation and scale

Source
npmnpm
Version
0.97.4
Version published
Weekly downloads
2.6K
65.65%
Maintainers
1
Weekly downloads
 
Created
Source

maptalks.TransformControl

NPM Version

Usage

transform-control a plugin to control model's translate、rotation and scale.

Install

  • Install with npm: npm install @maptalks/transform-control.
  • Use unpkg CDN: https://unpkg.com/@maptalks/transform-control/dist/transform-control.js

Vanilla Javascript

<script type="text/javascript" src="../maptalks.transform-control.js"></script>
<script>
var map = new maptalks.Map("map",{
    center : [0, 0],
    zoom   :  15
});
var transformControl = new maptalks.TransformControl();
transformControl.addTo(map);
transformControl.on('transforming', e => {
    //get translate、rotation、scale
    const translate = e.translate;
    const rotation = e.rotation;
    const scale = e.scale;
});
</script>

ES6

import TransfromControl from '@maptalks/transform-control';

const map = new maptalks.Map("map",{
    center : [0, 0],
    zoom   :  15
});
const transformControl = new maptalks.TransformControl();
transformControl.addTo(map);
transformControl.on('transforming', e => {
    const target = e.target;
    target.setTRS(e.translate, e.rotation, e.scale);
});
transformControl.on('positionchange', e => {
    const target = e.target;
    target.setCoordinates(e.coordinate);
});

API

  • Class : TransformControl(inherited from maptalks.Eventable)

    transform control's constructor.

    Method : new TransformControl(options)

    ParameterTypeDefaultDescription
    idStringtransform control's id
    optionsObjectnullconstruct options

    Method : addTo(map)

    add the control to a map

    ParameterTypeDefaultDescription
    mapmaptalks.Mapa map to add

    returns :
    TransformControl: this

    Method : remove()

    remove the control from map

    Method : transform(target)

    specify a target to transform

    ParameterTypeDefaultDescription
    targetGLTFMarker | Meshnullthe target to transform

    Method : getTransformTarget()

    get the current tranforming target

    returns :
    Object: the transforming target object

    Method : enable()

    enable the control

    returns :
    TransformControl: return this

    Method : disable()

    disable the control, when disable the control, it will be not available TransformControl: return this

    Method : isEnbale()

    whether the control is enable Boolean: true or false

    Event : transforming

    when transforming the target, it will trigger transforming event

    ParameterTypeDefaultDescription
    targetGLTFMarkerthe target to transform
    actionStringtransforming action, includes xy-translatex-translatey-translatez-translatez-rotatescale
    typeGLTFMarkerevent type name
    translateArraycurrent translate when transforming
    scaleArraycurrent scale when transforming
    rotationArraycurrent rotation when transforming

    Event : positionchange

    when changing target's position, it will trigger positionchange event

    ParameterTypeDefaultDescription
    targetGLTFMarkerthe target to transform
    actionStringtransforming action, includes xy-translatex-translatey-translatez-translatez-rotatescale
    typeGLTFMarkerevent type name
    coordinateArraycurrent coordinate when changing target's position

    Event : transformend

    when endding the transform task, it will trigger transformend event

    ParameterTypeDefaultDescription
    targetGLTFMarkerthe target to be transformed
    actionStringcurrent action
    typeGLTFMarkerevent type name

FAQs

Package last updated on 14 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts