Skip to content

Instantly share code, notes, and snippets.

@miguelpeixe
Last active December 23, 2015 13:39
Show Gist options
  • Save miguelpeixe/6643853 to your computer and use it in GitHub Desktop.
Save miguelpeixe/6643853 to your computer and use it in GitHub Desktop.
JEO - Manipulação de marcador no evento de filtro do range slider. Exemplo com contagem de metadado nas propriedades do GeoJSON
<?php
// Javascript utilizado para realizar a contagem total
function jeo_child_scripts() {
wp_enqueue_script('test-range', get_stylesheet_directory_uri() . '/js/test-range.js', array('jquery', 'jeo.markers'));
}
add_action('jeo_markers_enqueue_scripts', 'jeo_child_scripts');
/* Inserção do dado que queremos na lista de propriedades GeoJSON
* No caso a função pega o metadado "valor_numero" e insere no GeoJSON como "custom_value"
*
* Lembrar de limpar o cache GeoJSON ao inserir essa função no seu functions.php
*/
function jeo_child_marker_data($data) {
global $post;
$data['custom_value'] = get_post_meta($post->ID, 'valor_numero', true);
return $data;
}
add_filter('jeo_marker_data', 'jeo_child_marker_data');
(function($) {
var total = 0;
// Executa função enquanto o range slider filtra;
jeo.rangeSliderFiltered(function(markers, map) {
total = 0;
// Incrementa total a partir da propriedade "custom value" dos markers filtrados
$.each(markers, function(i, m) {
total = total + parseInt(m.toGeoJSON().properties.custom_value);
});
// Imprime no log o valor total
console.log(total);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment