|
@@ -2,8 +2,7 @@ import * as KMap from "@/utils/ol-map/KMap";
|
|
|
import * as util from "@/common/ol_common.js";
|
|
import * as util from "@/common/ol_common.js";
|
|
|
import config from "@/api/config.js";
|
|
import config from "@/api/config.js";
|
|
|
import Style from "ol/style/Style";
|
|
import Style from "ol/style/Style";
|
|
|
-import Photo from "ol-ext/style/Photo";
|
|
|
|
|
-import { Icon, Stroke } from "ol/style.js";
|
|
|
|
|
|
|
+import { Icon } from "ol/style.js";
|
|
|
import { newPoint } from "@/utils/map";
|
|
import { newPoint } from "@/utils/map";
|
|
|
|
|
|
|
|
/** 对齐 albumPanel `.zone-marker__label` 视觉 */
|
|
/** 对齐 albumPanel `.zone-marker__label` 视觉 */
|
|
@@ -12,9 +11,40 @@ const LABEL_PAD_X = 10;
|
|
|
const LABEL_HEIGHT = 26;
|
|
const LABEL_HEIGHT = 26;
|
|
|
const LABEL_BORDER = 1;
|
|
const LABEL_BORDER = 1;
|
|
|
const LABEL_RADIUS = 25;
|
|
const LABEL_RADIUS = 25;
|
|
|
-const LABEL_DPR = window.devicePixelRatio || 2;
|
|
|
|
|
|
|
+/** 标签底边相对点位顶部的间距(CSS px) */
|
|
|
|
|
+const LABEL_GAP = 26;
|
|
|
|
|
+
|
|
|
|
|
+const POINT_ICON_SRC = require("@/assets/img/home/garden-point.png");
|
|
|
|
|
+const POINT_SCALE = 0.5;
|
|
|
|
|
+/** garden-point.png 原始尺寸;位移按渲染后宽高计算,避免 PC/手机写死像素不一致 */
|
|
|
|
|
+const POINT_NATURAL_SIZE = [59, 76];
|
|
|
|
|
+
|
|
|
|
|
+function getDpr() {
|
|
|
|
|
+ const dpr = Number(window.devicePixelRatio) || 1;
|
|
|
|
|
+ return dpr > 0 ? dpr : 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getPointRenderSize() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ width: POINT_NATURAL_SIZE[0] * POINT_SCALE,
|
|
|
|
|
+ height: POINT_NATURAL_SIZE[1] * POINT_SCALE,
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 标签:底边锚在坐标上,再上移到点位顶部之上 */
|
|
|
|
|
+function getLabelDisplacement() {
|
|
|
|
|
+ const { height } = getPointRenderSize();
|
|
|
|
|
+ return [0, height + LABEL_GAP];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 角标:相对针尖偏右上,贴在点位右上角 */
|
|
|
|
|
+function getBadgeDisplacement() {
|
|
|
|
|
+ const { width, height } = getPointRenderSize();
|
|
|
|
|
+ return [width * 0.9, height * 1.2];
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
function createPillLabel(text) {
|
|
function createPillLabel(text) {
|
|
|
|
|
+ const dpr = getDpr();
|
|
|
const canvas = document.createElement("canvas");
|
|
const canvas = document.createElement("canvas");
|
|
|
const ctx = canvas.getContext("2d");
|
|
const ctx = canvas.getContext("2d");
|
|
|
const labelText = text || "";
|
|
const labelText = text || "";
|
|
@@ -26,9 +56,9 @@ function createPillLabel(text) {
|
|
|
const height = innerH + LABEL_BORDER * 2;
|
|
const height = innerH + LABEL_BORDER * 2;
|
|
|
const radius = Math.min(LABEL_RADIUS, height / 2);
|
|
const radius = Math.min(LABEL_RADIUS, height / 2);
|
|
|
|
|
|
|
|
- canvas.width = Math.ceil(width * LABEL_DPR);
|
|
|
|
|
- canvas.height = Math.ceil(height * LABEL_DPR);
|
|
|
|
|
- ctx.scale(LABEL_DPR, LABEL_DPR);
|
|
|
|
|
|
|
+ canvas.width = Math.ceil(width * dpr);
|
|
|
|
|
+ canvas.height = Math.ceil(height * dpr);
|
|
|
|
|
+ ctx.scale(dpr, dpr);
|
|
|
ctx.imageSmoothingEnabled = true;
|
|
ctx.imageSmoothingEnabled = true;
|
|
|
ctx.imageSmoothingQuality = "high";
|
|
ctx.imageSmoothingQuality = "high";
|
|
|
|
|
|
|
@@ -60,19 +90,20 @@ function createPillLabel(text) {
|
|
|
// 中文字体 middle 基线视觉偏下,略上移
|
|
// 中文字体 middle 基线视觉偏下,略上移
|
|
|
ctx.fillText(labelText, Math.round(width / 2), Math.round(height / 2) - 1);
|
|
ctx.fillText(labelText, Math.round(width / 2), Math.round(height / 2) - 1);
|
|
|
|
|
|
|
|
- return canvas.toDataURL();
|
|
|
|
|
|
|
+ return { src: canvas.toDataURL(), dpr };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 分区数量角标:金底深字小圆点,叠加在点位右上角 */
|
|
/** 分区数量角标:金底深字小圆点,叠加在点位右上角 */
|
|
|
function createCountBadge(count) {
|
|
function createCountBadge(count) {
|
|
|
|
|
+ const dpr = getDpr();
|
|
|
const canvas = document.createElement("canvas");
|
|
const canvas = document.createElement("canvas");
|
|
|
const ctx = canvas.getContext("2d");
|
|
const ctx = canvas.getContext("2d");
|
|
|
const radius = 11;
|
|
const radius = 11;
|
|
|
const pad = 2;
|
|
const pad = 2;
|
|
|
const size = (radius + pad) * 2;
|
|
const size = (radius + pad) * 2;
|
|
|
- canvas.width = size * LABEL_DPR;
|
|
|
|
|
- canvas.height = size * LABEL_DPR;
|
|
|
|
|
- ctx.scale(LABEL_DPR, LABEL_DPR);
|
|
|
|
|
|
|
+ canvas.width = Math.ceil(size * dpr);
|
|
|
|
|
+ canvas.height = Math.ceil(size * dpr);
|
|
|
|
|
+ ctx.scale(dpr, dpr);
|
|
|
ctx.imageSmoothingEnabled = true;
|
|
ctx.imageSmoothingEnabled = true;
|
|
|
ctx.imageSmoothingQuality = "high";
|
|
ctx.imageSmoothingQuality = "high";
|
|
|
|
|
|
|
@@ -87,7 +118,7 @@ function createCountBadge(count) {
|
|
|
ctx.textBaseline = "middle";
|
|
ctx.textBaseline = "middle";
|
|
|
ctx.fillText(String(count), radius + pad, radius + pad + 0.5);
|
|
ctx.fillText(String(count), radius + pad, radius + pad + 0.5);
|
|
|
|
|
|
|
|
- return canvas.toDataURL();
|
|
|
|
|
|
|
+ return { src: canvas.toDataURL(), dpr };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -104,12 +135,13 @@ class IndexMap {
|
|
|
|
|
|
|
|
this.borderStyle = new Style({
|
|
this.borderStyle = new Style({
|
|
|
image: new Icon({
|
|
image: new Icon({
|
|
|
- src: require("@/assets/img/home/garden-point.png"),
|
|
|
|
|
- scale: 0.5,
|
|
|
|
|
|
|
+ src: POINT_ICON_SRC,
|
|
|
|
|
+ scale: POINT_SCALE,
|
|
|
|
|
+ // 底边对准坐标,保证针尖落点一致
|
|
|
|
|
+ anchor: [0.5, 1],
|
|
|
onload: function () {
|
|
onload: function () {
|
|
|
that.gardenPointLayer.layer.changed();
|
|
that.gardenPointLayer.layer.changed();
|
|
|
},
|
|
},
|
|
|
- danchor: [0.5,1],
|
|
|
|
|
}),
|
|
}),
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -117,14 +149,20 @@ class IndexMap {
|
|
|
minZoom: 6,
|
|
minZoom: 6,
|
|
|
maxZoom: 22,
|
|
maxZoom: 22,
|
|
|
style: (feature) => {
|
|
style: (feature) => {
|
|
|
- const labelText = this.onlyName ? feature.get("farmName") : ((feature.get("executeDate") + ' ' + feature.get("farmName")) || feature.get("mapInfo") || "");
|
|
|
|
|
|
|
+ const labelText = this.onlyName
|
|
|
|
|
+ ? feature.get("farmName")
|
|
|
|
|
+ : ((feature.get("executeDate") + " " + feature.get("farmName")) ||
|
|
|
|
|
+ feature.get("mapInfo") ||
|
|
|
|
|
+ "");
|
|
|
if (!this.labelStyleCache[labelText]) {
|
|
if (!this.labelStyleCache[labelText]) {
|
|
|
|
|
+ const label = createPillLabel(labelText);
|
|
|
this.labelStyleCache[labelText] = new Style({
|
|
this.labelStyleCache[labelText] = new Style({
|
|
|
image: new Icon({
|
|
image: new Icon({
|
|
|
- src: createPillLabel(labelText),
|
|
|
|
|
- scale: 1 / LABEL_DPR,
|
|
|
|
|
|
|
+ src: label.src,
|
|
|
|
|
+ // canvas 已按 DPR 绘制,缩回 CSS 像素,PC/手机视觉尺寸一致
|
|
|
|
|
+ scale: 1 / label.dpr,
|
|
|
anchor: [0.5, 1],
|
|
anchor: [0.5, 1],
|
|
|
- displacement: [0, 36],
|
|
|
|
|
|
|
+ displacement: getLabelDisplacement(),
|
|
|
}),
|
|
}),
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -134,12 +172,13 @@ class IndexMap {
|
|
|
if (count != null && count !== "" && Number(count) > 0) {
|
|
if (count != null && count !== "" && Number(count) > 0) {
|
|
|
const badgeKey = `count_${count}`;
|
|
const badgeKey = `count_${count}`;
|
|
|
if (!this.countStyleCache[badgeKey]) {
|
|
if (!this.countStyleCache[badgeKey]) {
|
|
|
|
|
+ const badge = createCountBadge(count);
|
|
|
this.countStyleCache[badgeKey] = new Style({
|
|
this.countStyleCache[badgeKey] = new Style({
|
|
|
image: new Icon({
|
|
image: new Icon({
|
|
|
- src: createCountBadge(count),
|
|
|
|
|
- scale: 1 / LABEL_DPR,
|
|
|
|
|
|
|
+ src: badge.src,
|
|
|
|
|
+ scale: 1 / badge.dpr,
|
|
|
anchor: [0.5, 0.5],
|
|
anchor: [0.5, 0.5],
|
|
|
- displacement: [24, 22],
|
|
|
|
|
|
|
+ displacement: getBadgeDisplacement(),
|
|
|
}),
|
|
}),
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|