|
@@ -1,5 +1,10 @@
|
|
|
import { Polygons } from "./polygons";
|
|
|
-import { register, BoundQueryPlugin, setGenerateStartId } from "../../board";
|
|
|
+import {
|
|
|
+ register,
|
|
|
+ BoundQueryPlugin,
|
|
|
+ setGenerateStartId,
|
|
|
+ inRevise,
|
|
|
+} from "../../board";
|
|
|
import { PolygonsAttrib } from "./type";
|
|
|
import { Map } from "ol";
|
|
|
import { boundingExtent } from "ol/extent";
|
|
@@ -9,8 +14,9 @@ const boundJoinMap = (
|
|
|
mountDOM?: HTMLDivElement,
|
|
|
map?: Map
|
|
|
) => {
|
|
|
+ let mapView = map?.getView();
|
|
|
const getMapBound = () => {
|
|
|
- return map.getView().calculateExtent(map.getSize());
|
|
|
+ return mapView.calculateExtent(map.getSize());
|
|
|
};
|
|
|
|
|
|
const setMapBound = (bound: number[]) => {
|
|
@@ -18,26 +24,32 @@ const boundJoinMap = (
|
|
|
[bound[0], bound[1]],
|
|
|
[bound[2], bound[3]],
|
|
|
]);
|
|
|
- map.getView().fit(extent, {
|
|
|
+ mapView.fit(extent, {
|
|
|
size: map.getSize(),
|
|
|
padding: [0, 0, 0, 0], // 根据需要调整边距
|
|
|
- maxZoom: 19.5, // 防止过度放大
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const setBoardBound = () => {
|
|
|
if (mountDOM && map) {
|
|
|
const bound = getMapBound();
|
|
|
- boundQuery.setSize(mountDOM.offsetWidth, mountDOM.offsetHeight);
|
|
|
- boundQuery.setBound([bound[0], bound[3], bound[2], bound[1]]);
|
|
|
+ if (!boundQuery.bound || inRevise(boundQuery.bound, bound)) {
|
|
|
+ boundQuery.setSize(mountDOM.offsetWidth, mountDOM.offsetHeight);
|
|
|
+ boundQuery.setBound([bound[0], bound[3], bound[2], bound[1]]);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const setMap = (bindMap: Map) => {
|
|
|
if (map) {
|
|
|
+ mapView.removeEventListener("change:center", setBoardBound);
|
|
|
+ mapView.removeEventListener("change:resolution", setBoardBound);
|
|
|
map.removeEventListener("moveend", setBoardBound);
|
|
|
}
|
|
|
- bindMap.addEventListener("moveend", setBoardBound);
|
|
|
+ mapView = bindMap.getView();
|
|
|
+ mapView.addEventListener("change:center", setBoardBound);
|
|
|
+ mapView.addEventListener("change:resolution", setBoardBound);
|
|
|
+ map.addEventListener("moveend", setBoardBound);
|
|
|
map = bindMap;
|
|
|
setBoardBound();
|
|
|
};
|
|
@@ -53,11 +65,14 @@ const boundJoinMap = (
|
|
|
|
|
|
return {
|
|
|
setMap,
|
|
|
+ setBoardBound,
|
|
|
setMountDom(dom: HTMLDivElement) {
|
|
|
mountDOM = dom;
|
|
|
setBoardBound();
|
|
|
},
|
|
|
destory() {
|
|
|
+ mapView.removeEventListener("change:center", setBoardBound);
|
|
|
+ mapView.removeEventListener("change:resolution", setBoardBound);
|
|
|
map.removeEventListener("moveend", setBoardBound);
|
|
|
},
|
|
|
};
|
|
@@ -81,21 +96,20 @@ export const createBoard = (
|
|
|
const board = initBoard(props.dom, { polygons: data }, false);
|
|
|
const mapJoin = boundJoinMap(board.bound, props.dom, props.map);
|
|
|
|
|
|
- board.tree.bus.on("active", (entity) => {
|
|
|
- console.log(entity);
|
|
|
- });
|
|
|
+ const setProps = (props: { dom?: HTMLDivElement; map?: Map } = {}) => {
|
|
|
+ if (props.dom) {
|
|
|
+ board.mount(props.dom);
|
|
|
+ mapJoin.setMountDom(props.dom);
|
|
|
+ }
|
|
|
+ if (props.map) {
|
|
|
+ mapJoin.setMap(props.map);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ setProps(props);
|
|
|
|
|
|
return {
|
|
|
raw: board,
|
|
|
- setProps(props: { dom?: HTMLDivElement; map?: Map }) {
|
|
|
- if (props.dom) {
|
|
|
- board.mount(props.dom);
|
|
|
- mapJoin.setMountDom(props.dom);
|
|
|
- }
|
|
|
- if (props.map) {
|
|
|
- mapJoin.setMap(props.map);
|
|
|
- }
|
|
|
- },
|
|
|
+ setProps,
|
|
|
getData() {
|
|
|
return board.getData().polygons[0];
|
|
|
},
|
|
@@ -118,3 +132,5 @@ export const createBoard = (
|
|
|
export * from "../../board";
|
|
|
export * from "./polygons";
|
|
|
export * from "./type";
|
|
|
+export * from "./path";
|
|
|
+export * from "./point";
|