OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Assign ID to marker in leaflet

  • Thread starter Thread starter lauWM
  • Start date Start date
L

lauWM

Guest
So i try to achieve a result as on foursquare: https://foursquare.com/explore?cat=drinks&mode=url&near=Paris which is when you clik on a marker on the map, it scrolls through the listed of restaurants on the right -hand side of the screen to the ad hoc restaurant, and highlights it through CSS. Conversely, when you click on the restaurant on the list, it highlights it on the map.

I am using skobbler/leaflet. I think I can achieve this by amending dynamically CSS as shown in this example: http://jsfiddle.net/gU4sw/7/ + a scroll to destination script already in place in the page.

To achieve this however, it looks like I need to assign an ID within the markers (2 markers below):

Code:
var marker = L.marker([52.52112, 13.40554]).addTo(map);
marker.bindPopup("Hello world!<br>I am a popup1.", { offset: new L.Point(-1, -41) }).openPopup();

var marker = L.marker([52.53552, 13.41994]).addTo(map);
marker.bindPopup("Hello world!<br>I am a popup2.", { offset: new L.Point(-1, -41) }).openPopup();

Question is: How can I assign an marker ID to trigger css change in the corresponding element within my html page?

My knowledge of JS is very limited, but may be there's a nice and easy solution out there, thx

<p>So i try to achieve a result as on foursquare: <a href="https://foursquare.com/explore?cat=drinks&mode=url&near=Paris" rel="noreferrer">https://foursquare.com/explore?cat=drinks&mode=url&near=Paris</a> which is when you clik on a marker on the map, it scrolls through the listed of restaurants on the right -hand side of the screen to the ad hoc restaurant, and highlights it through CSS. Conversely, when you click on the restaurant on the list, it highlights it on the map.</p>

<p>I am using skobbler/leaflet. I think I can achieve this by amending dynamically CSS as shown in this example: <a href="http://jsfiddle.net/gU4sw/7/" rel="noreferrer">http://jsfiddle.net/gU4sw/7/</a> + a scroll to destination script already in place in the page. </p>

<p>To achieve this however, it looks like I need to assign an ID within the markers (2 markers below): </p>

<pre><code>var marker = L.marker([52.52112, 13.40554]).addTo(map);
marker.bindPopup("Hello world!<br>I am a popup1.", { offset: new L.Point(-1, -41) }).openPopup();

var marker = L.marker([52.53552, 13.41994]).addTo(map);
marker.bindPopup("Hello world!<br>I am a popup2.", { offset: new L.Point(-1, -41) }).openPopup();
</code></pre>

<p>Question is: How can I assign an marker ID to trigger css change in the corresponding element within my html page?</p>

<p>My knowledge of JS is very limited, but may be there's a nice and easy solution out there, thx </p>
 

Latest posts

Top