1.0.0 • Published 5 years ago

three-points-map v1.0.0

Weekly downloads
2
License
MIT
Repository
gitlab
Last release
5 years ago

three-points-map

Map by three.js

Demo

Online Demo

Install

npm i -S three-map

Usage

React/Vue usage

import ThreePointsMap from 'three-map';

VanillaJS usage

<script src="dist/three-map.min.js"></script>

Initialize

new ThreePointsMap(mapContainer, parameters), returns initialized ThreePointsMap instance.

  • mapContainer - string - css selector of the tree container(document.querySelector inside).
  • parameters - object - options of the tree.

For example:

var myThreePointsMap = new ThreePointsMap('#container');

Parameters

NameTypeDescription
urlstringa URL to retrieve remote data,or use data
methodstringhttp method(GET/POST), default 'GET'
dataarraythe json tree data
valuesarrayids which you want to check
closeDepthintegerexpand level
beforeLoadfunctioninvoke before the tree load data. Format raw data in this function.
loadedfunctioninvoke after the tree load data
onChangefunctioninvoke when the node status change

Example

var myTree = new Tree('#container', {
  url: '/api/treeJson',
  method: 'GET',

  values: ['1', '2', '3'],

  // only expand level 1 node
  closeDepth: 1,

  beforeLoad: function(rawData) {
    function formatData() {
      // do some format
    }
    return formatData(rawData);
  },

  loaded: function() {
    // do something or set values after Tree loaded callback
    // do not use arrow function `()=>` , if you use `this`, use function instead.
    // this context bind current tree instance
    this.values = ['0-1'];
  },

  onChange: function() {
    console.log(this.values);
  },
});

Properties

PropertyTypeOperationDescription
valuesarrayget/setselected values.
selectedNodesarraygetselected nodes data with attributes.
disablesarrayget/setget disabled values, or set disable nodes.
disabledNodesarraygetdisabled nodes data with attributes.

myTree.values

// get
var values = myTree.values;

// set
tree.values = ['0-1'];

myTree.selectedNodes

// get
var selectedNodes = myTree.selectedNodes;

myTree.disables

// get
var disables = myTree.disables;

// set
tree.disables = ['0-1'];

myTree.disabledNodes

// get
var disabledNodes = myTree.disabledNodes;

Events

EventParametersDescription
beforeLoadcurrent datainvoke before the tree load data
loadednullinvoke after the tree load data
onChangenullinvoke when the node status change

Examples

var treeData = [
  {
    id: '0',
    text: 'node-0',
    children: [
      {
        id: '0-0',
        text: 'node-0-0',
        children: [
          {id: '0-0-0', text: 'node-0-0-0'},
          {id: '0-0-1', text: 'node-0-0-1'},
          {id: '0-0-2', text: 'node-0-0-2'},
        ],
      },
      {id: '0-1', text: 'node-0-1'},
    ],
  },
  {
    id: '1',
    text: 'node-1',
    children: [{id: '1-0', text: 'node-1-0'}, {id: '1-1', text: 'node-1-1'}],
  },
];

var myTree = new Tree('#container', {
  data: treeData,
});

var myTree = new Tree('#container', {
  url: '/api/treeWithCheckedStatusJson',
});

Like three-map? just 🌟 star the project! Create issues if you find bug.