196 lines
5.5 KiB
JavaScript
196 lines
5.5 KiB
JavaScript
const getGTOMarkerText = function (feature) {
|
|
const statemum = feature.get('garagenum')
|
|
if (statemum) {
|
|
return statemum;
|
|
}
|
|
return feature.get('name')
|
|
};
|
|
|
|
const createGTOStateNumTextStyle = function (feature, resolution) {
|
|
const font = 'bold' + ' ' + '12px' + '/' + '1' + ' ' + 'Arial';
|
|
return new ol.style.Text({
|
|
textAlign: 'center',
|
|
textBaseline: 'middle',
|
|
font: font,
|
|
text: getGTOMarkerText(feature, resolution),
|
|
fill: new ol.style.Fill({color: '#000'}),
|
|
offsetX: 0,
|
|
offsetY: -25,
|
|
placement: 'point',
|
|
maxAngle: '0.7853981633974483',
|
|
overflow: 'false',
|
|
rotation: parseFloat('0'),
|
|
backgroundFill: new ol.style.Fill({color: '#fff'}),
|
|
backgroundStroke: new ol.style.Stroke({color: '#000', width: 1}),
|
|
padding: [3, 3, 3, 3],
|
|
});
|
|
};
|
|
|
|
const createGTOZoneNameTextStyle = function (feature, resolution) {
|
|
const font = 'bold' + ' ' + '9px' + '/' + '1' + ' ' + 'Arial';
|
|
return new ol.style.Text({
|
|
textAlign: 'center',
|
|
textBaseline: 'middle',
|
|
font: font,
|
|
text: getGTOMarkerText(feature, resolution),
|
|
fill: new ol.style.Fill({color: '#000'}),
|
|
offsetX: 0,
|
|
offsetY: -25,
|
|
placement: 'point',
|
|
maxAngle: '0.7853981633974483',
|
|
overflow: 'false',
|
|
rotation: parseFloat('0'),
|
|
padding: [3, 3, 3, 3],
|
|
});
|
|
};
|
|
|
|
function GTOStyleFunction(feature, resolution) {
|
|
return new ol.style.Style({
|
|
image: new ol.style.Icon({
|
|
src: feature.get('icon') ? feature.get('icon') : "/static/img/belaz.png",
|
|
width: 30,
|
|
height: 20
|
|
}),
|
|
text: createGTOStateNumTextStyle(feature, resolution)
|
|
})
|
|
}
|
|
|
|
function createHatchPattern() {
|
|
// Создаем элемент canvas для шаблона штриховки
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = 10; // Ширина шаблона
|
|
canvas.height = 10; // Высота шаблона
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
ctx.strokeStyle = 'rgba(125, 105, 49, 0.1)'; // Цвет штриховки
|
|
ctx.lineWidth = 2;
|
|
|
|
// Рисуем диагональные линии для штриховки
|
|
ctx.beginPath();
|
|
ctx.moveTo(0, 10);
|
|
ctx.lineTo(10, 0);
|
|
ctx.stroke();
|
|
|
|
// Создаем паттерн из канваса
|
|
return ctx.createPattern(canvas, 'repeat');
|
|
}
|
|
|
|
|
|
function BaseStationStyleFunction(feature, resolution) {
|
|
return new ol.style.Style({
|
|
image: new ol.style.Icon({
|
|
src: '/static/img/base-station.png',
|
|
width: 50,
|
|
height: 40
|
|
})
|
|
})
|
|
}
|
|
|
|
const createFeatureTextStyle = function (feature, resolution, bgFill, textFill) {
|
|
|
|
const font = 'bold' + ' ' + '12px' + '/' + '1' + ' ' + 'Arial';
|
|
return new ol.style.Text({
|
|
textAlign: 'center',
|
|
textBaseline: 'middle',
|
|
font: font,
|
|
text: feature.get('sn'),
|
|
fill: textFill,
|
|
offsetX: 0,
|
|
offsetY: -27,
|
|
placement: 'point',
|
|
maxAngle: '0.7853981633974483',
|
|
overflow: 'false',
|
|
rotation: parseFloat('0'),
|
|
backgroundFill: bgFill,
|
|
backgroundStroke: new ol.style.Stroke({color: '#000', width: 1}),
|
|
padding: [3, 3, 3, 3],
|
|
});
|
|
};
|
|
|
|
function VlocationStyleFunction(feature, resolution) {
|
|
const objDate = new Date(feature.get("iso_time"))
|
|
let bgFill = undefined
|
|
let textFill = new ol.style.Fill({color: '#000'})
|
|
|
|
if (objDate) {
|
|
const nowDate = new Date()
|
|
const diffDate = (nowDate - objDate) / (1000 * 60 * 60)
|
|
if (diffDate < 1) {
|
|
bgFill = '#fff'
|
|
} else if (diffDate > 1 && diffDate < 24) {
|
|
bgFill = '#ffc107'
|
|
} else {
|
|
bgFill = "#bebebe"
|
|
}
|
|
}
|
|
|
|
const backgroundStyle = new ol.style.Circle({
|
|
radius: 15,
|
|
fill: new ol.style.Fill({
|
|
color: bgFill
|
|
}),
|
|
stroke: new ol.style.Stroke({
|
|
color: '#000',
|
|
width: 1
|
|
})
|
|
});
|
|
let textStyle
|
|
if (showTagSnOnMarker) {
|
|
textStyle = new ol.style.Style({
|
|
text: createFeatureTextStyle(feature, resolution, new ol.style.Fill({color: bgFill}), textFill)
|
|
})
|
|
} else {
|
|
textStyle = new ol.style.Style({
|
|
text: undefined
|
|
})
|
|
}
|
|
return [
|
|
new ol.style.Style({
|
|
image: backgroundStyle
|
|
}),
|
|
new ol.style.Style({
|
|
image: new ol.style.Icon({
|
|
src: '/static/img/worker.png',
|
|
width: 25,
|
|
height: 30
|
|
})
|
|
}),
|
|
textStyle
|
|
];
|
|
}
|
|
|
|
function SPStyleFunction(feature, resolution) {
|
|
return new ol.style.Style({
|
|
image: new ol.style.Icon({
|
|
src: '/static/img/earthquake_yellow.png',
|
|
width: 25,
|
|
height: 30
|
|
})
|
|
})
|
|
}
|
|
|
|
function polygonStyleFunction(feature, resolution) {
|
|
return new ol.style.Style({
|
|
stroke: new ol.style.Stroke({
|
|
color: 'rgb(0,117,217)',
|
|
width: 2,
|
|
}),
|
|
fill: new ol.style.Fill({
|
|
color: createHatchPattern(),
|
|
}),
|
|
});
|
|
}
|
|
|
|
function polygonBrownStyleFunction(feature, resolution) {
|
|
return new ol.style.Style({
|
|
stroke: new ol.style.Stroke({
|
|
color: 'rgb(199,136,10)',
|
|
width: 2,
|
|
}),
|
|
fill: new ol.style.Fill({
|
|
color: 'rgba(199,136,10, 0.6)',
|
|
}),
|
|
text: createGTOZoneNameTextStyle(feature, resolution)
|
|
});
|
|
}
|