72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
import React from 'react';
|
|
import GisApp from './lib/gis.core';
|
|
import GisOlMeasure from './lib/gis.measure';
|
|
import { useContext } from 'react';
|
|
import { useGisContext } from './Gis';
|
|
export default React.memo(function GisToolBar() {
|
|
const { gisMap } = useGisContext();
|
|
if (!gisMap) return <></>;
|
|
const gisMeasuer = new GisOlMeasure(gisMap);
|
|
GisApp.Module.measure = gisMeasuer;
|
|
const zoomIn = () => {
|
|
if (gisMap.getView().getMaxZoom() > gisMap.getView().getZoom()) {
|
|
gisMap.getView().animate({
|
|
zoom: gisMap.getView().getZoom() + 1,
|
|
duration: 250,
|
|
});
|
|
}
|
|
};
|
|
const zoomOut = () => {
|
|
if (gisMap.getView().getMaxZoom() > gisMap.getView().getZoom()) {
|
|
gisMap.getView().animate({
|
|
zoom: gisMap.getView().getZoom() - 1,
|
|
duration: 250,
|
|
});
|
|
}
|
|
};
|
|
|
|
const measure = type => {
|
|
gisMeasuer.addInteraction(type);
|
|
};
|
|
|
|
const reset = () => {
|
|
gisMeasuer.removeFeature();
|
|
};
|
|
return (
|
|
<>
|
|
<div className="custom-toolbar">
|
|
<div className="tool-bar">
|
|
<h3>toolbar 영역</h3>
|
|
<ul>
|
|
<li>
|
|
<div className="btn_control_zoomin" title="확대" onClick={zoomIn}>
|
|
<span>확대</span>
|
|
</div>
|
|
</li>
|
|
<li>
|
|
<div className="btn_control_zoomout" title="축소" onClick={zoomOut}>
|
|
<span>축소</span>
|
|
</div>
|
|
</li>
|
|
<li>
|
|
<div className="btn_control_ruler btn_control_measure" title="거리 측정" onClick={() => measure(GisApp.measure.LineString)}>
|
|
<span>거리측정</span>
|
|
</div>
|
|
</li>
|
|
<li>
|
|
<div className="btn_control_area btn_control_measure" title="면적 측정" onClick={() => measure(GisApp.measure.Polygon)}>
|
|
<span>면적측정</span>
|
|
</div>
|
|
</li>
|
|
<li>
|
|
<div className="sprite_gis icon4 btn_select_cancel" title="리셋" onClick={() => reset()}>
|
|
<span>리셋</span>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
});
|