From 74703e9c1dfdf93ba6d6a0b7406d68722eddc6ea Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Mon, 19 May 2025 09:42:29 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=20?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D0=BB=D0=B8=20=D0=B2=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/main/templates/main/index.html | 19 +---- .../street_pos/templates/street_pos/map.html | 11 +-- static/openLayers/layersStyles.js | 75 ++++++++++++++++++- 3 files changed, 73 insertions(+), 32 deletions(-) diff --git a/positioning/apps/main/templates/main/index.html b/positioning/apps/main/templates/main/index.html index a7a0afd..947aa91 100644 --- a/positioning/apps/main/templates/main/index.html +++ b/positioning/apps/main/templates/main/index.html @@ -48,6 +48,7 @@ + {% endblock %} {% block script_footer %} @@ -161,25 +162,7 @@ await updateMarkers(); setInterval(updateMarkers, 3000); - function VlocationStyleFunction(feature, resolution) { - return new ol.style.Style({ - image: new ol.style.Icon({ - src: '{% static 'img/worker.png' %}', - width: 25, - height: 30 - }) - }) - } - function BaseStationStyleFunction(feature, resolution) { - return new ol.style.Style({ - image: new ol.style.Icon({ - src: '{% static 'img/base-station.png' %}', - width: 50, - height: 40 - }) - }) - } function polygonGrayStyleFunction(feature, resolution) { return new ol.style.Style({ diff --git a/positioning/apps/street_pos/templates/street_pos/map.html b/positioning/apps/street_pos/templates/street_pos/map.html index 63590e4..b555c68 100644 --- a/positioning/apps/street_pos/templates/street_pos/map.html +++ b/positioning/apps/street_pos/templates/street_pos/map.html @@ -65,6 +65,7 @@ + {% endblock %} {% block script_footer %} diff --git a/static/openLayers/layersStyles.js b/static/openLayers/layersStyles.js index 5d2cdef..7537b7f 100644 --- a/static/openLayers/layersStyles.js +++ b/static/openLayers/layersStyles.js @@ -75,16 +75,83 @@ function createHatchPattern() { return ctx.createPattern(canvas, 'repeat'); } -function VlocationStyleFunction(feature, resolution) { + +function BaseStationStyleFunction(feature, resolution) { return new ol.style.Style({ image: new ol.style.Icon({ - src: '/static/img/worker.png', - width: 25, - height: 30 + 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 + }) + }); + + 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 + }) + }), + new ol.style.Style({ + text: createFeatureTextStyle(feature, resolution, new ol.style.Fill({color: bgFill}), textFill) + }) + ]; +} + function SPStyleFunction(feature, resolution) { return new ol.style.Style({ image: new ol.style.Icon({