Turbo87 / leaflet-sidebar

A responsive sidebar for Leaflet maps
http://turbo87.github.io/leaflet-sidebar/examples/
MIT License
487 stars 157 forks source link

Load file inside sidebar #42

Closed htwmehdi closed 8 years ago

htwmehdi commented 8 years ago

Hello,

How can i load a file and insert it into the sidebar div ? I have many markers, and each one have a seperate file with datas to be shown in the sidebar, i have tried the .setContent function, but i do have a php function that runs a query that must be displayed in the sidebar.

thank you

zedd45 commented 8 years ago

The loading of the file contents and the displaying are two different concerns:

  1. you can use fetch or ajax (jQuery flavored or otherwise) to make a request to the server that returns the file contents.
  2. .setContent method takes a String and sets the content of the sidebar to that string

assuming

var sidebar = L.control.sidebar( 
   //...
);

Therefore, once you have loaded the string / text you want from PHP via your desired method, you can just call sidebar.setContent(myStringFromTheSever).

It sounds like you need to load a different string for each server request, so just call setContent when you want to update it again.

Feel free to elaborate on the issue more, but I'm closing this for now.