|
|
|
@ -16,51 +16,32 @@ d3.select('svg').selectAll('path')
|
|
|
|
.attr('fill', '#099')
|
|
|
|
.attr('fill', '#099')
|
|
|
|
.attr('d', dAttributeFunction);
|
|
|
|
.attr('d', dAttributeFunction);
|
|
|
|
|
|
|
|
|
|
|
|
const dragBehavior = d3.drag()
|
|
|
|
let points = [];
|
|
|
|
.on('start', (event) => {
|
|
|
|
d3.select('svg').on('click', (event)=>{
|
|
|
|
d3.select('table tr:nth-child(2) td:first-child')
|
|
|
|
points.push([event.x, event.y])
|
|
|
|
.html(worldProjection.invert([event.x, event.y])[0])
|
|
|
|
const path = d3.path();
|
|
|
|
d3.select('table tr:nth-child(2) td:last-child')
|
|
|
|
path.moveTo(points[0][0], points[0][1])
|
|
|
|
.html(worldProjection.invert([event.x, event.y])[1])
|
|
|
|
for(let i = 1; i < points.length; i++){
|
|
|
|
|
|
|
|
path.lineTo(points[i][0], points[i][1])
|
|
|
|
d3.selectAll('rect').remove();
|
|
|
|
}
|
|
|
|
d3.select('svg').append('rect')
|
|
|
|
path.closePath()
|
|
|
|
.attr('x', event.x)
|
|
|
|
d3.select('#polygon').remove()
|
|
|
|
.attr('y', event.y);
|
|
|
|
d3.select('svg')
|
|
|
|
|
|
|
|
.append('path')
|
|
|
|
|
|
|
|
.attr('id', 'polygon')
|
|
|
|
|
|
|
|
.attr('fill', 'black')
|
|
|
|
|
|
|
|
.attr('d', path)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.on('drag', (event) => {
|
|
|
|
d3.select('body').on('keydown', (event)=>{
|
|
|
|
d3.select('table tr:nth-child(3) td:first-child')
|
|
|
|
d3.select('tbody').html('');
|
|
|
|
.html(worldProjection.invert([event.x, event.y])[0])
|
|
|
|
const coords = points.map(point => worldProjection.invert(point))
|
|
|
|
d3.select('table tr:nth-child(3) td:last-child')
|
|
|
|
for(coord of coords){
|
|
|
|
.html(worldProjection.invert([event.x, event.y])[1])
|
|
|
|
const row = d3.select('tbody')
|
|
|
|
|
|
|
|
.append('tr')
|
|
|
|
d3.select('rect').attr('width', event.x-d3.select('rect').attr('x'))
|
|
|
|
row.append('td')
|
|
|
|
d3.select('rect').attr('height', event.y-d3.select('rect').attr('y'))
|
|
|
|
.html(coord[0])
|
|
|
|
|
|
|
|
row.append('td')
|
|
|
|
|
|
|
|
.html(coord[1])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
points = [];
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
d3.select('svg').call(dragBehavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d3.select('form').on('submit', (event) => {
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d3.selectAll('rect').remove();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lat1 = d3.select('input:first-child').property('value');
|
|
|
|
|
|
|
|
const lng1 = d3.select('input:nth-child(2)').property('value');
|
|
|
|
|
|
|
|
const location1 = worldProjection([lat1, lng1]);
|
|
|
|
|
|
|
|
const x1 = location1[0];
|
|
|
|
|
|
|
|
const y1 = location1[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lat2 = d3.select('input:nth-child(4)').property('value');
|
|
|
|
|
|
|
|
const lng2 = d3.select('input:nth-child(5)').property('value');
|
|
|
|
|
|
|
|
const location2 = worldProjection([lat2, lng2]);
|
|
|
|
|
|
|
|
const x2 = location2[0];
|
|
|
|
|
|
|
|
const y2 = location2[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d3.select('svg').append('rect')
|
|
|
|
|
|
|
|
.attr('fill', '#000')
|
|
|
|
|
|
|
|
.attr('x', x1)
|
|
|
|
|
|
|
|
.attr('y', y1)
|
|
|
|
|
|
|
|
.attr('width', x2-x1)
|
|
|
|
|
|
|
|
.attr('height', y2-y1)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|