143 lines
4.1 KiB
JavaScript
143 lines
4.1 KiB
JavaScript
const gtoDefaultIcon = '/static/img/belaz.png'
|
|
const workerDefaultIcon = '/static/img/worker.png'
|
|
|
|
const getMarkerText = function (feature) {
|
|
let text = feature.get('garagenum')
|
|
if (!text) {
|
|
text = feature.get('name')
|
|
}
|
|
if (text.length > 20) {
|
|
text = text.substring(0, 20) + '...'
|
|
}
|
|
return text
|
|
};
|
|
|
|
const createFeatureTextStyle = function (feature, resolution) {
|
|
const objCond = feature.get("condition")
|
|
let bgFill = undefined
|
|
let textFill = new ol.style.Fill({color: '#000'})
|
|
|
|
if (objCond) {
|
|
if (objCond === "ok") {
|
|
bgFill = new ol.style.Fill({color: '#fff'})
|
|
} else if (objCond === "warning") {
|
|
bgFill = new ol.style.Fill({color: '#ffc107'})
|
|
} else {
|
|
bgFill = new ol.style.Fill({color: '#bebebe'})
|
|
}
|
|
}
|
|
|
|
const font = 'bold' + ' ' + '12px' + '/' + '1' + ' ' + 'Arial';
|
|
return new ol.style.Text({
|
|
textAlign: 'center',
|
|
textBaseline: 'middle',
|
|
font: font,
|
|
text: getMarkerText(feature, resolution),
|
|
fill: textFill,
|
|
offsetX: 0,
|
|
offsetY: -25,
|
|
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],
|
|
});
|
|
};
|
|
|
|
const createGTOZoneNameTextStyle = function (feature, resolution) {
|
|
const font = 'bold' + ' ' + '9px' + '/' + '1' + ' ' + 'Arial';
|
|
return new ol.style.Text({
|
|
textAlign: 'center',
|
|
textBaseline: 'middle',
|
|
font: font,
|
|
text: getMarkerText(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') : gtoDefaultIcon,
|
|
width: 30,
|
|
height: 20
|
|
}),
|
|
text: createFeatureTextStyle(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 VlocationStyleFunction(feature, resolution) {
|
|
return new ol.style.Style({
|
|
image: new ol.style.Icon({
|
|
src: feature.get('icon') ? feature.get('icon') : workerDefaultIcon,
|
|
width: 25,
|
|
height: 30
|
|
}),
|
|
text: createFeatureTextStyle(feature, resolution)
|
|
})
|
|
}
|
|
|
|
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)
|
|
});
|
|
}
|