parent
04d075ddb1
commit
326c9b4dcd
@ -1,19 +1,66 @@
|
|||||||
var width = 960;
|
const width = 960;
|
||||||
var height = 490;
|
const height = 490;
|
||||||
|
|
||||||
d3.select('svg')
|
d3.select('svg')
|
||||||
.attr('width', width)
|
.attr('width', width)
|
||||||
.attr('height', height);
|
.attr('height', height);
|
||||||
|
|
||||||
var worldProjection = d3.geoEquirectangular();
|
const worldProjection = d3.geoEquirectangular();
|
||||||
|
const dAttributeFunction = d3.geoPath()
|
||||||
|
.projection(worldProjection);
|
||||||
|
|
||||||
d3.select('svg').selectAll('path')
|
d3.select('svg').selectAll('path')
|
||||||
.data(map_json.features)
|
.data(map_json.features)
|
||||||
.enter()
|
.enter()
|
||||||
.append('path')
|
.append('path')
|
||||||
.attr('fill', '#099');
|
.attr('fill', '#099')
|
||||||
|
.attr('d', dAttributeFunction);
|
||||||
|
|
||||||
var dAttributeFunction = d3.geoPath()
|
const dragBehavior = d3.drag()
|
||||||
.projection(worldProjection);
|
.on('start', (event) => {
|
||||||
|
d3.select('table tr:nth-child(2) td:first-child')
|
||||||
|
.html(worldProjection.invert([event.x, event.y])[0])
|
||||||
|
d3.select('table tr:nth-child(2) td:last-child')
|
||||||
|
.html(worldProjection.invert([event.x, event.y])[1])
|
||||||
|
|
||||||
d3.selectAll('path').attr('d', dAttributeFunction);
|
d3.selectAll('rect').remove();
|
||||||
|
d3.select('svg').append('rect')
|
||||||
|
.attr('x', event.x)
|
||||||
|
.attr('y', event.y);
|
||||||
|
})
|
||||||
|
.on('drag', (event) => {
|
||||||
|
d3.select('table tr:nth-child(3) td:first-child')
|
||||||
|
.html(worldProjection.invert([event.x, event.y])[0])
|
||||||
|
d3.select('table tr:nth-child(3) td:last-child')
|
||||||
|
.html(worldProjection.invert([event.x, event.y])[1])
|
||||||
|
|
||||||
|
d3.select('rect').attr('width', event.x-d3.select('rect').attr('x'))
|
||||||
|
d3.select('rect').attr('height', event.y-d3.select('rect').attr('y'))
|
||||||
|
})
|
||||||
|
|
||||||
|
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)
|
||||||
|
});
|
||||||
|
|||||||
@ -1,13 +1,38 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" dir="ltr">
|
<html lang="en" dir="ltr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script src="https://d3js.org/d3.v5.min.js" charset="utf-8"></script>
|
<script src="https://d3js.org/d3.v7.min.js" charset="utf-8"></script>
|
||||||
<script src="https://cdn.rawgit.com/mahuntington/mapping-demo/master/map_data3.js" charset="utf-8"></script>
|
<script src="map_data3.js" charset="utf-8"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<svg></svg>
|
<svg></svg>
|
||||||
<script src="app.js" charset="utf-8"></script>
|
<form>
|
||||||
</body>
|
Top Left:
|
||||||
|
<input type="text" placeholder="latitude"/>
|
||||||
|
<input type="text" placeholder="longitude"/>
|
||||||
|
<br/>
|
||||||
|
Bottom Right:
|
||||||
|
<input type="text" placeholder="latitude"/>
|
||||||
|
<input type="text" placeholder="longitude"/>
|
||||||
|
|
||||||
|
<input type="submit"/>
|
||||||
|
</form>
|
||||||
|
<table border="1">
|
||||||
|
<tr>
|
||||||
|
<th>lat</th>
|
||||||
|
<th>lng</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<script src="app.js" charset="utf-8"></script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue