<?
$mass2 = array("type" =>"Feature","id" => "",
"geometry" => array("type" => "Polygon","coordinates" => 1), //сюда надо вставаить координаты
"properties" => array(
"description" => "",
"fill" => "#ff931e",
"fill-opacity"=>0.3,
"stroke"=>"#e6761b",
"stroke-width"=>"2",
"stroke-opacity"=>0.9
),
);
$mass3 = array(
'type' => "FeatureCollection",
'features'=> "",
);
$featuresMass=[];
\Bitrix\Main\Loader::includeModule('iblock');
$arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM",);
$arFilter = Array("IBLOCK_ID"=>11, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y");
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>10), $arSelect);
//$mass=[];
$map = 0;
$map2 = 0;
$map3 = 0;
while($ob = $res->GetNextElement()){
$arFields = $ob->GetFields();
$arProps = $ob->GetProperties();
$str = $arProps['COORDINATES']['VALUE']; //координаты
$array = array(
'coordinates' => json_decode($str)
);
$json_ne = json_encode($array, true);
//echo $json_ne;
$mass2['id']=$arFields["ID"];
$mass2['properties']['description']=$arFields["NAME"];
$mass2['geometry']['coordinates']=$json_ne;
echo '<pre>';
//print_r($mass2);
//print_r($arProps);
echo '</pre>';
array_push($featuresMass,$mass2);
}
$data_for_write ='';
$mass3['features'] = $featuresMass;
$json = json_encode($mass3);
?>
[[[[-3546.84,2290.81],[-2390.84,2290.81],[-2394.84,1790.81],[-3542.84,1790.81],[-3546.84,2290.81]]]]
<?php
$str = "[[[-3546.84, 2290.81], [-2390.84, 2290.81], [-2394.84, 1790.81], [-3542.84, 1790.81], [-3546.84, 2290.81]]]";
$array = array(
'coordinates' => $str
);
$json = json_encode($array, true);
echo $json;
$array_de = json_decode($json);
echo $array_de;
?>
{"coordinates":"[[[-354684, 229081], [-239084, 229081], [-239484, 179081], [-354284, 179081], [-354684, 229081]]]"}<br />
<b>Fatal error</b>: Uncaught Error: Object of class stdClass could not be converted to string in [...][...]:11
Stack trace:
#0 {main}
thrown in <b>[...][...]</b> on line <b>11</b><br />
$generate_xml = $_GET['generate_xml']; //просто для проверки
$json_object = $_GET['json_object'];
if($_GET['generate_xml']) {
$dir = $_SERVER['DOCUMENT_ROOT'].'/scheme/geoObjects2.geojson';
$write = file_put_contents( $dir , $json_object );
if($write) { $info = "Запись прошла";} else {$info = "Запись не прошла";}
echo $info;
}
$json = json_encode($mass);
echo $json; //["404","401"]
<input type="button" value="Обновить данные карты" id="generate">
<input type="hidden" value="1" id="generate_xml" name="generate_xml">
<div id="json_object"><?echo $json;?></div>
$("#generate").on("click", function () {
var generate_xml= $("#generate_xml").val();
var json_object = $("#json_object").text();
$.ajax({
url: '/scheme/generate.php',
method: 'get',
dataType: 'json',
data: {generate_xml: generate_xml, json_object: json_object},
success: function(textStatus, data){
if (textStatus == 'success') {
alert('Карта обновлена. Перезагрузите страницу!');
}
if (textStatus == 'error') {
alert('Ошибка.');
}
alert(data);
},
error: function() {
console.log('error', arguments);
}
});
});