Skip to content

Instantly share code, notes, and snippets.

@PerryRylance
Created March 28, 2019 12:59
Show Gist options
  • Save PerryRylance/c6899e02e1fe5ecd58f115ee7510b7f9 to your computer and use it in GitHub Desktop.
Save PerryRylance/c6899e02e1fe5ecd58f115ee7510b7f9 to your computer and use it in GitHub Desktop.
Polyline toggle checkboxes for WP Google Maps
jQuery(function($) {
$(window).on("load", function(event) {
var $ = jQuery;
var map_id = 2;
function bindClickListener(checkbox)
{
$(checkbox).on("change input", function() {
var polyline_id = $(checkbox).attr("data-polyline-id");
var checked = $(checkbox).prop("checked");
console.log(polyline_id, checked);
WPGM_Path[polyline_id].setVisible(checked);
});
}
var container = $("<div class='wpgmza-custom-checkbox-container'/>");
$("#wpgmza_filter_" + map_id).before(container);
for(var polyline_id in WPGM_Path)
{
console.log("polyline_id", polyline_id);
var label = $("<label/>");
var checkbox = $("<input type='checkbox'/>");
var data = wpgmaps_localize_polyline_settings[map_id][polyline_id];
bindClickListener(checkbox);
$(checkbox).prop("checked", true);
$(checkbox).attr("data-polyline-id", polyline_id);
$(label).append(checkbox);
$(label).append(" " + data.polyname);
$(container).append(label);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment