Last active
December 23, 2015 13:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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