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"}})]