#
Junjie
4 天以前 d594d7ee5f331b82f8de83e779be5b42501fdd81
src/main/webapp/components/MapCanvas.js
@@ -96,7 +96,7 @@
  },
  methods: {
    createMap() {
      this.pixiApp = new PIXI.Application({ backgroundColor: 0xF5F7F9FF });
      this.pixiApp = new PIXI.Application({ backgroundColor: 0xF5F7F9FF, antialias: true });
      this.$refs.pixiView.appendChild(this.pixiApp.view);
      this.pixiApp.view.style.width = '100%';
      this.pixiApp.view.style.height = '100%';
@@ -151,6 +151,7 @@
        const newPosX = sx - worldX * newZoom;
        const newPosY = sy - worldY * newZoom;
        this.pixiApp.stage.setTransform(newPosX, newPosY, newZoom, newZoom, 0, 0, 0, 0, 0);
        this.adjustLabelScale();
      });
      //*******************缩放画布*******************
@@ -380,6 +381,7 @@
      const posX = (vw - contentW * scale) / 2 - minX * scale;
      const posY = (vh - contentH * scale) / 2 - minY * scale;
      this.pixiApp.stage.setTransform(posX, posY, scale, scale, 0, 0, 0, 0, 0);
      this.adjustLabelScale();
      this.map = map;
    },
    initWidth(map) {
@@ -500,6 +502,7 @@
              }
            }
          }
          this.adjustLabelScale();
        }
      });
    },
@@ -560,6 +563,7 @@
              }
            }
          }
          this.adjustLabelScale();
        }
      });
    },
@@ -858,5 +862,39 @@
    getTrackSiteNo(obj) {
      if (this.isJson(obj)) { let data = JSON.parse(obj); if (data.trackSiteNo == null || data.trackSiteNo == undefined) { return -1; } return data.trackSiteNo; } else { return -1; }
    },
    adjustLabelScale() {
      const s = this.pixiApp && this.pixiApp.stage ? (this.pixiApp.stage.scale.x || 1) : 1;
      const minPx = 14;
      this.pixiStaMap && this.pixiStaMap.forEach((sprite) => {
        const textObj = sprite && sprite.textObj;
        if (!textObj) { return; }
        const base = (textObj.style && textObj.style.fontSize) ? textObj.style.fontSize : 10;
        let scale = minPx / (base * s);
        if (!isFinite(scale)) { scale = 1; }
        scale = Math.max(0.8, Math.min(scale, 3));
        textObj.scale.set(scale);
        textObj.position.set(sprite.width / 2, sprite.height / 2);
      });
      this.pixiCrnMap && this.pixiCrnMap.forEach((sprite) => {
        const textObj = sprite && sprite.textObj;
        if (!textObj) { return; }
        const base = (textObj.style && textObj.style.fontSize) ? textObj.style.fontSize : 12;
        let scale = minPx / (base * s);
        if (!isFinite(scale)) { scale = 1; }
        scale = Math.max(0.8, Math.min(scale, 3));
        textObj.scale.set(scale);
        textObj.position.set(sprite.width / 2, sprite.height / 2);
      });
      this.pixiRgvMap && this.pixiRgvMap.forEach((sprite) => {
        const textObj = sprite && sprite.textObj;
        if (!textObj) { return; }
        const base = (textObj.style && textObj.style.fontSize) ? textObj.style.fontSize : 12;
        let scale = minPx / (base * s);
        if (!isFinite(scale)) { scale = 1; }
        scale = Math.max(0.8, Math.min(scale, 3));
        textObj.scale.set(scale);
        textObj.position.set(sprite.width / 2, sprite.height / 2);
      });
    }
  }
});