I need to make a tag filter on the map using the Yandex map API. The question is that you need to display data from the database and then use filters to display or hide tags on the map. I brought the tags to the map and added filters, but I don’t understand how to make the tags hide, I ask for help or hints on how to do this. Here is the code for how it works now:

<script> ymaps.ready(function () { var myMap = new ymaps.Map('map', { center: [59.9386300, 30.3141300], zoom: 9, controls: [] }); var arrList = $('#prof_ul li').map(function(){ return $(this).attr('id'); }).get(); var arrList2 = $('#obr_ul li').map(function(){ return $(this).attr('id'); }).get(); var arrList3 = $('#napravlenie_ul li').map(function(){ return $(this).attr('id'); }).get(); // Π‘ΠΎΠ·Π΄Π°Π΄ΠΈΠΌ 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ² Π²Ρ‹ΠΏΠ°Π΄Π°ΡŽΡ‰Π΅Π³ΠΎ списка. var listBoxItems = arrList .map(function(title) { return new ymaps.control.ListBoxItem({ data: { content: title }, state: { selected: true } }) }), // Π’Π΅ΠΏΠ΅Ρ€ΡŒ создадим список, содСрТащий 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ². listBoxControl = new ymaps.control.ListBox({ data: { content: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ профСссиям', title: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ профСссиям' }, items: listBoxItems, state: { // ΠŸΡ€ΠΈΠ·Π½Π°ΠΊ, Ρ€Π°Π·Π²Π΅Ρ€Π½ΡƒΡ‚ Π»ΠΈ список. expanded: true, filters: listBoxItems.reduce(function(filters, filter) { filters[filter.data.get('content')] = filter.isSelected(); return filters; }, {}) } }); myMap.controls.add(listBoxControl); // Π‘ΠΎΠ·Π΄Π°Π΄ΠΈΠΌ 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ² Π²Ρ‹ΠΏΠ°Π΄Π°ΡŽΡ‰Π΅Π³ΠΎ списка. var listBoxItems2 = arrList2 .map(function(title) { return new ymaps.control.ListBoxItem({ data: { content: title }, state: { selected: true } }) }), // Π’Π΅ΠΏΠ΅Ρ€ΡŒ создадим список, содСрТащий 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ². listBoxControl2 = new ymaps.control.ListBox({ data: { content: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠΌΡƒ ΡƒΡ‡Π΅Ρ€Π΅ΠΆΠ΄Π΅Π½ΠΈΡŽ', title: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠΌΡƒ ΡƒΡ‡Π΅Ρ€Π΅ΠΆΠ΄Π΅Π½ΠΈΡŽ' }, items: listBoxItems2, state: { // ΠŸΡ€ΠΈΠ·Π½Π°ΠΊ, Ρ€Π°Π·Π²Π΅Ρ€Π½ΡƒΡ‚ Π»ΠΈ список. expanded: true, filters: listBoxItems2.reduce(function(filters, filter) { filters[filter.data.get('content')] = filter.isSelected(); return filters; }, {}) } }); myMap.controls.add(listBoxControl2); // Π‘ΠΎΠ·Π΄Π°Π΄ΠΈΠΌ 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ² Π²Ρ‹ΠΏΠ°Π΄Π°ΡŽΡ‰Π΅Π³ΠΎ списка. var listBoxItems3 = arrList3 .map(function(title) { return new ymaps.control.ListBoxItem({ data: { content: title }, state: { selected: true } }) }), // Π’Π΅ΠΏΠ΅Ρ€ΡŒ создадим список, содСрТащий 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ². listBoxControl3 = new ymaps.control.ListBox({ data: { content: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΡŽ', title: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΡŽ' }, items: listBoxItems3, state: { // ΠŸΡ€ΠΈΠ·Π½Π°ΠΊ, Ρ€Π°Π·Π²Π΅Ρ€Π½ΡƒΡ‚ Π»ΠΈ список. expanded: true, filters: listBoxItems3.reduce(function(filters, filter) { filters[filter.data.get('content')] = filter.isSelected(); return filters; }, {}) } }); myMap.controls.add(listBoxControl3); // Π”ΠΎΠ±Π°Π²ΠΈΠΌ отслСТиваниС измСнСния ΠΏΡ€ΠΈΠ·Π½Π°ΠΊΠ°, Π²Ρ‹Π±Ρ€Π°Π½ Π»ΠΈ ΠΏΡƒΠ½ΠΊΡ‚ списка ΠΏΠΎΠ΄ Π½ΠΎΠΌΠ΅Ρ€ΠΎΠΌ #3 . listBoxControl3.events.add(['select', 'deselect'], function(e) { var listBoxItem3 = e.get('target'); var filters = ymaps.util.extend({}, listBoxControl3.state.get('filters')); filters[listBoxItem3.data.get('content')] = listBoxItem3.isSelected(); listBoxControl3.state.set('filters', filters); }); var filterMonitor = new ymaps.Monitor(listBoxControl3.state); filterMonitor.add('filters', function(filters) { // ΠŸΡ€ΠΈΠΌΠ΅Π½ΠΈΠΌ Ρ„ΠΈΠ»ΡŒΡ‚Ρ€. objectManager.setFilter(getFilterFunction(filters)); }); function getFilterFunction(categories){ return function(obj){ var content = obj.properties.balloonContent; return categories[content] } } $.ajax({ url: "data.json" }).done(function (data) { objectManager.add(data); }); <?php foreach ($maps as $maps) { print ' // БобствСнноС ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ для ΠΌΠ΅Ρ‚ΠΊΠΈ с ΠΊΠΎΠ½Ρ‚Π΅Π½Ρ‚ΠΎΠΌ var placemark'.$maps['id'].' = new ymaps.Placemark('.$maps['cardination'].', { hintContent: "Π£Π»ΠΈΡ†Π°: '.$maps['street'].' <br> ΠžΡ€Π³Π°Π½ΠΈΠ·Π°Ρ†ΠΈΡ : '.$maps['name'].' <br> ΠšΠ°Ρ‚Π΅Π³ΠΎΡ€ΠΈΡ: '.$maps['category'].'", "balloonContent": "'.$maps['prof'].'", "clusterCaption": "'.$maps['zavedenie'].'", "iconCaption": "'.$maps['naprav'].'", }, { // ΠžΠΏΡ†ΠΈΠΈ. // НСобходимо ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ Π΄Π°Π½Π½Ρ‹ΠΉ Ρ‚ΠΈΠΏ ΠΌΠ°ΠΊΠ΅Ρ‚Π°. iconLayout: "default#image", // Π‘Π²ΠΎΡ‘ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΌΠ΅Ρ‚ΠΊΠΈ. iconImageHref: "'.$maps['image'].'", // Π Π°Π·ΠΌΠ΅Ρ€Ρ‹ ΠΌΠ΅Ρ‚ΠΊΠΈ. iconImageSize: [32, 32], // Π‘ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅ Π»Π΅Π²ΠΎΠ³ΠΎ Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ ΡƒΠ³Π»Π° ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ // Π΅Ρ‘ "Π½ΠΎΠΆΠΊΠΈ" (Ρ‚ΠΎΡ‡ΠΊΠΈ привязки). iconImageOffset: [-16, -16], }); myMap.geoObjects.add(placemark'.$maps['id'].'); '; } ?> }); </script> 

The code is taken and adapted from the official page of api yandex, as I understand it, you need to get the json file in this line

 $.ajax({ url: "data.php" }).done(function (data) { objectManager.add(data); }); 

but how do I do this by associating with the base?

The json file format should look like this:

 {"type": "Feature", "id": 0, "geometry": {"type": "Point", "coordinates": [55.831903, 37.411961]}, "properties": {"balloonContent": "АптСка", "clusterCaption": "АптСка", "hintContent": "АптСка", "iconCaption": "АптСка"}, "options": {"preset": "islands#blueCircleDotIconWithCaption"}})] 

    1 answer 1

    Solved the question, now I get the value but I can not hide the labels that are needed if anyone knows tell me.

     ymaps.ready(function () { var myMap = new ymaps.Map('map', { center: [59.9386300, 30.3141300], zoom: 9, controls: [] }); <?php foreach ($maps as $maps) { if($maps['prof'] == 1) { print ' // БобствСнноС ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ для ΠΌΠ΅Ρ‚ΠΊΠΈ с ΠΊΠΎΠ½Ρ‚Π΅Π½Ρ‚ΠΎΠΌ var placemark'.$maps['id'].' = new ymaps.Placemark('.$maps['cardination'].', { hintContent: "Π£Π»ΠΈΡ†Π°: '.$maps['street'].' <br> ΠžΡ€Π³Π°Π½ΠΈΠ·Π°Ρ†ΠΈΡ : '.$maps['name'].' <br> ΠšΠ°Ρ‚Π΅Π³ΠΎΡ€ΠΈΡ: '.$maps['category'].'", "balloonContent": "'.$maps['prof'].'", "clusterCaption": "'.$maps['zavedenie'].'", "iconCaption": "'.$maps['naprav'].'", }, { // ΠžΠΏΡ†ΠΈΠΈ. // НСобходимо ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ Π΄Π°Π½Π½Ρ‹ΠΉ Ρ‚ΠΈΠΏ ΠΌΠ°ΠΊΠ΅Ρ‚Π°. iconLayout: "default#image", // Π‘Π²ΠΎΡ‘ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΌΠ΅Ρ‚ΠΊΠΈ. iconImageHref: "'.$maps['image'].'", // Π Π°Π·ΠΌΠ΅Ρ€Ρ‹ ΠΌΠ΅Ρ‚ΠΊΠΈ. iconImageSize: [32, 32], // Π‘ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅ Π»Π΅Π²ΠΎΠ³ΠΎ Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ ΡƒΠ³Π»Π° ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ // Π΅Ρ‘ "Π½ΠΎΠΆΠΊΠΈ" (Ρ‚ΠΎΡ‡ΠΊΠΈ привязки). iconImageOffset: [-16, -16], }); myMap.geoObjects.add(placemark'.$maps['id'].'); '; } } ?> var arrList = $('#prof_ul li').map(function(){ return $(this).attr('id'); }).get(); var arrList2 = $('#obr_ul li').map(function(){ return $(this).attr('id'); }).get(); var arrList3 = $('#napravlenie_ul li').map(function(){ return $(this).attr('id'); }).get(); // Π‘ΠΎΠ·Π΄Π°Π΄ΠΈΠΌ 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ² Π²Ρ‹ΠΏΠ°Π΄Π°ΡŽΡ‰Π΅Π³ΠΎ списка. var listBoxItems = arrList .map(function(title) { return new ymaps.control.ListBoxItem({ data: { content: title }, state: { selected: true } }) }), // Π’Π΅ΠΏΠ΅Ρ€ΡŒ создадим список, содСрТащий 5 ΠΏΡƒΠ½ΠΊΡ‚ΠΎΠ². listBoxControl = new ymaps.control.ListBox({ data: { content: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ профСссиям', title: 'Π€ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΠΎ профСссиям' }, items: listBoxItems, state: { // ΠŸΡ€ΠΈΠ·Π½Π°ΠΊ, Ρ€Π°Π·Π²Π΅Ρ€Π½ΡƒΡ‚ Π»ΠΈ список. expanded: true, filters: listBoxItems.reduce(function(filters, filter) { filters[filter.data.get('content')] = filter.isSelected(); return filters; }, {}) } }); myMap.controls.add(listBoxControl); listBoxControl.events.add(['select', 'deselect'], function (e) { var selectedFilters = listBoxControl.filter(function (it) { return it.isSelected(); }); applyFilters(selectedFilters); }); function applyFilters(filters,myMap,geoObjects) { filters.forEach(function (filter,myMap,geoObjects) { <?php foreach ($prof_main as $prof_main) { print ' if(filter.data.get("content") == '.$prof_main['name'].') { console.log("'.$prof_main['name'].'"); for (var i = 0; i< geoObjects.length; i++) { console.log(i); geoObject.options.set("visible", false); } } '; } ?> }) } }); </script>