123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- window.grendCAD = (function grendCAD() {
- let initFloor;
- let initScript;
- let initDOM;
- let point, dire;
- window.cad = {
- setSign: function (p, d) {
- point = p;
- dire = d;
- },
- };
- function loadScript(cb) {
- if (initScript) return cb();
- let $script = document.createElement("script");
- $script.src = "static/js/bundle.js";
- $script.onload = function () {
- initScript = true;
- cb();
- };
- document.documentElement.appendChild($script);
- }
- function loadDOM($parent) {
- if (initDOM) return initDOM;
- let $layer = document.createElement("div");
- let $cad = document.createElement("div");
- let $name = document.createElement("div");
- $name.className = "name";
- $name.textContent = "当前位置:耀光别墅";
- $layer.appendChild($name);
- $layer.className = "cad";
- $cad.id = "cad";
- $layer.appendChild($cad);
- let style = document.createElement("style");
- style.innerHTML = `
- .cad {
- position: absolute;
- right: 20px;
- top: 20px;
- width: 180px;
- height: 180px;
- background: rgba(56,56,56,0.56);
- pointer-events: none;
-
- }
- .name {
- width: 100%;
- height: 20px !important;
- color: white;
- font-size: 14px;
- text-align:center;
- margin-top: 10px;
- }
- .cad > div {
- width: 100%;
- height: 100%;
- }
-
- @media only screen and (max-width: 1000px) {
- .cad {
- position: absolute;
- left:auto;
- transform: translate(0, 0);
- right: 10px;
- top: 10px;
- width: 120px;
- height: 120px;
- background: rgba(56,56,56,0.56);
- border-radius: 5px;
- border: 2px solid #D6B970;
- }
- .name {
- font-size: 12px;
- }
- }
- `;
- document.documentElement.appendChild(style);
- $("body").append($layer);
- $parent.appendChild(style);
- $parent.appendChild($layer);
- return $layer;
- }
- function setStyle(signColor, borderColor, borderWidth) {
- cad.setDefaultPointStyle({
- fillColor: "rgba(0,0,0,0)",
- storkeColor: "rgba(0,0,0,0)",
- });
- console.log(borderWidth);
- cad.setDefaultLineStyle({
- width: borderWidth,
- color: borderColor,
- });
- cad.setDefaultSignStyle({
- color: signColor,
- });
- }
- return function (floor, $parent, signColor, borderColor, borderWidth) {
- if (initFloor) {
- console.log("cache");
- return setStyle(signColor, borderColor, borderWidth);
- }
- console.log("load");
- initFloor = floor;
- loadScript(function () {
- let $layer = loadDOM($parent);
- $layer.style.visibility = "hidden";
- window.cad = structureCAD({
- data: {
- block: [],
- column: [],
- door: [],
- hole: [],
- segment: [],
- "vertex-xy": [],
- "vertex-z": [],
- },
- layer: $layer.querySelector("#cad"),
- edit: false,
- });
- setStyle(signColor, borderColor, borderWidth);
- cad.hideDire();
- cad.hideGauge();
- console.log("loadData");
- cad.loadData(initFloor);
- if (point && dire) {
- window.cad.setSign(point, dire);
- }
- $layer.style.visibility = "visible";
- });
- };
- })();
- $.ajax({
- url: g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(),
- method: "GET",
- success(data) {
- if (!data.showCad) return;
- $.ajax({
- url: "./data/" + window.number + "/floor.json",
- method: "GET",
- success(res) {
- grendCAD(
- res,
- document.querySelector("body"),
- data.cadSignColor,
- data.cadBorderColor,
- data.cadBorderWidth
- );
- },
- });
- },
- });
|