3

I'm breaking down my question into three parts. I am a beginner to Leaflet and to writing code. Currently, I have a JSON file with all of my markers linked to my map page. The idea is that every marker will have a different image so when the user clicks on the marker the thumbnail for the image will appear in the map, which will link to an image in the website.

Here is an example of a marker in the JSON file:

var mapshs4 = {
    "type": "FeatureCollection",

    "features": [

    { "type": "Feature", "id": 0, "properties": { "idcode": "A", "popupContent": "Here!" + '< img src="thumbnail">' }, "geometry": { "type": "Point", "coordinates": [ -89.2, 22.4 ] } }
  1. Is there a way to resize the popup box to the image in the popup of a marker.

  2. At the same time, I would like the click event to connect to a larger sized image embedded within the site. My guess is that I would have to attach an ID to each image and to each marker to link them together.

  3. Conversely, how do you make it so that when the user clicks on the image embedded in the site, it will go to that marker on the map? (For an example that uses a label: http://www.theglobeandmail.com/life/home-and-garden/real-estate/exclusive-how-much-are-homes-in-your-toronto-neighbourhood/article4520994/)

Any help would be much appreciated.

1

In regards to the third question:

Each table row in the above example has a "data-polyindex" attribute, the attribute value is the layer._leaflet_id property, which is a unique id to each layer.
The external elements/images should have this attribute in order to relate to a specific layer.
You should add the attributes to the external elements after the featureGroup is created, in order to get the current unique id's.
Then you can create an event listener on elements that has this attribute, parse the data-polyindex attribute and use something like :
featureGroup.getLayer(data-polyindex).fireEvent('click');
to open the popup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.