Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
HIRE Promotionskolleg Team
Study Areas Map
Commits
fb4794c6
Commit
fb4794c6
authored
Aug 29, 2024
by
Alfakhori
Browse files
Update public/js/script.js
parent
eee94b25
Pipeline
#10059
passed with stage
in 5 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
public/js/script.js
0 → 100644
View file @
fb4794c6
const
map
=
L
.
map
(
'
map
'
).
setView
([
51.505
,
-
0.09
],
13
);
// Add OSM base map
L
.
tileLayer
(
'
https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
'
,
{
maxZoom
:
19
,
}).
addTo
(
map
);
// Function to load pins from CSV and add them to the map
function
loadPins
()
{
Papa
.
parse
(
'
/data/pins.csv
'
,
{
download
:
true
,
header
:
true
,
complete
:
function
(
results
)
{
results
.
data
.
forEach
(
pin
=>
{
if
(
pin
.
lat
&&
pin
.
lng
&&
pin
.
name
&&
pin
.
color
)
{
const
marker
=
L
.
marker
([
parseFloat
(
pin
.
lat
),
parseFloat
(
pin
.
lng
)],
{
title
:
pin
.
name
,
icon
:
L
.
divIcon
({
className
:
'
custom-pin
'
,
html
:
`<div style="background-color:
${
pin
.
color
}
;" class="pin"></div>`
})
}).
addTo
(
map
);
marker
.
bindPopup
(
`<b>
${
pin
.
name
}
</b>`
);
}
});
}
});
}
// Call the function to load pins from the CSV
loadPins
();
// Add click event to the map to add new pins
map
.
on
(
'
click
'
,
function
(
e
)
{
const
name
=
prompt
(
"
Enter pin name:
"
);
const
color
=
prompt
(
"
Enter pin color (e.g., red, #ff0000):
"
);
if
(
name
&&
color
)
{
const
newPin
=
{
lat
:
e
.
latlng
.
lat
,
lng
:
e
.
latlng
.
lng
,
name
:
name
,
color
:
color
};
// Save the pin to the CSV file
addPinToCSV
(
newPin
);
// Add the new pin to the map
const
marker
=
L
.
marker
([
newPin
.
lat
,
newPin
.
lng
],
{
title
:
newPin
.
name
,
icon
:
L
.
divIcon
({
className
:
'
custom-pin
'
,
html
:
`<div style="background-color:
${
newPin
.
color
}
;" class="pin"></div>`
})
}).
addTo
(
map
);
marker
.
bindPopup
(
`<b>
${
newPin
.
name
}
</b>`
);
}
});
// Function to add a pin to the CSV (simulated by logging to the console)
function
addPinToCSV
(
pin
)
{
const
csvLine
=
`
${
pin
.
lat
}
,
${
pin
.
lng
}
,
${
pin
.
name
}
,
${
pin
.
color
}
\n`
;
console
.
log
(
"
Pin to add to CSV:
"
,
csvLine
);
// Note: This will only log to the console since we cannot write to files on GitHub Pages
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment