bill 1 år sedan
förälder
incheckning
a06876fee1
2 ändrade filer med 9 tillägg och 4 borttagningar
  1. 5 2
      src/app/4dmap/index.ts
  2. 4 2
      src/board/packages/scale/scale.ts

+ 5 - 2
src/app/4dmap/index.ts

@@ -145,7 +145,7 @@ export const createBoard = (
   let captureCanvas: HTMLCanvasElement;
 
   const scaleEntity = board.tree.entrys.scale[0] as Scale;
-  scaleEntity.allowable = 0.00000000001;
+  scaleEntity.allowable = 0.01;
   scaleEntity.getScaleUnit = (data: number[]) => {
     if (!props.map) return;
     const mapView = props.map.getView();
@@ -155,7 +155,10 @@ export const createBoard = (
   };
   scaleEntity.getScaleText = (val: number) => {
     if (val > 1000) {
-      return round(val / 1000, 1) + " km";
+      let km = round(val / 1000, 1);
+      let mkm = km % 1;
+      km = Math.floor(km) + (mkm > 0.5 ? 1 : mkm < 0.5 ? -1 : 0.5);
+      return km + " km";
     } else {
       return Math.floor(val) + " m";
     }

+ 4 - 2
src/board/packages/scale/scale.ts

@@ -19,7 +19,7 @@ export type ScaleAttrib = {
 export class Scale extends Entity<ScaleAttrib, Group> {
   private mat: Transform;
   pixelScale: number;
-  allowable = 0.001;
+  allowable = 0.01;
   private fontSize = 12;
   private padding = 4;
   get height() {
@@ -95,7 +95,9 @@ export class Scale extends Entity<ScaleAttrib, Group> {
     for (let w = this.attrib.minWidth; w <= this.attrib.maxWidth; w++) {
       const rw = w * this.pixelScale;
       const deviation = round(rw, 10) - rw;
-      if (deviation < this.allowable && rw % 5 < 1) {
+      const mod = rw < 1000 ? 5 : 500;
+
+      if (deviation < this.allowable && rw % mod < 1) {
         width = w;
         realWidth = rw;
         break;