lundi 25 mars 2019

Bring up different info boxes for each marker on the map after clicking on it

I'm trying to make an interactive map with markers, that would bring up a box with information about the place. I'm using MapBox API and I managed to add a marker using GEOJSON

var geojson = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "marker-color": "#7e7e7e",
        "marker-size": "medium",
        "marker-symbol": "",
        "name": "zamek"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          17.968410551548004,
          49.47832705255177
        ]
      }
    }
  ]
}

Now I need to assign an event to that marker that would bring a text box specific for the place of the marker. I don't have any experiences with Js, I'm basically learning in this process.

So what would be the best way to do it? My info box would be a div that would "slide in" from the left side of the screen (its a div with 100% height and 300px width placed on left: -300px) with appropriate information. My only idea was to use some kind of database (it may be a total non-sense since I'm just a noob) with all the titles, texts, etc . and change the info box content based on which marker was clicked on.

Example: If I click on the castle, the website pulls the necesseary text from database for a "castle", puts it in the info box and displays it.

I would really appreciate any help with this, as I said, I've just started studying the magic of interactive web making and js so please correct any non senses I've said in this (also I know my english isn't by any means good, so please don't blame me).




Aucun commentaire:

Enregistrer un commentaire