Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/dealers/ |
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/dealers/map.json.php |
<? require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"); CModule::IncludeModule('iblock'); $COUNTRIES_ID = 8; $CITIES_ID = 5; $DEALERS_ID = 22; $EQUIPMENT_ID = 27; // если выбрана страна if(!empty($_REQUEST["country"])) { $res = CIBlockElement::GetList( false, array('IBLOCK_ID' => $COUNTRIES_ID, 'ID' => intval($_REQUEST["country"]), 'ACTIVE' => 'Y'), false, false, array('ID', 'NAME', 'PROPERTY_ZOOM') ); while ($country = $res->Fetch()) { $coords = array(); $zoom = 6; if($country["ID"] == 1172) // rus $zoom = 3; $xml = simplexml_load_file('http://geocode-maps.yandex.ru/1.x/?geocode='.$country["NAME"].'&results=1'); $found = $xml->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found; if ($found > 0) { $coords = explode(' ', $xml->GeoObjectCollection->featureMember->GeoObject->Point->pos); } else { $coords[1] = "63.70371572180206"; $coords[0] = "94.25138813484573"; $zoom = 3; } $json['coords'] = array(array($coords[1], $coords[0])); $json['zoom'] = $zoom; } // и не выбран город if(empty($_REQUEST["city"])) { // Получим все города этой страны $allCities = array(); $res = CIBlockElement::GetList( false, array('IBLOCK_ID' => $CITIES_ID, 'ACTIVE' => 'Y', 'PROPERTY_COUNTRY' => intval($_REQUEST["country"])), false, false, array('ID') ); while ($ob = $res->Fetch()) $allCities[] = $ob["ID"]; // затем выберем все магазины из этих городов, где есть координаты и адреса $res = CIBlockElement::GetList( false, array('IBLOCK_ID' => $DEALERS_ID, 'ACTIVE' => 'Y', '!PROPERTY_ADDRESS' => false, '!PROPERTY_COORDS' => false, 'PROPERTY_CITY' => $allCities), false, // Array("nPageSize"=>2), false, array('ID', 'NAME', 'IBLOCK_ID') ); $countShops = $res->SelectedRowsCount(); if($countShops > 0) { $json['baloons'] = array('type' => 'FeatureCollection'); // получим название Категорий товаров $arCategoryIdName = array(); $resCategory = CIBlockElement::GetList( false, array('IBLOCK_ID' => $EQUIPMENT_ID, 'ACTIVE' => 'Y'), false, false, array('ID', 'NAME', 'IBLOCK_ID') ); while ($obCategory = $resCategory->Fetch()) $arCategoryIdName[$obCategory["ID"]] = $obCategory["NAME"]; while ($ob = $res->GetNextElement()) { $coords = array(); // тут много множественных свойств, поэтому так $arShopFields = $ob->GetFields(); $arShopProps = $ob->GetProperties(); $coords = explode(',', $arShopProps['COORDS']['VALUE']); // уберем из именли лишние теги $arShopFields['NAME'] = str_replace('<br>', "\r\n", $arShopFields['NAME']); // пишем в балун инфу $bodyBaloon = '<p style="font-size:14px;">'.$arShopProps['ADDRESS']['VALUE']."</p><br>"; if(!empty($arShopProps['EQUIPMENT']['VALUE'])) { $bodyBaloon .= '<p><b>Оборудование</b></p>'; // подходящие Товарные категории foreach($arShopProps['EQUIPMENT']['VALUE'] as $equipment) { $bodyBaloon .= $arCategoryIdName[$equipment]."<br>"; } } if(!empty($arShopProps['SITE']['VALUE'])) { $bodyBaloon .= "<br>"; foreach($arShopProps['SITE']['VALUE'] as $site) { $bodyBaloon .= '<p><a href="http://'.$site.'" target="_blank">'.$site.'</a></p>'; } } if(!empty($arShopProps['PHONE']['VALUE'])) { $bodyBaloon .= "<br>"; foreach($arShopProps['PHONE']['VALUE'] as $phone) { $bodyBaloon .= '<p>тел: '.$phone.'</p>'; } } $json['baloons']['features'][] = array( 'type' => 'Feature', 'geometry' => array( 'type' => 'Point', 'coordinates' => array($coords[0], $coords[1]) ), 'properties' => array( 'balloonContentHeader' => $arShopFields['NAME'], 'balloonContentBody' => "<p>".$bodyBaloon."</p>", //'balloonContentFooter' => $balloonFooter, ), 'options' => array( 'iconColor' => '#44a326', 'strokeWidth' => '2', 'opacity' => '0.2', ) ); } } } } // если выбран город if(!empty($_REQUEST["city"])) { $x_city_sum = 0; $y_city_sum = 0; $zoom = 10; $arFilter = array('IBLOCK_ID' => $DEALERS_ID, 'ACTIVE' => 'Y', '!PROPERTY_COORDS' => false, 'PROPERTY_CITY' => intval($_REQUEST["city"])); // если выбрана категория if(!empty($_REQUEST["category"])) $arFilter['PROPERTY_EQUIPMENT'] = $_REQUEST["category"]; $resShops = CIBlockElement::GetList( false, $arFilter, false, false, array('ID', 'NAME', 'IBLOCK_ID', 'PROPERTY_COORDS') ); $countRes = $resShops->SelectedRowsCount(); if($countRes > 0) { $arCategoryIdName = array(); $resCategory = CIBlockElement::GetList( false, array('IBLOCK_ID' => $EQUIPMENT_ID, 'ACTIVE' => 'Y'), false, false, array('ID', 'NAME', 'IBLOCK_ID') ); while ($obCategory = $resCategory->Fetch()) $arCategoryIdName[$obCategory["ID"]] = $obCategory["NAME"]; $json['baloons'] = array('type' => 'FeatureCollection'); while ($obShops = $resShops->GetNextElement()) { $coords = array(); // тут много множественных свойств, поэтому так $arShopFields = $obShops->GetFields(); $arShopProps = $obShops->GetProperties(); // получим координаты $coords = explode(',', $arShopProps['COORDS']['VALUE']); // уберем из именли лишние теги $arShopFields['NAME'] = str_replace('<br>', "\r\n", $arShopFields['NAME']); // пишем в балун инфу $bodyBaloon = '<p style="font-size:14px;">'.$arShopProps['ADDRESS']['VALUE']."</p><br>"; if(!empty($arShopProps['EQUIPMENT']['VALUE'])) { $bodyBaloon .= '<p><b>Оборудование</b></p>'; // подходящие Товарные категории foreach($arShopProps['EQUIPMENT']['VALUE'] as $equipment) { $bodyBaloon .= $arCategoryIdName[$equipment]."<br>"; } } if(!empty($arShopProps['SITE']['VALUE'])) { $bodyBaloon .= "<br>"; foreach($arShopProps['SITE']['VALUE'] as $site) { $bodyBaloon .= '<p><a href="http://'.$site.'" target="_blank">'.$site.'</a></p>'; } } if(!empty($arShopProps['PHONE']['VALUE'])) { $bodyBaloon .= "<br>"; foreach($arShopProps['PHONE']['VALUE'] as $phone) { $bodyBaloon .= '<p>тел: '.$phone.'</p>'; } } $json['baloons']['features'][] = array( 'type' => 'Feature', 'geometry' => array( 'type' => 'Point', 'coordinates' => array($coords[0], $coords[1]) ), 'properties' => array( 'balloonContentHeader' => $arShopFields['NAME'], 'balloonContentBody' => $bodyBaloon, //'balloonContentFooter' => $balloonFooter, ), 'options' => array( 'iconColor' => '#44a326', 'strokeWidth' => '2', 'opacity' => '0.2', ) ); $x_city_sum += $coords[0]; $y_city_sum += $coords[1]; } $x_centr = $x_city_sum / $countRes; $y_centr = $y_city_sum / $countRes; $json['coords'] = array(array($x_centr, $y_centr)); $json['zoom'] = $zoom; } } echo json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);