I'm currently trying to link the markers on my leaflet map to a portion of text available to the left of the map. What I would like to have happen is when the user clicks on a marker, the site will scroll to that portion of text.
I should also note that my markers are derived from a separate geoJson file.
This is the code I intend to use once each of the markers have their unique IDs to be manipulated:
document.getElementById("A").addEventListener("click", function() {
window.location.href = "#B";
});
So in this case, "A" would be the unique ID given to one of the markers, and #B is the ID of the text I want to scroll to via the href.
*Edit
I should clarify that the primary issue is actually giving ID's to the markers from the geoJson elements I added onto the map. The relevant code for this is here:
//convert points to circles in layer
function pointToLayer(feature, latlng, attributes){
var attribute = attributes[0];
// styling for the circles which are pink with white borders
var geojsonMarkerOptions = {
fillColor: "#800000",
color: "white",
weight: 1,
opacity: 1,
fillOpacity: 0.5,
};
var layer = L.circleMarker(latlng, geojsonMarkerOptions);
//returns layer with circle markers
return layer;
//function to fill the global attribute array variable at top of page
function processData(data){
//variable to store the first feature in the data
var properties = data.features[0].properties;
//for loop to push each attribute name into array
for (var attribute in properties){
//indexOf will only allow attributes with population values to be pushed
if (attribute.indexOf("Victims") > -1){
attributes.push(attribute);
};
};
return attributes; //returns attributes array to be used in callback
};
//function to retrieve the data from geojson
function getData(map){
//load the data and calls functions
$.getJSON("data/WarCrimes3.geojson");
};