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

Option to disable zone name popup for clicked zone & ability to read the clicked zone's name programatically #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Ladis82
Copy link
Contributor

@Ladis82 Ladis82 commented Jul 9, 2021

The original behaviour always shows a bubble with a clicked zone's name. To be able to integrate this library into more complex projects, people may want to disable showing this bubble. The new optional parameter allows that. Default is the original behaviour.

@Ladis82
Copy link
Contributor Author

Ladis82 commented Jul 9, 2021

Example to disable the zone name popup:
var track = new L.KML(kml, { disablePlacePopup: true });

Is there some documentation where I should add this? (I see people can just read pull requests' comments 😏)

@Ladis82
Copy link
Contributor Author

Ladis82 commented Jul 9, 2021

Added zone name in the KML layer's data to be able to read the clicked zone's name programatically. The previous commit allows to disable the bubble with the clicked zone's name, this commit allows to read the clicked zone's name in the code of projects using this library.

Example (adding the KML layers into a feature group, instead of directly into the map, allows to catch events, e.g. click):

var featureGroup = L.featureGroup().addTo(map).on("click", function (event) {
    alert('lat=' + event.latlng.lat + ', lng=' + event.latlng.lng + '\nzone name=' + event.layer.options.zoneName);  // renamed "name" to "zoneName", see a later comment
});

$.ajax({ url: 'https://server/file.kml' })
    .done(function(kml) {
        var track = new L.KML(kml, { disablePlacePopup: true });    // disable the automatic popup bubble with the zone's name
        featureGroup.addLayer(track);                               // add it into the feature group catching the click event, instead of directly into the map
    });

@Ladis82
Copy link
Contributor Author

Ladis82 commented Jul 10, 2021

Real life example (not finished, thus waits for the first click on color zones):
Snow load zones of Germany according to Eurocode

@Ladis82
Copy link
Contributor Author

Ladis82 commented Jul 10, 2021

Hm, looking at PR 16, I renamed the field differently than just "name". So now it's my "zoneName" for the zone inside the KML layer and doesn't affect the layer's "name" from PR 16.

@Ladis82 Ladis82 changed the title Added parameter to disable the popup with a zone name for a clicked zone Option to disable zone name popup for clicked zone & ability to read the clicked zone's name programatically Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant