0

На карте 3000 объектов, выгружаются из JSON. Весь функционал построен с помощью ObjectManager. Несколько кастомных кнопок с чекбоксами и фильтрацией по виду объекта с помощью setFilter().

function mapFilter () {
var item = $( "input[type="checkbox"]" );
obj = {};
item.each(function( index ) {
    obj[$( this ).val()] = $( this ).prop('checked');
});
    objectManager.setFilter(getFilterFunction(obj));
};

function getFilterFunction(categories){
    return function(obj){
      var content = obj.properties.typeObgect;
      return categories[content];
    }
};
$('input[type="checkbox"]').click(mapFilter);

Необходимо добавить фильтрацию по цене "от до" (значения берутся из инпутов), с сохранением результата предыдущего фильтра. Конструкция типа:

objectManager.setFilter('properties.cost >= "10000" && properties.cost <= "20000"');

работает, а как объединить результаты двух фильтров не знаю. Подскажите куда копать. Фрагмент JSON:

"properties": {
            "code": "160058",
            "cost": "8500",
            "typeObgect": "home",
            "balloonContentBody": ""
        },

1 ответ 1

0

Мое решение:

function mapFilter () {
  var item = $( "input[type="checkbox"]" );
  obj = {};
  item.each(function( index ) {
    obj[$( this ).val()] = $( this ).prop('checked');
  });
objectManager.setFilter(getFilterFunction(obj));
};
function getFilterFunction(categories){
var costMin = $("#input_cost_min").val(),
    costMax = $("#input_cost_max").val();
  return function(obj){
    if (obj.properties.cost >= costMin && obj.properties.cost <= costMax) {
        var content = obj.properties.balloonContent;
        return categories[content];
    };
  };
};


$('input[type="checkbox"]').click(mapFilter);
$('input[type="button"]').click(mapFilter);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.