Browse Source

Merge branch 'master' of http://gitea.palntour.com/pav/pav-home

pull/2/head
노승철 2 years ago
parent
commit
34566fab96
  1. 1406
      package-lock.json
  2. 2
      package.json
  3. 4
      src/components/mapDraw/naver/NaverMap.js
  4. 150
      src/components/mapDraw/naver/draw/JQueryDraw.js

1406
package-lock.json generated

File diff suppressed because it is too large Load Diff

2
package.json

@ -14,6 +14,8 @@
"@fullcalendar/timeline": "5.7.2", "@fullcalendar/timeline": "5.7.2",
"@hookform/resolvers": "1.3.4", "@hookform/resolvers": "1.3.4",
"@stomp/stompjs": "^6.1.0", "@stomp/stompjs": "^6.1.0",
"@turf/buffer": "^6.5.0",
"@turf/turf": "^6.5.0",
"@types/googlemaps": "^3.43.3", "@types/googlemaps": "^3.43.3",
"@types/history": "^4.7.8", "@types/history": "^4.7.8",
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",

4
src/components/mapDraw/naver/NaverMap.js

@ -49,9 +49,7 @@ export const NaverCustomMap = () => {
{/* 그리기 도구 모음 불러오는 거 */} {/* 그리기 도구 모음 불러오는 거 */}
<DrawMap map={mapObject} naver={naver} /> <DrawMap map={mapObject} naver={naver} />
{/* <Test map={mapObject} naver={naver} /> */}
{/* <JQueryConv map={mapObject} naver={naver} /> */}
</> </>
) : null} ) : null}

150
src/components/mapDraw/naver/draw/JQueryDraw.js

@ -2,10 +2,7 @@ import $ from 'jquery';
import '../../../../assets/css/custom.css'; import '../../../../assets/css/custom.css';
import { CustomInput } from 'reactstrap'; import { CustomInput } from 'reactstrap';
import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader' import buffer from '@turf/buffer'
import GeoJSONWriter from 'jsts/org/locationtech/jts/io/GeoJSONWriter'
import GeometryFactory from 'jsts/org/locationtech/jts/geom/GeometryFactory'
import {BufferOp} from 'jsts/org/locationtech/jts/operation/buffer'
export const JQueryDraw = props => { export const JQueryDraw = props => {
const {naver} = props; const {naver} = props;
@ -108,54 +105,67 @@ export const JQueryDraw = props => {
if (this._polyline) { if (this._polyline) {
// console.log(this._polyline.getPath()._array, 'path') // console.log(this._polyline.getPath()._array, 'path')
let te = this._polyline.getPath()._array; let polypaths = this._polyline.getPath()._array;
let co = [];
for(let i = 0; i< te.length; i++) {
co.push([te[i]._lat, te[i]._lng]);
}
console.log(co, 'co')
let coords = { //파싱
"type": "LineString", let polypathJSON = new Array();
"coordinates": co for(let i = 0; i< polypaths.length; i++) {
};
const reader = new GeoJSONReader(); //파싱
const writer = new GeoJSONWriter(); let obj = new Object();
const distance = (100 * 0.001) / 111.12; obj.x = '' + polypaths[i]._lng + '';
const line = reader.read(coords); obj.y = '' + polypaths[i]._lat + '';
const buffer = BufferOp.bufferOp(line, distance);
const polygon = writer.write(buffer);
// console.log(buffer._shell._points._coordinates, 'coords'); obj = JSON.stringify(obj);
let bu = buffer._shell._points._coordinates; polypathJSON.push(JSON.parse(obj));
let buffers = [];
for(let i = 0; i< bu.length; i++) {
buffers.push([bu[i].y, bu[i].x]);
} }
console.log(buffers, 'buffers') console.log(polypathJSON, 'json polyline path')
const poly = new naver.maps.Polyline({ //버퍼 생성에 필요한 coordinates 배열 변환
let lineStringPaths = [];
for(let i = 0; i < this._polyline.getPath().length; i++) {
lineStringPaths.push([this._polyline.getPath()._array[i].x, this._polyline.getPath()._array[i].y]);
}
console.log(lineStringPaths, 'polyline path')
//버퍼 생성을 위한 line 객체
const originalGeojson = {
type: "FeatureCollection",
features: [
{
type: "Feature",
properties: {},
geometry: {
type: "LineString",
coordinates: lineStringPaths
}
}
]
};
console.log(originalGeojson)
//버퍼 객체
const bufferObj = buffer(originalGeojson, 50, {units:'meters'});
//버퍼 라인 생성
let bufferPath = bufferObj.features[0].geometry.coordinates[0];
console.log(bufferPath, 'buffer path')
this.bufferPolyline = new naver.maps.Polyline({
strokeColor: '#ff0000', strokeColor: '#ff0000',
strokeWeight: 2, strokeWeight: 2,
strokeStyle: [4, 4], strokeStyle: [4, 4],
strokeOpacity: 0.6, strokeOpacity: 0.6,
path : buffers, path : bufferPath,
map: map map: map
}) });
console.log(poly, 'poly')
// 이거 하면 그동안 한거 싹 사라짐 -> 얘를 통해서 drawType이 바뀌면 다 날라가는 걸로 해보면 될듯 // 이거 하면 그동안 한거 싹 사라짐 -> 얘를 통해서 drawType이 바뀌면 다 날라가는 걸로 해보면 될듯
// this._polyline.setMap(null) // this._polyline.setMap(null)
delete this._polyline; delete this._polyline;
//버퍼 테스트
delete this._buffercircle;
delete this._buffercoord;
} }
//onfocus()의 반대기능 = blur() //onfocus()의 반대기능 = blur()
this.$btnLine.removeClass('control-on').blur(); this.$btnLine.removeClass('control-on').blur();
@ -241,13 +251,56 @@ export const JQueryDraw = props => {
} }
}, },
_fromMetersToText: function(meters) {
meters = meters || 0;
var km = 1000,
text = meters;
if(meters >= km) {
text = parseFloat((meters / km).toFixed(1)) + 'km';
} else {
text = parseFloat(meters.toFixed(1)) + 'm';
}
return text;
},
_addMileStone: function(coord, text, css) {
if(!this._ms) this._ms = [];
let content;
if(text == 'Start') {
content = '<div style="display:inline-block;padding:5px;text-align:center;background-color:#fff;border:1px solid #000;font-size:14px;color:#ff0000;"><span>'+ text +'</span></div>'
} else {
content = '<div style="display:inline-block;padding:5px;text-align:center;background-color:#fff;border:1px solid #000;color:#737373;"><span>'+ text +'</span></div>'
}
var ms = new naver.maps.Marker({
position: coord,
icon: {
content: content,
anchor: new naver.maps.Point(-5, -5)
},
map: this.map
});
var msElement = $(ms.getElement());
if(css) {
msElement.css(css);
} else {
msElement.css('font-size', '13px');
}
this._ms.push(ms);
},
_onClickDistance: function(e) { _onClickDistance: function(e) {
console.log('onClickDistance') console.log('onClickDistance')
var map = this.map, var map = this.map,
coord = e.coord; coord = e.coord;
// console.log(coord, '클릭좌표1');
if (!this._polyline) { if (!this._polyline) {
// 임시로 보여줄 점선 폴리라인을 생성합니다. // 임시로 보여줄 점선 폴리라인을 생성합니다.
this._guideline = new naver.maps.Polyline({ this._guideline = new naver.maps.Polyline({
@ -275,9 +328,16 @@ export const JQueryDraw = props => {
map: map map: map
}); });
this._lastDistance = this._polyline.getDistance();
this._addMileStone(coord, 'Start');
} else { } else {
this._guideline.setPath([e.coord]); this._guideline.setPath([e.coord]);
this._polyline.getPath().push(coord); this._polyline.getPath().push(coord);
var distance = this._polyline.getDistance();
this._addMileStone(coord, this._fromMetersToText(distance - this._lastDistance));
this._lastDistance = distance;
} }
}, },
@ -520,11 +580,11 @@ export const JQueryDraw = props => {
this._polyline.setMap(null); this._polyline.setMap(null);
delete this._polyline; delete this._polyline;
this._buffercircle.setMap(null); // this._buffercircle.setMap(null);
delete this._buffercircle; // delete this._buffercircle;
this._buffercoord.setMap(null) // this._buffercoord.setMap(null)
delete this._buffercoord; // delete this._buffercoord;
} }
this._finishDistance(); this._finishDistance();
@ -590,12 +650,6 @@ export const JQueryDraw = props => {
className='control-btn' className='control-btn'
src='http://static.naver.net/maps/mantle/drawing/1x/rectangle.png' src='http://static.naver.net/maps/mantle/drawing/1x/rectangle.png'
/> />
<br/>
<CustomInput
id='input'
type='input'
className='buffer-input'
/>
</li> </li>
</ul> </ul>
</div> </div>

Loading…
Cancel
Save