160 lines
6.4 KiB
HTML
160 lines
6.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<base data-ice="baseUrl" href="../../../">
|
|
<title data-ice="title">src/toolbar/QueryMode.js | xeokit-viewer</title>
|
|
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
<script src="script/prettify/prettify.js"></script>
|
|
<script src="script/manual.js"></script>
|
|
<meta name="description" content="BIM viewer built on xeokit"><meta property="og:type" content="website"><meta property="og:url" content="https://github.com/xeokit/xeokit-viewer"><meta property="og:site_name" content="xeokit-viewer"><meta property="og:title" content="xeokit-viewer"><meta property="og:image" content="./images/logo.jpg"><meta property="og:description" content="BIM viewer built on xeokit"><meta property="og:author" content="http://xeolabs.com"><meta property="twitter:card" content="summary"><meta property="twitter:title" content="xeokit-viewer"><meta property="twitter:description" content="BIM viewer built on xeokit"><meta property="twitter:image" content="./images/logo.jpg"></head>
|
|
<body class="layout-container" data-ice="rootContainer">
|
|
|
|
<header>
|
|
<a href="./" style="display: flex; align-items: center;"><img src="./image/brand_logo.jpg" style="width:34px;"></a>
|
|
|
|
<a href="identifiers.html">Reference</a>
|
|
<a href="source.html">Source</a>
|
|
|
|
<div class="search-box">
|
|
<span>
|
|
<img src="./image/search.png">
|
|
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
</span>
|
|
<ul class="search-result"></ul>
|
|
</div>
|
|
<a style="position:relative; top:3px;" href="https://github.com/xeokit/xeokit-viewer"><img width="20px" src="./image/github.png"></a></header>
|
|
|
|
<nav class="navigation" data-ice="nav"><div>
|
|
<ul>
|
|
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/ViewerUI.js~ViewerUI.html">ViewerUI</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#ifcobjectdefaults">IFCObjectDefaults</a><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-IFCObjectDefaults">IFCObjectDefaults</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#server">server</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/server/Server.js~Server.html">Server</a></span></span></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="content" data-ice="content"><h1 data-ice="title">src/toolbar/QueryMode.js</h1>
|
|
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import {Controller} from "../Controller.js";
|
|
import {math} from "@xeokit/xeokit-sdk/src/viewer/scene/math/math.js";
|
|
|
|
function closeEnough(p, q) {
|
|
const CLICK_DIST = 4;
|
|
return (Math.abs(p[0] - q[0]) < 4) && (Math.abs(p[1] - q[1]) < CLICK_DIST);
|
|
}
|
|
|
|
/** @private */
|
|
class QueryMode extends Controller {
|
|
|
|
constructor(parent, cfg) {
|
|
|
|
super(parent);
|
|
|
|
if (!cfg.buttonElement) {
|
|
throw "Missing config: buttonElement";
|
|
}
|
|
|
|
const buttonElement = cfg.buttonElement;
|
|
|
|
this.on("enabled", (enabled) => {
|
|
if (!enabled) {
|
|
buttonElement.classList.add("disabled");
|
|
} else {
|
|
buttonElement.classList.remove("disabled");
|
|
}
|
|
});
|
|
|
|
this.on("active", (active) => {
|
|
if (active) {
|
|
buttonElement.classList.add("active");
|
|
} else {
|
|
buttonElement.classList.remove("active");
|
|
}
|
|
});
|
|
|
|
buttonElement.addEventListener("click", (event) => {
|
|
if (!this.getEnabled()) {
|
|
return;
|
|
}
|
|
const active = this.getActive();
|
|
this.setActive(!active);
|
|
event.preventDefault();
|
|
});
|
|
|
|
this.viewerUI.on("reset", ()=>{
|
|
this.setActive(false);
|
|
});
|
|
|
|
this._initQueryMode();
|
|
}
|
|
|
|
_initQueryMode() {
|
|
const viewer = this.viewer;
|
|
const cameraControl = viewer.cameraControl;
|
|
var entity = null;
|
|
this._onHover = cameraControl.on("hover", (e) => {
|
|
if (!this.getActive() || !this.getEnabled()) {
|
|
return;
|
|
}
|
|
if (entity) {
|
|
entity.highlighted = false;
|
|
entity = null;
|
|
}
|
|
entity = e.entity;
|
|
entity.highlighted = true;
|
|
});
|
|
this._onHoverOff = cameraControl.on("hoverOff", (e) => {
|
|
if (!this.getActive() || !this.getEnabled()) {
|
|
return;
|
|
}
|
|
if (entity) {
|
|
entity.highlighted = false;
|
|
entity = null;
|
|
}
|
|
});
|
|
const lastCoords = math.vec2();
|
|
this._onMousedown = viewer.scene.input.on("mousedown", (coords) => {
|
|
if (!this.getActive() || !this.getEnabled()) {
|
|
return;
|
|
}
|
|
lastCoords[0] = coords[0];
|
|
lastCoords[1] = coords[1];
|
|
});
|
|
this._onMouseup = viewer.scene.input.on("mouseup", (coords) => {
|
|
if (!this.getActive() || !this.getEnabled()) {
|
|
return;
|
|
}
|
|
if (entity) {
|
|
if (!closeEnough(lastCoords, coords)) {
|
|
entity = null;
|
|
return;
|
|
}
|
|
this.fire("queryPicked", entity.id);
|
|
entity = null;
|
|
} else {
|
|
this.fire("queryNotPicked", false);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export {QueryMode};</code></pre>
|
|
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
|
|
</footer>
|
|
|
|
<script src="script/search_index.js"></script>
|
|
<script src="script/search.js"></script>
|
|
<script src="script/pretty-print.js"></script>
|
|
<script src="script/inherited-summary.js"></script>
|
|
<script src="script/test-summary.js"></script>
|
|
<script src="script/inner-link.js"></script>
|
|
<script src="script/patch-for-local.js"></script>
|
|
</body>
|
|
</html>
|