Skip to content

Commit

Permalink
feat: 完善 bbox 文档 (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
heiyexing authored Jan 26, 2024
1 parent 1abc0dd commit 0007cac
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions docs/example/common/bbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Scene } from '@antv/l7';
import { Scene, PolygonLayer } from '@antv/l7';
import { DrawEvent, DrawPolygon } from '@antv/l7-draw';
import { GaodeMap } from '@antv/l7-maps';
import { Feature } from '@turf/turf';
import { Feature, bboxPolygon, featureCollection } from '@turf/turf';
import 'antd/dist/antd.css';
import React, { useEffect, useState } from 'react';

Expand All @@ -22,24 +22,43 @@ const Demo: React.FC = () => {
});
scene.on('loaded', () => {
const drawer = new DrawPolygon(scene, {
adsorbOptions: {},
bbox: true,
});
drawer.enable();

drawer.on(DrawEvent.Change, setPolygonList);
const polygonLayer = new PolygonLayer();

polygonLayer
.source(featureCollection([]))
.shape('line')
.size(2)
.color('#fff')
.style({
opacity: 0.5,
});

scene.addLayer(polygonLayer);

drawer.on(DrawEvent.Change, (newFeatures: Feature[]) => {
setPolygonList(newFeatures);

polygonLayer.setData(
featureCollection(newFeatures.map((item) => bboxPolygon(item.bbox!))),
);
});
});
}, []);

return (
<div>
<div id={id} style={{ height: 400, position: 'relative' }} />
<div>
<pre style={{ padding: 12 }}>
{JSON.stringify(
polygonList.map((item) => item.bbox),
null,
2,
)}
</div>
</pre>
</div>
);
};
Expand Down

0 comments on commit 0007cac

Please sign in to comment.