Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions packages/vt/src/layer/vector/ExtrudePolygonLayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as maptalks from "maptalks";
import { Geometry, Circle, Rectangle, Ellipse, Sector, Coordinate, Point, Polygon, MultiPolygon } from "maptalks";

import type { LitDataConfig, LitMaterial } from "../../types";
import { extend, isNil } from "../../common/Util";
Expand All @@ -14,6 +14,16 @@ import computeOMBB from "../../worker/builder/Ombb";
import { fromJSON } from "./util/from_json";
import { meterToPoint } from "../plugins/Util";


function isSpecialGeometry(geo: Geometry) {
if (!geo) {
return false;
}
return (geo instanceof Circle) || (geo instanceof Ellipse) || (geo instanceof Sector) || (geo instanceof Rectangle);
}

const TEMP_POLYGON_COORDINATES: Array<Array<Coordinate>> = [];

const { DEFAULT_TEX_WIDTH } = getVectorPacker();

interface ExtrudePolygonLayerOptions extends OverlayLayerOptionsType {
Expand Down Expand Up @@ -153,7 +163,7 @@ const sideFilter = (mesh) => {
};

class ExtrudePolygonLayerRenderer extends PolygonLayerRenderer {
GeometryTypes = [maptalks.Polygon, maptalks.MultiPolygon];
GeometryTypes = [Polygon, MultiPolygon];
sidePainter: Record<string, any>;
sidePainterSymbol: Record<string, any>;

Expand Down Expand Up @@ -375,8 +385,8 @@ class ExtrudePolygonLayerRenderer extends PolygonLayerRenderer {
const tileRatio = 1;
// 原zoom是用来计算functiont-type 的symbol属性值
const zoom = map.getZoom();
const tilePoint = new maptalks.Point(0, 0);
const tileCoord = new maptalks.Coordinate(0, 0);
const tilePoint = new Point(0, 0);
const tileCoord = new Coordinate(0, 0);
const dataConfig = extend(
{},
DEFAULT_DATACONFIG,
Expand Down Expand Up @@ -461,15 +471,19 @@ class ExtrudePolygonLayerRenderer extends PolygonLayerRenderer {
geo.setProperties({});
}
if (!geo.getProperties()[PROP_OMBB]) {
const coordinates = geo.getCoordinates();
if (geo instanceof maptalks.MultiPolygon) {
let coordinates = geo.getCoordinates();
if (geo instanceof MultiPolygon) {
const ombb = [];
for (let i = 0; i < coordinates.length; i++) {
const shell = coordinates[i] && coordinates[i][0];
ombb[i] = computeOMBB(shell);
}
geo.getProperties()[PROP_OMBB] = ombb;
} else {
if (isSpecialGeometry(geo)) {
TEMP_POLYGON_COORDINATES[0] = geo.getShell();
coordinates = TEMP_POLYGON_COORDINATES;
}
const ombb = computeOMBB(coordinates[0]);
geo.getProperties()[PROP_OMBB] = ombb;
}
Expand Down