-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
992 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.form-group label { | ||
display: flex; | ||
align-items: center; | ||
gap: 6px; | ||
height: 30px; | ||
} | ||
.form-group { | ||
display: flex; | ||
align-items: center; | ||
gap: 6px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/brands.css" crossorigin="anonymous"> | ||
<link rel="stylesheet" type="text/css" href="./theme/ol.css"> | ||
<link rel="stylesheet" type="text/css" href="/theme/site.css"> | ||
<link rel="stylesheet" type="text/css" href="webgl-draw-line.css"> | ||
<link rel="icon" type="image/svg+xml" href="/theme/img/logo-light.svg" media="(prefers-color-scheme: light)" /> | ||
<link rel="icon" type="image/svg+xml" href="/theme/img/logo-dark.svg" media="(prefers-color-scheme: dark)" /> | ||
</head> | ||
|
@@ -299,6 +300,12 @@ <h5 class="modal-title" id="tag-example-title"></h5> | |
<span id="value-offset">0</span> | ||
</div> | ||
<div class="form-group"> | ||
<label> | ||
<input type="checkbox" class="rebuild" id="dashEnable"> | ||
Enable dashes | ||
</label> | ||
</div> | ||
<div class="form-group" style="margin-left: 18px"> | ||
<label> | ||
Line dash pattern (px) | ||
<input type="number" class="uniform" name="dashLength1" min="0" max="100" value="25"> | ||
|
@@ -307,11 +314,26 @@ <h5 class="modal-title" id="tag-example-title"></h5> | |
<input type="number" class="uniform" name="dashLength4" min="0" max="100" value="15"> | ||
</label> | ||
</div> | ||
<label> | ||
Line dash offset (pixels) | ||
<input type="range" class="uniform" name="dashOffset" min="-200" max="200" value="0"> | ||
</label> | ||
<span id="value-dashOffset">0</span> | ||
<div class="form-group" style="margin-left: 18px"> | ||
<label> | ||
Line dash offset (pixels) | ||
<input type="range" class="uniform" name="dashOffset" min="-200" max="200" value="0"> | ||
</label> | ||
<span id="value-dashOffset">0</span> | ||
</div> | ||
<div class="form-group"> | ||
<label> | ||
<input type="checkbox" class="rebuild" id="patternEnable"> | ||
Enable image pattern | ||
</label> | ||
</div> | ||
<div class="form-group" style="margin-left: 18px"> | ||
<label> | ||
Pattern spacing (pixels) | ||
<input type="range" class="uniform" name="patternSpacing" min="0" max="64" value="0"> | ||
</label> | ||
<span id="value-patternSpacing">0</span> | ||
</div> | ||
</form> | ||
|
||
</div> | ||
|
@@ -340,33 +362,10 @@ <h5 class="source-heading">main.js</h5> | |
import {Tile as TileLayer} from 'ol/layer.js'; | ||
import {fromLonLat} from 'ol/proj.js'; | ||
|
||
const style = { | ||
variables: { | ||
width: 12, | ||
offset: 0, | ||
capType: 'butt', | ||
joinType: 'miter', | ||
miterLimit: 10, // ratio | ||
dashLength1: 25, | ||
dashLength2: 15, | ||
dashLength3: 15, | ||
dashLength4: 15, | ||
dashOffset: 0, | ||
}, | ||
'stroke-width': ['var', 'width'], | ||
'stroke-color': 'rgba(24,86,34,0.7)', | ||
'stroke-line-dash': [ | ||
['var', 'dashLength1'], | ||
['var', 'dashLength2'], | ||
['var', 'dashLength3'], | ||
['var', 'dashLength4'], | ||
], | ||
'stroke-line-dash-offset': ['var', 'dashOffset'], | ||
'stroke-offset': ['var', 'offset'], | ||
'stroke-line-cap': ['var', 'capType'], | ||
'stroke-line-join': ['var', 'joinType'], | ||
'stroke-miter-limit': ['var', 'miterLimit'], | ||
}; | ||
/** | ||
* @type {import('ol/style/webgl.js').WebGLStyle} | ||
*/ | ||
let style; | ||
|
||
class WebGLLayer extends Layer { | ||
createRenderer() { | ||
|
@@ -377,27 +376,94 @@ <h5 class="source-heading">main.js</h5> | |
} | ||
} | ||
|
||
const osm = new TileLayer({ | ||
source: new OSM(), | ||
}); | ||
|
||
const source = new VectorSource({ | ||
url: 'data/geojson/switzerland.geojson', | ||
format: new GeoJSON(), | ||
}); | ||
const vector = new WebGLLayer({ | ||
source: source, | ||
|
||
/** | ||
* @param {boolean} dash Include line dash | ||
* @param {boolean} pattern Include image pattern | ||
* @return {import('ol/style/webgl.js').WebGLStyle} Generated style | ||
*/ | ||
const getStyle = (dash, pattern) => { | ||
let newStyle = { | ||
variables: style | ||
? style.variables | ||
: { | ||
width: 12, | ||
offset: 0, | ||
capType: 'butt', | ||
joinType: 'miter', | ||
miterLimit: 10, // ratio | ||
dashLength1: 25, | ||
dashLength2: 15, | ||
dashLength3: 15, | ||
dashLength4: 15, | ||
dashOffset: 0, | ||
patternSpacing: 0, | ||
}, | ||
'stroke-width': ['var', 'width'], | ||
'stroke-color': 'rgba(24,86,34,0.7)', | ||
'stroke-offset': ['var', 'offset'], | ||
'stroke-miter-limit': ['var', 'miterLimit'], | ||
'stroke-line-cap': ['var', 'capType'], | ||
'stroke-line-join': ['var', 'joinType'], | ||
}; | ||
if (dash) { | ||
newStyle = { | ||
...newStyle, | ||
'stroke-line-dash': [ | ||
['var', 'dashLength1'], | ||
['var', 'dashLength2'], | ||
['var', 'dashLength3'], | ||
['var', 'dashLength4'], | ||
], | ||
'stroke-line-dash-offset': ['var', 'dashOffset'], | ||
}; | ||
} | ||
if (pattern) { | ||
delete newStyle['stroke-color']; | ||
newStyle = { | ||
...newStyle, | ||
'stroke-pattern-src': 'data/dot.svg', | ||
'stroke-pattern-spacing': ['var', 'patternSpacing'], | ||
}; | ||
} | ||
return newStyle; | ||
}; | ||
|
||
style = getStyle(false, false); | ||
|
||
let vector = new WebGLLayer({ | ||
source, | ||
}); | ||
|
||
const map = new Map({ | ||
layers: [osm, vector], | ||
layers: [ | ||
new TileLayer({ | ||
source: new OSM(), | ||
}), | ||
vector, | ||
], | ||
target: 'map', | ||
view: new View({ | ||
center: fromLonLat([8.43, 46.82]), | ||
zoom: 7, | ||
}), | ||
}); | ||
|
||
const rebuildStyle = () => { | ||
const dash = document.getElementById('dashEnable').checked; | ||
const pattern = document.getElementById('patternEnable').checked; | ||
style = getStyle(dash, pattern); | ||
map.removeLayer(vector); | ||
vector = new WebGLLayer({ | ||
source, | ||
}); | ||
map.addLayer(vector); | ||
}; | ||
|
||
const modify = new Modify({source: source}); | ||
map.addInteraction(modify); | ||
|
||
|
@@ -432,6 +498,9 @@ <h5 class="source-heading">main.js</h5> | |
document | ||
.querySelectorAll('input.uniform') | ||
.forEach((input) => input.addEventListener('input', inputListener)); | ||
document | ||
.querySelectorAll('input.rebuild') | ||
.forEach((input) => input.addEventListener('input', rebuildStyle)); | ||
</code></pre> | ||
</div> | ||
|
||
|
@@ -448,6 +517,17 @@ <h5 class="source-heading">index.html</h5> | |
width: 100%; | ||
height: 400px; | ||
} | ||
.form-group label { | ||
display: flex; | ||
align-items: center; | ||
gap: 6px; | ||
height: 30px; | ||
} | ||
.form-group { | ||
display: flex; | ||
align-items: center; | ||
gap: 6px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
@@ -497,6 +577,12 @@ <h5 class="source-heading">index.html</h5> | |
<span id="value-offset">0</span> | ||
</div> | ||
<div class="form-group"> | ||
<label> | ||
<input type="checkbox" class="rebuild" id="dashEnable"> | ||
Enable dashes | ||
</label> | ||
</div> | ||
<div class="form-group" style="margin-left: 18px"> | ||
<label> | ||
Line dash pattern (px) | ||
<input type="number" class="uniform" name="dashLength1" min="0" max="100" value="25"> | ||
|
@@ -505,11 +591,26 @@ <h5 class="source-heading">index.html</h5> | |
<input type="number" class="uniform" name="dashLength4" min="0" max="100" value="15"> | ||
</label> | ||
</div> | ||
<label> | ||
Line dash offset (pixels) | ||
<input type="range" class="uniform" name="dashOffset" min="-200" max="200" value="0"> | ||
</label> | ||
<span id="value-dashOffset">0</span> | ||
<div class="form-group" style="margin-left: 18px"> | ||
<label> | ||
Line dash offset (pixels) | ||
<input type="range" class="uniform" name="dashOffset" min="-200" max="200" value="0"> | ||
</label> | ||
<span id="value-dashOffset">0</span> | ||
</div> | ||
<div class="form-group"> | ||
<label> | ||
<input type="checkbox" class="rebuild" id="patternEnable"> | ||
Enable image pattern | ||
</label> | ||
</div> | ||
<div class="form-group" style="margin-left: 18px"> | ||
<label> | ||
Pattern spacing (pixels) | ||
<input type="range" class="uniform" name="patternSpacing" min="0" max="64" value="0"> | ||
</label> | ||
<span id="value-patternSpacing">0</span> | ||
</div> | ||
</form> | ||
|
||
<script type="module" src="main.js"></script> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.