Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add popupTemplate-option to marker_options #129

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ new L.GPX(app.params.gpx_url, {
}).addTo(map);
```

The content of the popup created for waypoints can be customised by setting `marker_options.popupTemplate` to a function returning the popup content, receiving name and description of the waypoint as arguments. The (simplified) default looks like
tudacs marked this conversation as resolved.
Show resolved Hide resolved

```javascript
marker_options.popupTemplate = function(name, desc) { return `<b>${name}</b> $desc` };
```

## Custom markers

You can also use your own icons/markers if you want to use custom
Expand Down
5 changes: 3 additions & 2 deletions gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ var _DEFAULT_MARKER_OPTS = {
shadowSize: [50, 50],
iconAnchor: [16, 45],
shadowAnchor: [16, 47],
clickable: false
clickable: false,
popupTemplate: function(name, desc) { return `<b>${name}</b>${desc.length > 0 ? '<br>' : ''} ${desc}` }
};
var _DEFAULT_POLYLINE_OPTS = {
color: 'blue'
Expand Down Expand Up @@ -443,7 +444,7 @@ L.GPX = L.FeatureGroup.extend({
icon: symIcon,
type: 'waypoint'
});
marker.bindPopup("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')).openPopup();
marker.bindPopup(options.marker_options.popupTemplate(name, desc)).openPopup();
this.fire('addpoint', { point: marker, point_type: 'waypoint', element: el[i] });
layers.push(marker);
}
Expand Down