gis-common 5.1.33 → 5.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gis-common.es.js +20 -21
- package/dist/gis-common.umd.js +1 -1
- package/dist/index.d.ts +3 -6
- package/package.json +1 -1
- package/dist/17.png +0 -0
package/dist/gis-common.es.js
CHANGED
|
@@ -3354,26 +3354,27 @@ class Color {
|
|
|
3354
3354
|
class CanvasDrawer {
|
|
3355
3355
|
constructor(el) {
|
|
3356
3356
|
__publicField(this, "ctx");
|
|
3357
|
+
__publicField(this, "canvas");
|
|
3357
3358
|
if (el && typeof el === "string") {
|
|
3358
|
-
|
|
3359
|
-
if (!
|
|
3359
|
+
this.canvas = document.querySelector("#" + el);
|
|
3360
|
+
if (!this.canvas) {
|
|
3360
3361
|
throw new Error("Element not found");
|
|
3361
3362
|
}
|
|
3362
3363
|
}
|
|
3363
3364
|
if (el instanceof HTMLCanvasElement) {
|
|
3364
|
-
|
|
3365
|
-
if (canvas.getContext) {
|
|
3366
|
-
this.ctx = canvas.getContext("2d");
|
|
3365
|
+
this.canvas = el;
|
|
3366
|
+
if (this.canvas.getContext) {
|
|
3367
|
+
this.ctx = this.canvas.getContext("2d");
|
|
3367
3368
|
} else {
|
|
3368
3369
|
throw new Error("getContext is not available on this element");
|
|
3369
3370
|
}
|
|
3370
3371
|
} else {
|
|
3371
|
-
|
|
3372
|
-
canvas.style.cssText = "position: absolute; display: block; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 999999;";
|
|
3373
|
-
canvas.width = window.innerWidth;
|
|
3374
|
-
canvas.height = window.innerHeight;
|
|
3375
|
-
document.body.appendChild(canvas);
|
|
3376
|
-
this.ctx = canvas.getContext("2d");
|
|
3372
|
+
this.canvas = document.createElement("canvas");
|
|
3373
|
+
this.canvas.style.cssText = "position: absolute; display: block; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 999999;";
|
|
3374
|
+
this.canvas.width = window.innerWidth;
|
|
3375
|
+
this.canvas.height = window.innerHeight;
|
|
3376
|
+
document.body.appendChild(this.canvas);
|
|
3377
|
+
this.ctx = this.canvas.getContext("2d");
|
|
3377
3378
|
if (!this.ctx) {
|
|
3378
3379
|
throw new Error("getContext is not available on this element");
|
|
3379
3380
|
}
|
|
@@ -3387,10 +3388,10 @@ class CanvasDrawer {
|
|
|
3387
3388
|
* @param options 绘制选项,包括线条宽度和颜色
|
|
3388
3389
|
* @throws 当画布上下文不存在时抛出错误
|
|
3389
3390
|
*/
|
|
3390
|
-
drawLine({ x: startX, y: startY }, { x: endX, y: endY }, options) {
|
|
3391
|
+
drawLine({ x: startX, y: startY }, { x: endX, y: endY }, options = {}) {
|
|
3391
3392
|
this.ctx.beginPath();
|
|
3392
|
-
const width =
|
|
3393
|
-
const color =
|
|
3393
|
+
const width = options.width || 1;
|
|
3394
|
+
const color = options.color || "#000";
|
|
3394
3395
|
this.ctx.lineWidth = width;
|
|
3395
3396
|
this.ctx.strokeStyle = color;
|
|
3396
3397
|
this.ctx.moveTo(startX, startY);
|
|
@@ -3423,14 +3424,12 @@ class CanvasDrawer {
|
|
|
3423
3424
|
this.ctx.stroke();
|
|
3424
3425
|
}
|
|
3425
3426
|
}
|
|
3426
|
-
drawImage({ x, y }, image,
|
|
3427
|
-
const width =
|
|
3428
|
-
const height =
|
|
3429
|
-
const angle = options.angle || 0;
|
|
3430
|
-
this.ctx.save();
|
|
3427
|
+
drawImage({ x, y }, image, angleDeg, color) {
|
|
3428
|
+
const width = image.width;
|
|
3429
|
+
const height = image.height;
|
|
3431
3430
|
this.ctx.translate(x, y);
|
|
3432
|
-
if (
|
|
3433
|
-
const angleRad =
|
|
3431
|
+
if (angleDeg) {
|
|
3432
|
+
const angleRad = angleDeg * Math.PI / 180;
|
|
3434
3433
|
this.ctx.rotate(angleRad);
|
|
3435
3434
|
}
|
|
3436
3435
|
this.ctx.drawImage(image, -width / 2, -height / 2, width, height);
|