Старт

This commit is contained in:
2023-11-07 19:51:49 +06:00
commit 86542a157f
5002 changed files with 199551 additions and 0 deletions

View File

@ -0,0 +1,856 @@
class TRoutes
{
constructor(map)
{
this.routes = []; //Список маршрутов
}
//Получаем список объектов
//Фильтруем объекты для заполнения в таблицу
filtering()
{
showProgressBar(document.getElementById('div_tbl_e'));
var data = {
name: "",
type: ""
};
$.ajax({
url: '/monitoring/pscripts/routes.php',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
type: "POST",
dataType: "json",
success: function(thiz){return function(data,status){
if(status=='success')
{
thiz.routes = []; //Удаляю старые объекты
g_vectorSourceRoute.clear(); //Удаляю все отображения
for(i=0;i<data.length;i++)
{
var obj = new TRoute();
obj.id=data[i].id;
obj.name=data[i].name;
obj.station=data[i].station;
obj.carriers=data[i].carriers;
obj.count=data[i].count;
obj.length=data[i].length;
obj.lon=parseFloat(data[i].lon);
obj.lat=parseFloat(data[i].lat);
obj.schedules=data[i].schedules;
obj.checkpoints = [];
for(var j=0;j<data[i].checkpoints.length;j++)
{
var chp = new TCheckPoint();
Object.assign(chp,data[i].checkpoints[j]); //Копирую все свойства в новый объект
obj.checkpoints.push(chp);
}
thiz.routes.push(obj);
}
thiz.fillRezDiv();
}else
{
alert(status);
}
hideProgressBar(document.getElementById('div_tbl_e'));
}}(this)
});
}
//Заполнить результатом выборки DIV в виде таблицы
fillRezDiv()
{
var div=document.getElementById("div_tbl_e");
delChild(div);
div.innerHTML='<table id="thetable_e" border="0" style="width:100%;" class="SShow"><thead><tr style="background-color: rgb(218, 218, 218);"><th></th><th id="route_ch_M" style="width:1%;text-decoration:underline;cursor: pointer;">'+trt('View')+'.</th><th style="width: 90%;">'+trt('Route_name')+'</th><th style="width: 1%;">'+trt('Points')+'</th><th style="width: 1%;">'+trt('Length')+'</th></tr></thead><tbody></tbody></table>';
var theTable = document.getElementById('thetable_e');
for(i=0;i<this.routes.length;i++)
{
let tr = document.createElement('tr');
let bgColor='';
if (i%2==0) bgColor='var(--row-color-1)'; else bgColor='var(--row-color-2)';
tr.style.backgroundColor=bgColor;
tr.onmouseover=function(){this.style.backgroundColor='var(--btn-color2)';};
tr.onmouseout=function(val1,val2){return function(){val1.style.backgroundColor=val2;}}(tr,bgColor);
tr.id='cell_e_'+this.routes[i].id;
var td;
td = document.createElement('td');
td.style.cssText="width:24px;text-align:center;vertical-align:top;";
td.innerHTML='<img id="routes_down_btn_'+this.routes[i].id+'" src="/resources/images/right.png" alt="" style="cursor: pointer;">';
tr.appendChild(td);
td = document.createElement('td');
td.style.cssText="text-align: center;";
td.innerHTML='<input id="route_ch_'+this.routes[i].id+'" type="checkbox"/>';
tr.appendChild(td);
td = document.createElement('td');
td.style.cursor='pointer';
td.innerHTML=this.routes[i].name;
td.onclick=function(route){
return function(){
route.goToStart();
}
}(this.routes[i]);
tr.appendChild(td);
td = document.createElement('td');
td.style.cssText='cursor:pointer;text-align:right;';
td.innerHTML=this.routes[i].count;
td.onclick=function(route){
return function(){
route.goToStart();
}
}(this.routes[i]);
tr.appendChild(td);
td = document.createElement('td');
td.style.cssText='cursor:pointer;white-space:nowrap;text-align:right;';
td.innerHTML=this.routes[i].length+' '+trt('km');
td.onclick=function(route){
return function(){
route.goToStart();
}
}(this.routes[i]);
tr.appendChild(td);
/*td = document.createElement('td');
td.innerHTML=this.routes[i].value;
tr.appendChild(td);*/
/*td = document.createElement('td');
td.innerHTML=this.routes[i].date;
tr.appendChild(td);*/
theTable.tBodies[0].appendChild(tr);
//Формирую раскрывающийся список
tr = document.createElement('tr');
tr.id=this.routes[i].id;
tr.style.cssText="background-color:var(--back-color-3);display:none";
td = document.createElement('td');
td.colSpan=6;
var html='<table style="width:100%;"><tr><td style="width:100%;border: 0;">';
html+='<b>'+trt('Bus_station')+':</b> <img id="route_edit2_'+this.routes[i].id+'" src="/resources/images/edit16.png" alt="'+trt('Edit')+'" title="'+trt('Edit')+'" style="cursor:pointer;"> '+this.routes[i].station+'<br>';
html+='<b>'+trt('Carrier')+':</b> <img id="route_edit3_'+this.routes[i].id+'" src="/resources/images/edit16.png" alt="'+trt('Edit')+'" title="'+trt('Edit')+'" style="cursor:pointer;"> '+this.routes[i].carriers+'<br>';
html+='<b>'+trt('Schedule')+':</b> <img id="route_edit4_'+this.routes[i].id+'" src="/resources/images/edit16.png" alt="'+trt('Edit')+'" title="'+trt('Edit')+'" style="cursor:pointer;"><br>';
for(var j=0;j<this.routes[i].schedules.length;j++)
{
html+='<span style="padding-left:1em">'+this.routes[i].schedules[j].direction+': '+this.routes[i].schedules[j].time+' '+this.routes[i].schedules[j].carrier+'</span><br>';
}
html+='<b>Контрольные точки:</b> <img id="route_edit5_'+this.routes[i].id+'" src="/resources/images/rplus16.png" alt="'+trt('Create')+'" title="'+trt('Create')+'" style="cursor:pointer;"> <img id="route_edit6_'+this.routes[i].id+'" src="/resources/images/edit16.png" alt="'+trt('Edit')+'" title="'+trt('Edit')+'" style="cursor:pointer;"><br>';
for(var j=0;j<this.routes[i].checkpoints.length;j++)
{
html+='<span style="padding-left:1em"><input id="route_ch_c_'+this.routes[i].checkpoints[j].id+'" type="checkbox"/> <div id="route_ch_cd_'+this.routes[i].checkpoints[j].uid+'" style="display:inline;cursor:pointer;">'+this.routes[i].checkpoints[j].direction+': '+this.routes[i].checkpoints[j].time+' '+this.routes[i].checkpoints[j].name+'</div> <img id="route_edit_cp1_'+this.routes[i].checkpoints[j].id+'" src="/resources/images/edit16.png" alt="'+trt('Edit')+'" title="'+trt('Edit')+'" style="cursor:pointer;"> <img id="route_edit_cp2_'+this.routes[i].checkpoints[j].id+'" src="/resources/images/rdel16.png" alt="'+trt('Delete')+'" title="'+trt('Delete')+'" style="cursor:pointer;"></span><br>';
}
html+='</td><td valign="top" style="border: 0;"><img id="route_rev_'+this.routes[i].id+'" src="/resources/images/rev24.png" alt="'+trt('Swap')+' A B" title="'+trt('Swap')+' A B" style="cursor:pointer;"></td><td valign="top" style="border: 0;"><img id="route_edit_'+this.routes[i].id+'" src="/resources/images/edit24.png" alt="'+trt('Edit')+'" title="'+trt('Edit')+'" style="cursor:pointer;"></td><td valign="top" style="border: 0;"><img id="route_del_'+this.routes[i].id+'" src="/resources/images/del24.png" alt="'+trt('Delete')+'" title="'+trt('Delete')+'" style="cursor:pointer;"></td></tr></table>';
td.innerHTML=html;
tr.appendChild(td);
theTable.tBodies[0].appendChild(tr);
//При щелчке на ячейку перемещаем карту на точку
/*var cell=document.getElementById("cell_e_"+this.routes[i].id);
cell.onclick=function(object){
return function(){
object.getGeoJSON();
}
}(this.routes[i]);*/
var cell=document.getElementById("route_ch_"+this.routes[i].id);
cell.onclick=function(route){
return function(){
var chb=document.getElementById("route_ch_"+route.id);
route.setVisibility(chb.checked);
}
}(this.routes[i]);
//Кнопка разсрыть список
var btn=document.getElementById('routes_down_btn_'+this.routes[i].id);
btn.onclick=function(tr,thiz,id){ return function(){
var btn=document.getElementById('routes_down_btn_'+id);
if(btn.src.indexOf("right.png")!=-1)
{
btn.src = '/resources/images/down.png';
tr.style.display = 'table-row';
}else if(btn.src.indexOf("down.png")!=-1)
{
btn.src = '/resources/images/right.png';
tr.style.display = 'none';
}
};
}(tr,this,this.routes[i].id);
//Кнопка поменять местами начальную и конечную точку
btn=document.getElementById('route_rev_'+this.routes[i].id)
btn.onclick=function(thiz,id){ return function(){ thiz.swapPoints({id:id}); }; }(this,this.routes[i].id);
//Кнопка редактировать
btn=document.getElementById('route_edit_'+this.routes[i].id)
btn.onclick=function(thiz,id){ return function(){ thiz.editRoute({id:id}); }; }(this,this.routes[i].id);
//Кнопка удалить
btn=document.getElementById('route_del_'+this.routes[i].id)
btn.onclick=function(thiz,id){ return function(){ thiz.deleteRoute({id:id}); }; }(this,this.routes[i].id);
//Кнопка редактировать "Автовокзал", "Перевозчик"
var eBtn=function(thiz,id){ return function(){
var settings='<type n="RoutesCompanies"><objects-list><filter><column n="route_id"><![CDATA['+id+']]></column></filter></objects-list></type>';
myFunction('RoutesCompanies',settings);
}; }(this,this.routes[i].id);
btn=document.getElementById('route_edit2_'+this.routes[i].id)
btn.onclick=eBtn;
btn=document.getElementById('route_edit3_'+this.routes[i].id)
btn.onclick=eBtn;
//Кнопка редактировать расписание рейса
btn=document.getElementById('route_edit4_'+this.routes[i].id)
btn.onclick=function(thiz,id){ return function(){
var settings='<type n="TripsSchedules"><objects-list><filter><column n="route_id"><![CDATA['+id+']]></column></filter></objects-list></type>';
myFunction('TripsSchedules',settings);
}; }(this,this.routes[i].id);
//Кнопка создать контрольную точку
btn=document.getElementById('route_edit5_'+this.routes[i].id)
btn.onclick=function(thiz,id){ return function(){
thiz.createCheckPoint(id);
}; }(this,this.routes[i].id);
//Кнопка редактировать контрольные точки (табличка)
btn=document.getElementById('route_edit6_'+this.routes[i].id)
btn.onclick=function(thiz,id){ return function(){
var settings='<type n="RoutesCheckpoints"><objects-list><filter><column n="route_id"><![CDATA['+id+']]></column></filter></objects-list></type>';
myFunction('RoutesCheckpoints',settings);
}; }(this,this.routes[i].id);
//Кнопки редактировать контрольные точки
for(var j=0;j<this.routes[i].checkpoints.length;j++)
{
//Чекбукс видимости контрольной точки
var bnt=document.getElementById("route_ch_c_"+this.routes[i].checkpoints[j].id);
bnt.onclick=function(checkPoint){
return function(){
var chb=document.getElementById("route_ch_c_"+checkPoint.id);
checkPoint.setVisibility(chb.checked);
}
}(this.routes[i].checkpoints[j]);
//Центрировать на контрольной точке
btn=document.getElementById('route_ch_cd_'+this.routes[i].checkpoints[j].uid);
btn.onclick=function(checkpoint){ return function(){ checkpoint.goToCenter(); }; }(this.routes[i].checkpoints[j]);
//Кнопка редактировать
btn=document.getElementById('route_edit_cp1_'+this.routes[i].checkpoints[j].id);
btn.onclick=function(thiz,id){ return function(){ thiz.editCheckPoint({id:id}); }; }(this,this.routes[i].checkpoints[j].id);
//Кнопка удалить контрольную точку
btn=document.getElementById('route_edit_cp2_'+this.routes[i].checkpoints[j].id);
btn.onclick=function(thiz,id){ return function(){ thiz.deleteControlPoint({id:id}); }; }(this,this.routes[i].checkpoints[j].id);
}
}
//Количество элементов в дереве
var divCnt = document.getElementById("count_e");
delChild(divCnt);
divCnt.appendChild(document.createTextNode(this.routes.length));
//По нажатию на заголовок инвертируем чекбуксы
divCnt = document.getElementById("route_ch_M");
divCnt.onclick=function(thiz){
return function(){
thiz.hide();
}
}(this);
}
//Поменять местами начальную и конечную точки
swapPoints(settings)
{
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
if (confirm(trt("Do_you_really_want_to_swap_the_points")+'?')) {
}
}
createRoute()
{
//В настройках передаю центр карты
let center=ol.proj.transform(g_map.getView().getCenter(), 'EPSG:3857','EPSG:4326');
let eRec = new EdtRec("");
eRec.eRecNa("Routes",-1,'<type n="Routes"><properties><prop n="name"><![CDATA['+document.getElementById("cnumber_e").value+']]></prop><prop n="lat"><![CDATA['+center[1]+']]></prop><prop n="lon"><![CDATA['+center[0]+']]></prop></properties></type>');
eRec.win.onClose=function(thiz){ return function(){ thiz.filtering();};}(this);
}
createCheckPoint(id)
{
//В настройках передаю центр карты
let center=ol.proj.transform(g_map.getView().getCenter(), 'EPSG:3857','EPSG:4326');
let eRec = new EdtRec("");
eRec.eRecNa("RoutesCheckpoints",-1,'<type n="RoutesCheckpoints"><properties><prop n="route_id"><![CDATA['+id+']]></prop><prop n="name"><![CDATA['+document.getElementById("cnumber_e").value+']]></prop><prop n="lat"><![CDATA['+center[1]+']]></prop><prop n="lon"><![CDATA['+center[0]+']]></prop></properties></type>');
eRec.win.onClose=function(thiz){ return function(){ thiz.filtering();};}(this);
}
//Удалить маршрут
deleteRoute(settings)
{
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
if (confirm(trt("Do_you_really_want_to_delete_the_record")+'?')) {
var req=createRequestObject();
req.onreadystatechange = function(thiz)
{
return function(){
if(req.readyState === 4){
var data=null;
try {
data = JSON.parse(req.responseText);
} catch (e) {
alert(e.message);
return;
}
if(data!=null)
{
if(data.errorMessage !== undefined && data.errorMessage!='')
{
alert(data.errorMessage);
thiz.win.hideProgressBar();
}else
{
}
}
//Фильтрую список заново
thiz.filtering();
}
};
}(this);
req.open("POST", '/monitoring/pscripts/routes.php?fn=3', true);
req.setRequestHeader("Content-type", "text/plain");
req.send(JSON.stringify(settings));
this.filtering();
}
return true;
}
//Удалить маршрут
deleteControlPoint(settings)
{
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
if (confirm(trt("Do_you_really_want_to_delete_the_record")+'?')) {
alert(settings.id);
/*var req=createRequestObject();
req.onreadystatechange = function(thiz)
{
return function(){
if(req.readyState === 4){
var data=null;
try {
data = JSON.parse(req.responseText);
} catch (e) {
alert(e.message);
return;
}
if(data!=null)
{
if(data.errorMessage !== undefined && data.errorMessage!='')
{
alert(data.errorMessage);
thiz.win.hideProgressBar();
}else
{
}
}
//Фильтрую список заново
thiz.filtering();
}
};
}(this);
req.open("POST", '/monitoring/pscripts/routes.php?fn=3', true);
req.setRequestHeader("Content-type", "text/plain");
req.send(JSON.stringify(settings));
this.filtering();*/
}
return true;
}
editRoute(settings)
{
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
let route=this.getRouteByID(settings.id);
let eRec = new EdtRec("");
eRec.eRecNa("Routes",settings.id);
eRec.win.onClose=function(thiz,route){ return function(){
route.showPoints(false);
//thiz.filtering();
};}(this,route);
if(route!=null)
{
route.showPoints(true);
route.setVisibility(true);
}
}
editCheckPoint(settings)
{
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
let checkPoint=this.getCheckPointByID(settings.id);
let eRec = new EdtRec("");
eRec.eRecNa("RoutesCheckpoints",settings.id);
eRec.win.onClose=function(thiz,checkPoint){ return function(){
checkPoint.showPoints(false);
};}(this,checkPoint);
//alert("checkPoint = "+checkPoint+" id = "+settings.id);
if(checkPoint!=null)
{
checkPoint.showPoints(true);
checkPoint.setVisibility(true);
}
}
//Вернуть объект TRoute по идентификатору
getRouteByID(id)
{
for(var i=0;i<this.routes.length;i++)
{
if(this.routes[i].id==id)
return this.routes[i];
}
return null;
}
//Вернуть объект TCheckPoint по идентификатору
getCheckPointByID(id)
{
for(var i=0;i<this.routes.length;i++)
{
for(var j=0;j<this.routes[i].checkpoints.length;j++)
{
if(this.routes[i].checkpoints[j].id==id)
return this.routes[i].checkpoints[j];
}
}
return null;
}
//Инвертировать видимость маршрутов
hide()
{
for(var i=0;i<this.routes.length;i++)
{
this.routes[i].setVisibility(!this.routes[i].getVisibility());
}
}
}
class TRoute
{
constructor(){
this.uid=getUID(); //Уникальный идентификатор
this.id='';
this.feature=null; //Объект который отображается на карте
this.featureA=null; //Начало маршрута
this.featureB=null; //Конец маршрута
this.shP=false; //Показывать ли точки для редактирования
this.visible=false; //По умолчанию всё видим
}
getVisibility()
{
return this.visible;
}
setVisibility(val)
{
var chb=document.getElementById("route_ch_"+this.id);
if(val)
{
if(!chb.checked) chb.checked=true;
if(this.feature==null)
{
this.getGeoJSON(); //Подгружаем объект с сервера
}else
{
//Проверяю чтобы заново не добавить
var exists=false;
var features=g_vectorSourceRoute.getFeatures();
for(var i=0;i<features.length;i++)
{
if(features[i]==this.feature)
{
exists=true;
break;
}
}
if(!exists)
{
g_vectorSourceRoute.addFeature(this.feature);
g_vectorSourceRoute.addFeature(this.featureA); //Начало маршрута
g_vectorSourceRoute.addFeature(this.featureB); //Конец маршрута
}
}
}else{
if(chb!=null && chb.checked) chb.checked=false;
if(this.feature!=null)
{
g_vectorSourceRoute.removeFeature(this.feature);
this.showPoints(false);
}
if(this.featureA!=null) g_vectorSourceRoute.removeFeature(this.featureA); //Начало маршрута
if(this.featureB!=null) g_vectorSourceRoute.removeFeature(this.featureB); //Конец маршрута
}
this.visible=val;
//Также присваваю видимость для контрольных точек
for(var i=0;i<this.checkpoints.length;i++)
{
this.checkpoints[i].setVisibility(val);
}
}
goToStart()
{
if(this.feature!=null)
{
var coord = this.feature.getGeometry().getCoordinates();
if(coord.length>0)
{
var point = coord[0];
if(point!=null)
{
g_map.getView().setCenter(point);
if(g_map.getView().getZoom()<9)
g_map.getView().setZoom(9);
}
}
}else
{
if(!isNaN(parseFloat(this.lon)))
{
var point = ol.proj.transform([this.lon,this.lat], 'EPSG:4326','EPSG:3857');
if(point!=null)
{
g_map.getView().setCenter(point);
if(g_map.getView().getZoom()<9)
g_map.getView().setZoom(9);
}
}
}
}
//Отобразить точки для редактирования
showPoints(val)
{
this.shP=val;
if(this.shP)
enableEditPoints(this.feature);
else
disableEditPoints(this.feature);
return true;
}
//Запросить гео данные для построения маршрута на карте
getGeoJSON()
{
if(this.feature!=null) return;
var data = {
id: this.id
};
$.ajax({
url: '/monitoring/pscripts/routes.php?fn=1',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
type: "POST",
dataType: "json",
success: function(thiz){return function(data,status){
if(status=='success')
{
var dataC;
var featuresC;
var vectorSourceC;
dataC = data;//JSON.parse('{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type": "LineString","coordinates": [[34.32128906249999,54.67383096593114],[45.3955078125,54.44449176335762],[52.7783203125,52.61639023304539],[62.13867187499999,49.095452162534826],[76.1572265625,43.45291889355465]]}}]}');
vectorSourceC = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(dataC,{featureProjection: 'EPSG:3857'})
});
featuresC = vectorSourceC.getFeatures();
var point=null; //Коордионаты первой точки в маршруте
for(i=0;i<featuresC.length;i++)
{
featuresC[i].setStyle(new ol.style.Style({
fill: new ol.style.Fill({color: 'rgba(255, 0, 76, 0.3)'}),
stroke: new ol.style.Stroke({color: 'rgba(255, 0, 0, 0.7)', width: 4}),
text: new ol.style.Text({
font: 'bold 12px helvetica,sans-serif',
//text: userData.percent+" %",
fill: new ol.style.Fill({color: 'black'}),
stroke: new ol.style.Stroke({color: 'white', width: 1}),
offsetX: 0,
offsetY: 0
})
}));
thiz.feature=featuresC[i]; //Должен быть один массив в объекте
thiz.feature.userData=thiz; //Ссылка на TRoute
g_vectorSourceRoute.addFeature(featuresC[i]);
}
var pointS=thiz.feature.getGeometry().getCoordinates()[0]; //Коордионаты первой точки в треке
var pointE=thiz.feature.getGeometry().getCoordinates()[thiz.feature.getGeometry().getCoordinates().length-1]; //Координаты последней точки
//Обозначаю начальную точку маршрута как A
thiz.featureA = new ol.Feature({geometry: new ol.geom.Point(pointS)});
thiz.featureA.setStyle(new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 24],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: '../resources/images/icons/19.png'
}))
}));
g_vectorSourceRoute.addFeature(thiz.featureA);
//Обозначаю конечную точку маршрутат как B
thiz.featureB = new ol.Feature({geometry: new ol.geom.Point(pointE)});
thiz.featureB.setStyle(new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 24],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: '../resources/images/icons/20.png'
}))
}));
g_vectorSourceRoute.addFeature(thiz.featureB);
//Если в режиме редактирования точек то отображаем эти точки
if(thiz.shP)
enableEditPoints(thiz.feature);
}else
{
alert(status);
}
}}(this)
});
}
};
//У каждого маршрута должно быть по крайней мере 2 контрольные точки
class TCheckPoint
{
constructor(){
this.uid=getUID(); //Уникальный идентификатор
this.id='';
this.feature=null; //Объект который отображается на карте
this.shP=false; //Показывать ли точки для редактирования
this.visible=false; //По умолчанию всё видим
}
getVisibility()
{
return this.visible;
}
setVisibility(val)
{
var chb=document.getElementById("route_ch_c_"+this.id);
if(val)
{
if(!chb.checked) chb.checked=true;
if(this.feature==null)
{
this.getGeoJSON(); //Подгружаем объект с сервера
}else
{
//Проверяю чтобы заново не добавить
var exists=false;
var features=g_vectorSourceRoute.getFeatures();
for(var i=0;i<features.length;i++)
{
if(features[i]==this.feature)
{
exists=true;
break;
}
}
if(!exists)
g_vectorSourceRoute.addFeature(this.feature);
}
}else{
if(chb!=null && chb.checked) chb.checked=false;
if(this.feature!=null)
{
//Проверяем есть ли Feature а если есть то удаляем
var exists=false;
var features=g_vectorSourceRoute.getFeatures();
for(var i=0;i<features.length;i++)
{
if(features[i]==this.feature)
{
exists=true;
break;
}
}
if(exists)
{
g_vectorSourceRoute.removeFeature(this.feature);
this.showPoints(false);
}
}
}
this.visible=val;
}
//Отобразить точки для редактирования
showPoints(val)
{
//alert("showPoints="+val);
this.shP=val;
if(this.shP)
enableEditPoints(this.feature);
else
disableEditPoints(this.feature);
return true;
}
goToCenter()
{
var point=ol.proj.transform([parseFloat(this.lon), parseFloat(this.lat)], 'EPSG:4326','EPSG:3857');
g_map.getView().setCenter(point);
if(g_map.getView().getZoom()<9)
g_map.getView().setZoom(9);
}
//Запросить гео данные для построения объекта на карте
getGeoJSON()
{
if(this.feature!=null) return;
var data = {
id: this.id
};
$.ajax({
url: '/monitoring/pscripts/routes.php?fn=2',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
type: "POST",
dataType: "json",
success: function(thiz){return function(data,status){
if(status=='success')
{
var features = (new ol.format.GeoJSON()).readFeatures(data, {dataProjection: 'EPSG:4326',featureProjection: 'EPSG:3857'});
for(i=0;i<features.length;i++)
{
features[i].setStyle(new ol.style.Style({
fill: new ol.style.Fill({color: 'rgba(0, 255, 0, 0.5)'}),
stroke: new ol.style.Stroke({color: 'rgba(0, 100, 0, 0.7)', width: 2}),
text: new ol.style.Text({
font: 'bold 12px helvetica,sans-serif',
//text: userData.percent+" %",
fill: new ol.style.Fill({color: 'black'}),
stroke: new ol.style.Stroke({color: 'white', width: 1}),
offsetX: 0,
offsetY: 0
})
}));
thiz.feature=features[i]; //Должен быть один объект в объекте
thiz.feature.userData=thiz; //ссылка на родителя
g_vectorSourceRoute.addFeature(thiz.feature);
//Если в режиме редактирования точек то отображаем эти точки
if(thiz.shP)
enableEditPoints(thiz.feature);
}
}else
{
alert(status);
}
}}(this)
});
}
}