aboutsummaryrefslogtreecommitdiffstats
path: root/main.js
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2024-01-18 14:50:06 +0100
committerGuilhem Moulin <guilhem@fripost.org>2024-01-18 15:54:33 +0100
commit8d250c86386d95a907465c29c356e2b5de261f67 (patch)
tree5ad14043842403a7729d535955a8fd18f9996385 /main.js
parent0e63b707c1a6c1e0259ed96aee4c2198fc7c65b3 (diff)
Add features from Svenska Kraftnät.
Source: https://ext-geodatakatalog-forv.lansstyrelsen.se/PlaneringsKatalogen/GetMetaDataById?id=08ec56a0-6b5c-4f83-b29e-375e6f1a34b9_C
Diffstat (limited to 'main.js')
-rw-r--r--main.js116
1 files changed, 116 insertions, 0 deletions
diff --git a/main.js b/main.js
index 90e059f..3e9cdb4 100644
--- a/main.js
+++ b/main.js
@@ -27,6 +27,17 @@ import ScaleLine from 'ol/control/ScaleLine.js';
import Zoom from 'ol/control/Zoom.js';
import ZoomSlider from 'ol/control/ZoomSlider.js';
+import MVT from 'ol/format/MVT.js';
+import VectorTileLayer from 'ol/layer/VectorTile.js';
+import VectorTile from 'ol/source/VectorTile.js';
+import {createXYZ} from 'ol/tilegrid.js';
+
+import CircleStyle from 'ol/style/Circle.js';
+import Fill from 'ol/style/Fill.js';
+import RegularShape from 'ol/style/RegularShape.js';
+import Stroke from 'ol/style/Stroke.js';
+import Style from 'ol/style/Style.js';
+
import proj4 from 'proj4';
import { get as getProjection } from 'ol/proj.js';
import { register as registerProjection } from 'ol/proj/proj4.js';
@@ -432,6 +443,111 @@ view.on('change', function(event) {
});
+const styles = {
+ 'svk_lines':
+ [1, 1.5, 2, 2, 2, 2, 3, 4, 5, 6, 8, 10].map(function(width) {
+ return new Style({
+ zIndex: 2,
+ stroke: new Stroke({
+ color: 'black',
+ width: width,
+ }),
+ });
+ }),
+ 'svk_pylons':
+ [undefined, undefined, undefined, undefined, undefined]
+ .concat([3, 4, 5, 6, 8, 10, 15].map(function(radius) {
+ return new Style({
+ zIndex: 1,
+ image: new CircleStyle({
+ radius: radius,
+ fill: new Fill({
+ color: 'black',
+ }),
+ }),
+ });
+ })),
+ 'svk_stations':
+ [5, 6, 8, 8, 10].map(function(radius) {
+ return new Style({
+ zIndex: 0,
+ image: new RegularShape({
+ radius: radius,
+ points: 4,
+ angle: Math.PI/4,
+ fill: new Fill({
+ color: 'black',
+ }),
+ }),
+ });
+ })
+ .concat([12, 15].map(function(radius) {
+ return new Style({
+ zIndex: 0,
+ image: new RegularShape({
+ radius: radius,
+ points: 4,
+ angle: Math.PI/4,
+ fill: new Fill({
+ color: 'rgba(128, 128, 128, .85)',
+ }),
+ stroke: new Stroke({
+ width: 1,
+ color: 'rgb(0, 0, 0)',
+ }),
+ }),
+ });
+ }))
+ .concat([1, 1.5, 1.5, 2, 2].map(function(width) {
+ return new Style({
+ zIndex: 0,
+ fill: new Fill({
+ color: 'rgba(128, 128, 128, .7)',
+ }),
+ stroke: new Stroke({
+ width: width,
+ color: 'rgb(0, 0, 0)',
+ }),
+ });
+ })),
+};
+
+map.addLayer(new VectorTileLayer({
+ source: new VectorTile({
+ url: '/public/xyztiles/{z}/{x}/{y}.pbf',
+ format: new MVT({
+ layers: Object.keys(styles),
+ }),
+ projection: projection,
+ wrapX: false,
+ transition: 0,
+ tileGrid: createXYZ({
+ extent: extent,
+ tileSize: 1024,
+ maxResolution: 1024, /* = 1048576/1024 */
+ minZoom: 0,
+ maxZoom: 9,
+ }),
+ }),
+ /* XXX switch to 'hybrid' if there are perf issues; but that seems to
+ * put lines above points regardless of their respective z-index */
+ renderMode: 'vector',
+ declutter: false,
+ style: function(feature, resolution) {
+ const style = styles[feature.getProperties().layer];
+ if (!Array.isArray(style)) {
+ return style;
+ } else {
+ const maxi = style.length - 1;
+ const z = resolutions.length - 2 - Math.log2(resolution);
+ /* use Math.floor() as VectorTile.js calls getZForResolution(resolution, 1) */
+ const i = z <= 0 ? 0 : z >= maxi ? maxi : Math.floor(z);
+ // console.log(`resolution=${resolution}, z=${z}, i=${i}`);
+ return style[i];
+ }
+ },
+}));
+
/* layer selection panel */
(function() {
const modal = document.getElementById('layer-selection-panel');