fix: change diameter to radius
This commit is contained in:
parent
1431aab04a
commit
aeb1b32441
|
@ -10,5 +10,6 @@ export interface ContentTable {
|
||||||
author: string
|
author: string
|
||||||
description: string
|
description: string
|
||||||
created_at: string
|
created_at: string
|
||||||
|
radius: number
|
||||||
unlocked_counter: number
|
unlocked_counter: number
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,11 +85,7 @@ const backendUrl = import.meta.env.PUBLIC_BACKEND_URL
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<input name='geolocation' id='geolocation-input' hidden />
|
<input name='geolocation' id='geolocation-input' hidden />
|
||||||
<input
|
<input name='geolocation-radius' id='geolocation-radius-input' hidden />
|
||||||
name='geolocation-diameter'
|
|
||||||
id='geolocation-diameter-input'
|
|
||||||
hidden
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -144,11 +144,15 @@ import { CalendarIcon } from "@radix-ui/react-icons"
|
||||||
const lockedContentContainer = document.getElementById(
|
const lockedContentContainer = document.getElementById(
|
||||||
"locked-content-container"
|
"locked-content-container"
|
||||||
)
|
)
|
||||||
if (lockedContentContainer)
|
if (lockedContentContainer) {
|
||||||
lockedContentContainer.dataset.targetPosition = data?.loc
|
lockedContentContainer.dataset.targetPosition = data?.loc
|
||||||
|
}
|
||||||
|
|
||||||
const leafletMap = document.getElementById("map")
|
const leafletMap = document.getElementById("map")
|
||||||
if (leafletMap) leafletMap.dataset.targetLocation = data?.loc
|
if (leafletMap) {
|
||||||
|
leafletMap.dataset.targetLocation = data?.loc
|
||||||
|
leafletMap.dataset.targetRadius = data?.radius.toString() ?? "50"
|
||||||
|
}
|
||||||
|
|
||||||
initMap()
|
initMap()
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ const targetLocationControl = new GoToTargetLocation({
|
||||||
position: "bottomleft",
|
position: "bottomleft",
|
||||||
})
|
})
|
||||||
|
|
||||||
function addTargetLocationMarker(target: TargetLocation) {
|
function addTargetLocationMarker(target: TargetLocation, radius = 50) {
|
||||||
if (target) {
|
if (target) {
|
||||||
L.marker(target, { icon: targetLocationIcon }).addTo(map)
|
L.marker(target, { icon: targetLocationIcon }).addTo(map)
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ function addTargetLocationMarker(target: TargetLocation) {
|
||||||
color: "blue",
|
color: "blue",
|
||||||
fillColor: "#30f",
|
fillColor: "#30f",
|
||||||
fillOpacity: 0.2,
|
fillOpacity: 0.2,
|
||||||
radius: 50,
|
radius,
|
||||||
}).addTo(map)
|
}).addTo(map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ export function initMap() {
|
||||||
map = L.map("map")
|
map = L.map("map")
|
||||||
|
|
||||||
const targetLocation = mapEl?.dataset.targetLocation
|
const targetLocation = mapEl?.dataset.targetLocation
|
||||||
|
const targetRadius = mapEl?.dataset.targetRadius
|
||||||
|
|
||||||
const data = targetLocation ? JSON.parse(targetLocation) : null
|
const data = targetLocation ? JSON.parse(targetLocation) : null
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ export function initMap() {
|
||||||
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
||||||
}).addTo(map)
|
}).addTo(map)
|
||||||
|
|
||||||
addTargetLocationMarker(TARGET_LOCATION)
|
addTargetLocationMarker(TARGET_LOCATION, Number(targetRadius))
|
||||||
targetLocationControl.addTo(map)
|
targetLocationControl.addTo(map)
|
||||||
goToCurrentLocationControl.addTo(map)
|
goToCurrentLocationControl.addTo(map)
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,11 +89,11 @@ const AskPermissonControl = L.Control.extend({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const DiameterControl = L.Control.extend({
|
const RadiusControl = L.Control.extend({
|
||||||
onAdd: function (map: L.Map) {
|
onAdd: function (map: L.Map) {
|
||||||
const diameterContainer = document.createElement("div")
|
const radiusContainer = document.createElement("div")
|
||||||
|
|
||||||
diameterContainer.classList.add(
|
radiusContainer.classList.add(
|
||||||
"bg-white",
|
"bg-white",
|
||||||
"h-[40px]",
|
"h-[40px]",
|
||||||
"p-2",
|
"p-2",
|
||||||
|
@ -102,7 +102,7 @@ const DiameterControl = L.Control.extend({
|
||||||
"gap-2"
|
"gap-2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const diameterButtonClasses = [
|
const radiusButtonClasses = [
|
||||||
"text-xl",
|
"text-xl",
|
||||||
"border-2",
|
"border-2",
|
||||||
"border-slate-700",
|
"border-slate-700",
|
||||||
|
@ -115,89 +115,79 @@ const DiameterControl = L.Control.extend({
|
||||||
"hover:bg-gray-300",
|
"hover:bg-gray-300",
|
||||||
]
|
]
|
||||||
|
|
||||||
const diameterIncreaseButton = document.createElement("button")
|
const radiusIncreaseButton = document.createElement("button")
|
||||||
|
|
||||||
diameterIncreaseButton.classList.add(...diameterButtonClasses)
|
radiusIncreaseButton.classList.add(...radiusButtonClasses)
|
||||||
|
|
||||||
const diameterDecreaseButton = document.createElement("button")
|
const radiusDecreaseButton = document.createElement("button")
|
||||||
|
|
||||||
diameterIncreaseButton.type = "button"
|
radiusIncreaseButton.type = "button"
|
||||||
|
|
||||||
diameterDecreaseButton.type = "button"
|
radiusDecreaseButton.type = "button"
|
||||||
|
|
||||||
diameterDecreaseButton.classList.add(...diameterButtonClasses)
|
radiusDecreaseButton.classList.add(...radiusButtonClasses)
|
||||||
|
|
||||||
const diameterContainerText = document.createElement("p")
|
const radiusContainerText = document.createElement("p")
|
||||||
|
|
||||||
const diameterText = document.createElement("p")
|
const radiusText = document.createElement("p")
|
||||||
|
|
||||||
diameterContainerText.classList.add("text-xl")
|
radiusContainerText.classList.add("text-xl")
|
||||||
|
|
||||||
diameterText.classList.add("text-xl")
|
radiusText.classList.add("text-xl")
|
||||||
|
|
||||||
diameterIncreaseButton.textContent = "+"
|
radiusIncreaseButton.textContent = "+"
|
||||||
|
|
||||||
diameterDecreaseButton.textContent = "-"
|
radiusDecreaseButton.textContent = "-"
|
||||||
|
|
||||||
diameterContainerText.textContent = "Çap: "
|
radiusContainerText.textContent = "Çap: "
|
||||||
|
|
||||||
diameterText.textContent = `${targetLocationCircleRadius.toString()}m`
|
radiusText.textContent = `${targetLocationCircleRadius.toString()}m`
|
||||||
|
|
||||||
diameterContainer.insertAdjacentElement(
|
radiusContainer.insertAdjacentElement("afterbegin", radiusIncreaseButton)
|
||||||
"afterbegin",
|
|
||||||
diameterIncreaseButton
|
|
||||||
)
|
|
||||||
|
|
||||||
diameterContainer.insertAdjacentElement("afterbegin", diameterText)
|
radiusContainer.insertAdjacentElement("afterbegin", radiusText)
|
||||||
|
|
||||||
diameterContainer.insertAdjacentElement(
|
radiusContainer.insertAdjacentElement("afterbegin", radiusDecreaseButton)
|
||||||
"afterbegin",
|
|
||||||
diameterDecreaseButton
|
|
||||||
)
|
|
||||||
|
|
||||||
diameterContainer.insertAdjacentElement("afterbegin", diameterContainerText)
|
radiusContainer.insertAdjacentElement("afterbegin", radiusContainerText)
|
||||||
|
|
||||||
diameterContainer.id = "diameter-control"
|
radiusContainer.id = "radius-control"
|
||||||
|
|
||||||
L.DomEvent.on(diameterIncreaseButton, "click", (ev) => {
|
L.DomEvent.on(radiusIncreaseButton, "click", (ev) => {
|
||||||
targetLocationCircleRadius = Math.min(
|
targetLocationCircleRadius = Math.min(
|
||||||
targetLocationCircleRadius + 100,
|
targetLocationCircleRadius + 100,
|
||||||
2000
|
2000
|
||||||
)
|
)
|
||||||
targetLocationCircle.setRadius(targetLocationCircleRadius)
|
targetLocationCircle.setRadius(targetLocationCircleRadius)
|
||||||
|
|
||||||
diameterText.innerText = `${targetLocationCircleRadius.toString()}m`
|
radiusText.innerText = `${targetLocationCircleRadius.toString()}m`
|
||||||
updateInputValue(
|
updateInputValue(
|
||||||
"geolocation-diameter-input",
|
"geolocation-radius-input",
|
||||||
targetLocationCircleRadius.toString()
|
targetLocationCircleRadius.toString()
|
||||||
)
|
)
|
||||||
L.DomEvent.stop(ev)
|
L.DomEvent.stop(ev)
|
||||||
})
|
})
|
||||||
|
|
||||||
L.DomEvent.on(diameterIncreaseButton, "dblclick", (ev) =>
|
L.DomEvent.on(radiusIncreaseButton, "dblclick", (ev) => L.DomEvent.stop(ev))
|
||||||
L.DomEvent.stop(ev)
|
|
||||||
)
|
|
||||||
|
|
||||||
L.DomEvent.on(diameterDecreaseButton, "click", (ev) => {
|
L.DomEvent.on(radiusDecreaseButton, "click", (ev) => {
|
||||||
targetLocationCircleRadius = Math.max(
|
targetLocationCircleRadius = Math.max(
|
||||||
targetLocationCircleRadius - 100,
|
targetLocationCircleRadius - 100,
|
||||||
50
|
50
|
||||||
)
|
)
|
||||||
targetLocationCircle.setRadius(targetLocationCircleRadius)
|
targetLocationCircle.setRadius(targetLocationCircleRadius)
|
||||||
diameterText.innerText = `${targetLocationCircleRadius.toString()}m`
|
radiusText.innerText = `${targetLocationCircleRadius.toString()}m`
|
||||||
updateInputValue(
|
updateInputValue(
|
||||||
"geolocation-diameter-input",
|
"geolocation-radius-input",
|
||||||
targetLocationCircleRadius.toString()
|
targetLocationCircleRadius.toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
L.DomEvent.stop(ev)
|
L.DomEvent.stop(ev)
|
||||||
})
|
})
|
||||||
|
|
||||||
L.DomEvent.on(diameterDecreaseButton, "dblclick", (ev) =>
|
L.DomEvent.on(radiusDecreaseButton, "dblclick", (ev) => L.DomEvent.stop(ev))
|
||||||
L.DomEvent.stop(ev)
|
|
||||||
)
|
|
||||||
|
|
||||||
return diameterContainer
|
return radiusContainer
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -207,7 +197,7 @@ const currentLocationControl = new CurrentLocationControl({
|
||||||
position: "bottomleft",
|
position: "bottomleft",
|
||||||
})
|
})
|
||||||
|
|
||||||
const diameterControl = new DiameterControl({ position: "bottomright" })
|
const radiusControl = new RadiusControl({ position: "bottomright" })
|
||||||
|
|
||||||
askPermissionControl.addTo(map)
|
askPermissionControl.addTo(map)
|
||||||
|
|
||||||
|
@ -229,7 +219,7 @@ map.on("click", (e) => {
|
||||||
radius: targetLocationCircleRadius,
|
radius: targetLocationCircleRadius,
|
||||||
}).addTo(map)
|
}).addTo(map)
|
||||||
|
|
||||||
diameterControl.addTo(map)
|
radiusControl.addTo(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
const pos = targetLocationMarker.getLatLng()
|
const pos = targetLocationMarker.getLatLng()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user