|
@@ -12,7 +12,8 @@ import { mapConfig } from "./mapConfig";
|
|
|
// 绘制挤出的材质
|
|
|
export function drawExtrudeMesh(
|
|
|
point,
|
|
|
- projectionFn
|
|
|
+ projectionFn,
|
|
|
+ featureColor
|
|
|
) {
|
|
|
const shape = new THREE.Shape();
|
|
|
const pointsArray = [];
|
|
@@ -32,8 +33,8 @@ export function drawExtrudeMesh(
|
|
|
});
|
|
|
|
|
|
const material = new THREE.MeshPhongMaterial({
|
|
|
- // color: mapConfig.mapColor,
|
|
|
- color: mapConfig.mapColorGradient[Math.floor(Math.random() * 4)], // 随机颜色
|
|
|
+ color: featureColor,
|
|
|
+ // color: mapConfig.mapColorGradient[Math.floor(Math.random() * 4)], // 随机颜色
|
|
|
// transparent: mapConfig.mapTransparent,
|
|
|
// opacity: mapConfig.mapOpacity,
|
|
|
});
|
|
@@ -119,10 +120,12 @@ export function generateMapObject3D(
|
|
|
// 每个坐标数组
|
|
|
const featureCoords =
|
|
|
basicFeatureItem.geometry.coordinates;
|
|
|
+ // 地图每个区块颜色
|
|
|
+ const featureColor = basicFeatureItem.properties.customColor
|
|
|
// 每个中心点位置
|
|
|
const featureCenterCoord =
|
|
|
- basicFeatureItem.properties.centroid &&
|
|
|
- projectionFn(basicFeatureItem.properties.centroid);
|
|
|
+ basicFeatureItem.properties.centroid
|
|
|
+ && projectionFn(basicFeatureItem.properties.centroid);
|
|
|
// 名字
|
|
|
const featureName = basicFeatureItem.properties.name;
|
|
|
console.log('featureName',featureName)
|
|
@@ -150,7 +153,7 @@ export function generateMapObject3D(
|
|
|
// Polygon 类型
|
|
|
if (featureType === "Polygon") {
|
|
|
featureCoords.forEach((polygon) => {
|
|
|
- const { mesh, line } = drawExtrudeMesh(polygon, projectionFn);
|
|
|
+ const { mesh, line } = drawExtrudeMesh(polygon, projectionFn,featureColor);
|
|
|
provinceMapObject3D.add(mesh);
|
|
|
provinceMapObject3D.add(line);
|
|
|
});
|
|
@@ -167,7 +170,6 @@ export function generateMapLabel2D(label2dData) {
|
|
|
const labelObject2D = new THREE.Object3D();
|
|
|
label2dData.forEach((item) => {
|
|
|
const { featureCenterCoord, featureName } = item;
|
|
|
- debugger
|
|
|
const labelObjectItem = draw2dLabel(featureCenterCoord, featureName);
|
|
|
if (labelObjectItem) {
|
|
|
labelObject2D.add(labelObjectItem);
|
|
@@ -200,12 +202,19 @@ export function generateMapSpot(label2dData) {
|
|
|
export const draw2dLabel = (coord, proviceName) => {
|
|
|
if (coord && coord.length) {
|
|
|
// 模版字符串
|
|
|
- const innerHTML = `<div class="your-classname" style="color: #fff">${proviceName}</div>`;
|
|
|
+ const innerHTML = `<div class="your-classname" style="color: #fff;text-shadow: 0px 0px 5px #6affff;">${proviceName}</div>`;
|
|
|
const labelDiv = document.createElement("div");
|
|
|
labelDiv.innerHTML = innerHTML;
|
|
|
labelDiv.style.pointerEvents = "none"; // 禁用事件
|
|
|
const labelObject = new CSS2DObject(labelDiv);
|
|
|
- labelObject.position.set(coord[0], -coord[1], mapConfig.label2dZIndex);
|
|
|
+ if(proviceName == '东风街道'){
|
|
|
+ // 东风街道
|
|
|
+ labelObject.position.set(coord[0] + 5.5, -coord[1] + 2.5, mapConfig.label2dZIndex)
|
|
|
+ } else if(proviceName == '广兴街道'){
|
|
|
+ labelObject.position.set(coord[0] + 4.75, -coord[1] - 3.5, mapConfig.label2dZIndex)
|
|
|
+ } else{
|
|
|
+ labelObject.position.set(coord[0], -coord[1], mapConfig.label2dZIndex);
|
|
|
+ }
|
|
|
return labelObject;
|
|
|
}
|
|
|
};
|