Стрелочки

This commit is contained in:
zakhy 2025-04-29 11:58:31 +07:00
parent e0e4f475ea
commit bf982e3aad
2 changed files with 89 additions and 79 deletions

View File

@ -197,90 +197,100 @@
mapCore.addLayer(historyLayer, 'static');
function getColorByColorIndex(colorIndex) {
const colors = ["#0d6efd", "#6f42c1", "#dc3545", "#fd7e14", "#d63384", "#ffc107", "#198754", "#20c997", "#0dcaf0", "#6610f2"]
let numIndex = Number(colorIndex)
while (colorIndex > colors.length) numIndex -= colors.length
return colors[numIndex]
}
function getColorByColorIndex(colorIndex) {
const colors = ["#0d6efd", "#6f42c1", "#dc3545", "#fd7e14", "#d63384",
"#ffc107", "#198754", "#20c997", "#0dcaf0", "#6610f2"];
let numIndex = Number(colorIndex);
while (numIndex >= colors.length) numIndex -= colors.length;
return colors[numIndex];
}
function styleFunction(feature) {
const geometry = feature.getGeometry();
const styles = [];
const colorIndex = feature.get('colorIndex')
const fillColor = getColorByColorIndex(colorIndex)
console.log(fillColor)
if (geometry.getType() === 'LineString') {
// Стилизация линии
styles.push(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: fillColor,
width: 2,
}),
})
);
function styleFunction(feature) {
const geometry = feature.getGeometry();
const styles = [];
const colorIndex = feature.get('colorIndex');
const fillColor = getColorByColorIndex(colorIndex);
geometry.forEachSegment(function (start, end) {
const dx = end[0] - start[0];
const dy = end[1] - start[1];
const rotation = Math.atan2(dy, dx);
var svg = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M7.293 4.707 14.586 12l-7.293 7.293 1.414 1.414L17.414 12 8.707 3.293 7.293 4.707z" fill="${fillColor}"/></svg>`;
// Стрелочки на концах линий
styles.push(
new ol.style.Style({
geometry: new ol.geom.Point(end),
image: new ol.style.Icon({
src: 'data:image/svg+xml;utf8,' + svg,
anchor: [0.9, 0.5],
rotateWithView: true,
rotation: -rotation,
}),
})
);
});
if (geometry.getType() === 'LineString') {
// Стиль для линии
styles.push(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: fillColor,
width: 2,
}),
})
);
styles.push(
new ol.style.Style({
text: new ol.style.Text({
text: feature.get("name"),
font: '12px Calibri,sans-serif',
fill: new ol.style.Fill({color: '#000'}),
stroke: new ol.style.Stroke({color: '#fff', width: 2}),
placement: 'line',
}),
})
);
geometry.forEachSegment(function(start, end) {
const dx = end[0] - start[0];
const dy = end[1] - start[1];
const rotation = Math.atan2(dy, dx);
} else if (geometry.getType() === 'Point') {
// Стилизация точки
styles.push(
new ol.style.Style({
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({color: 'white'}),
stroke: new ol.style.Stroke({color: `${fillColor}`, width: 1}),
}),
})
);
// Динамически создаём SVG с нужным цветом
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">` +
`<path d="M7.293 4.707 14.586 12l-7.293 7.293 1.414 1.414L17.414 12 8.707 3.293 7.293 4.707z" ` +
`fill="${fillColor}"/></svg>`;
if (time) {
styles.push(
new ol.style.Style({
text: new ol.style.Text({
text: feature.get('time'),
font: '12px Calibri,sans-serif',
fill: new ol.style.Fill({color: '#000'}),
stroke: new ol.style.Stroke({color: '#fff', width: 2}),
offsetY: -15, // Чуть выше точки
}),
})
);
}
}
// Правильно кодируем SVG для data URI
const encodedSvg = encodeURIComponent(svg);
return styles;
}
styles.push(
new ol.style.Style({
geometry: new ol.geom.Point(end),
image: new ol.style.Icon({
src: 'data:image/svg+xml;utf8,' + encodedSvg,
anchor: [0.9, 0.5],
rotateWithView: true,
rotation: -rotation,
scale: 0.8 // Можно добавить масштаб при необходимости
}),
})
);
});
// Стиль для текста
styles.push(
new ol.style.Style({
text: new ol.style.Text({
text: feature.get("name"),
font: '12px Calibri,sans-serif',
fill: new ol.style.Fill({color: '#000'}),
stroke: new ol.style.Stroke({color: '#fff', width: 2}),
placement: 'line',
}),
})
);
}
else if (geometry.getType() === 'Point') {
// Стиль для точки
styles.push(
new ol.style.Style({
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({color: 'white'}),
stroke: new ol.style.Stroke({color: fillColor, width: 1}),
}),
})
);
if (feature.get('time')) {
styles.push(
new ol.style.Style({
text: new ol.style.Text({
text: feature.get('time'),
font: '12px Calibri,sans-serif',
fill: new ol.style.Fill({color: '#000'}),
stroke: new ol.style.Stroke({color: '#fff', width: 2}),
offsetY: -15,
}),
})
);
}
}
return styles;
}
function polygonGrayStyleFunction(feature, resolution) {

View File

@ -17,6 +17,7 @@ const propertiesTranslate = {
uid: "Идентификатор",
description: "Описание"
}
const invisibleProperties = ['id', 'geometry', 'icon', 'condition', 'style', 'layer', 'pk', "colorIndex"]
let popover;
function disposePopover() {
@ -134,7 +135,6 @@ class MapCore {
function createPopover(feature) {
const res = document.createElement('div')
const properties = feature.getProperties()
const invisibleProperties = ['id', 'geometry', 'icon', 'condition', 'style', 'layer', 'pk']
for (let property in properties) {
if (invisibleProperties.includes(property)) continue
let div = document.createElement('div')