Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/#18_connect_static_map #20

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added icon/.DS_Store
Binary file not shown.
Binary file added icon/curr_pos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/minus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html><head><meta charset="utf-8"><title>Sparta front</title><script defer="defer" src="main.bundle.js"></script></head><body></body></html>
<!doctype html><html><head><meta charset="utf-8"><title>Sparta front</title><script defer="defer" src="main.bundle.js"></script></head><body><div class="loginField"><div class="login"><h2>Login</h2><div class="loginSocial"><button type="button" class="btn42"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/42_Logo.svg/1024px-42_Logo.svg.png" height="40px," weight="20px" alt="42logo"></button></div></div></div></body></html>
2 changes: 1 addition & 1 deletion main.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sparta front</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<title>간단한 지도 표시하기</title>
</head>
<body>

<div>
</div>
</body>
</html>
</html>
12 changes: 8 additions & 4 deletions public/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
$body-color: red;
.btn_img {
width: 10px;
height: 10px;
cursor: pointer;
}

body {
color: $body-color;
}
.map_img {
cursor: pointer;
}
111 changes: 93 additions & 18 deletions srcs/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,99 @@
const app = elem => {
const state = {text: 1};
import '../public/style.scss'
const mapsUrl = 'https://naveropenapi.apigw.ntruss.com/map-static/v2/raster-cors?'

const $elem = document.querySelector(elem);
let latitude = undefined
let longitude = undefined
let width = 800
let height = 700
let centerX = 127.061838
let centerY = 37.490211
let levelDist = 16 * 10
let level = 16
let apiKeyID = '9cdskm4clv'

const render = () => {
$elem.innerHTML = `
<h1>
${state.text}
</h1>
`;
};
navigator.geolocation.getCurrentPosition((pos) => {
latitude = pos.coords.latitude
longitude = pos.coords.longitude
if (latitude === undefined || longitude === undefined)
alert('can\'t load current position!')
else console.log(longitude, latitude)
})
const elem = document.createElement('div')
loadMap()
function loadMap() {
elem.innerHTML = `
<div>
<img id='mapsApi' class='map_img' src=${mapsUrl}w=${width}&h=${height}&center=${centerX},${centerY}&level=${level}&X-NCP-APIGW-API-KEY-ID=${apiKeyID}>
<img id='currPos' class='btn_img' src='./../icon/curr_pos.png'>
<img id='zoomUp' class='btn_img' src='./../icon/plus.png'>
<img id='zoomDown' class='btn_img' src='./../icon/minus.png'>
</div>
`

$elem.addEventListener('click', () => {
state.text = state.text + 1;
render();
});
document.querySelector('div').appendChild(elem)
document.getElementById('mapsApi').addEventListener("wheel", wheelEvent)
document.getElementById('currPos').addEventListener('click', currPoint)
document.getElementById('zoomUp').addEventListener('click', () => {
if (level < 19)
level += 1
levelDist = level * 10
loadMap()
})
document.getElementById('zoomDown').addEventListener('click', () => {
if (level > 5)
level -= 1
levelDist = level * 10
loadMap()
})
document.getElementById('mapsApi').addEventListener('click', (e) => {
let latLng = calLatitudeLongitude(e.offsetX, e.offsetY)
centerX = latLng[0]
centerY = latLng[1]
console.log(latLng[0], latLng[1])
loadMap()
})
}

render();

return $elem;
};
function wheelEvent() {
window.onmousewheel = function(e) {
if (e.wheelDelta === -120 && levelDist / 10 > 5)
levelDist -= 1;
else if (e.wheelDelta === 120 && levelDist / 10 < 18)
levelDist += 1;
}
if (level != parseInt(levelDist / 10))
{
level = parseInt(levelDist / 10)
loadMap()
}
}

app('body');
function currPoint() {
if (centerX !== latitude & centerY !== longitude) {
navigator.geolocation.getCurrentPosition((pos) => {
latitude = pos.coords.latitude
longitude = pos.coords.longitude
})
if (longitude === undefined || latitude === undefined)
alert('can\'t load current position!')
else {
centerX = longitude
centerY = latitude
}
loadMap()
}
}

function calLatitudeLongitude(w, h) {
let C = (256 / (2 * Math.PI)) * Math.pow(2, level + 1)
let x = C * (centerX * Math.PI / 180 + Math.PI)
let y = C * (Math.PI - Math.log(Math.tan((Math.PI / 4) + centerY * Math.PI / 180 / 2)))
let xp = x - (width / 2 - w)
let yp = y - (height / 2 - h)
let M = (xp / C) - Math.PI
let N = -(yp / C) + Math.PI
let lon_p = M / Math.PI * 180
let lat_p = ((Math.atan(Math.exp(N)) - (Math.PI / 4)) * 2) / Math.PI * 180
return [lon_p, lat_p]
}