Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,73 +1,79 @@
|
||||
import Feature from '../src/ol/Feature.js';
|
||||
import Map from '../src/ol/Map.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import {Point, LineString, Polygon} from '../src/ol/geom.js';
|
||||
import {Draw, Snap} from '../src/ol/interaction.js';
|
||||
import {Tile as TileLayer, Vector as VectorLayer} from '../src/ol/layer.js';
|
||||
import {OSM, Vector as VectorSource} from '../src/ol/source.js';
|
||||
import {Fill, Circle as CircleStyle, Stroke, Style, Text} from '../src/ol/style.js';
|
||||
import MousePosition from '../src/ol/control/MousePosition.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import {
|
||||
Circle as CircleStyle,
|
||||
Fill,
|
||||
Stroke,
|
||||
Style,
|
||||
Text,
|
||||
} from '../src/ol/style.js';
|
||||
import {Draw, Snap} from '../src/ol/interaction.js';
|
||||
import {LineString, Point, Polygon} from '../src/ol/geom.js';
|
||||
import {OSM, Vector as VectorSource} from '../src/ol/source.js';
|
||||
import {Tile as TileLayer, Vector as VectorLayer} from '../src/ol/layer.js';
|
||||
|
||||
const raster = new TileLayer({
|
||||
source: new OSM()
|
||||
source: new OSM(),
|
||||
});
|
||||
|
||||
const nodes = new VectorSource({wrapX: false});
|
||||
const nodesLayer = new VectorLayer({
|
||||
source: nodes,
|
||||
style: function(f) {
|
||||
style: function (f) {
|
||||
const style = new Style({
|
||||
image: new CircleStyle({
|
||||
radius: 8,
|
||||
fill: new Fill({color: 'rgba(255, 0, 0, 0.2)'}),
|
||||
stroke: new Stroke({color: 'red', width: 1})
|
||||
stroke: new Stroke({color: 'red', width: 1}),
|
||||
}),
|
||||
text: new Text({
|
||||
text: f.get('node').id.toString(),
|
||||
fill: new Fill({color: 'red'}),
|
||||
stroke: new Stroke({
|
||||
color: 'white',
|
||||
width: 3
|
||||
})
|
||||
})
|
||||
width: 3,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
return [style];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const edges = new VectorSource({wrapX: false});
|
||||
const edgesLayer = new VectorLayer({
|
||||
source: edges,
|
||||
style: function(f) {
|
||||
style: function (f) {
|
||||
const style = new Style({
|
||||
stroke: new Stroke({
|
||||
color: 'blue',
|
||||
width: 1
|
||||
width: 1,
|
||||
}),
|
||||
text: new Text({
|
||||
text: f.get('edge').id.toString(),
|
||||
fill: new Fill({color: 'blue'}),
|
||||
stroke: new Stroke({
|
||||
color: 'white',
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
width: 2,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
return [style];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const faces = new VectorSource({wrapX: false});
|
||||
const facesLayer = new VectorLayer({
|
||||
source: faces,
|
||||
style: function(f) {
|
||||
style: function (f) {
|
||||
const style = new Style({
|
||||
stroke: new Stroke({
|
||||
color: 'black',
|
||||
width: 1
|
||||
width: 1,
|
||||
}),
|
||||
fill: new Fill({
|
||||
color: 'rgba(0, 255, 0, 0.2)'
|
||||
color: 'rgba(0, 255, 0, 0.2)',
|
||||
}),
|
||||
text: new Text({
|
||||
font: 'bold 12px sans-serif',
|
||||
@@ -75,12 +81,12 @@ const facesLayer = new VectorLayer({
|
||||
fill: new Fill({color: 'green'}),
|
||||
stroke: new Stroke({
|
||||
color: 'white',
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
width: 2,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
return [style];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const map = new Map({
|
||||
@@ -88,26 +94,26 @@ const map = new Map({
|
||||
target: 'map',
|
||||
view: new View({
|
||||
center: [-11000000, 4600000],
|
||||
zoom: 16
|
||||
})
|
||||
zoom: 16,
|
||||
}),
|
||||
});
|
||||
|
||||
const topo = topolis.createTopology();
|
||||
|
||||
topo.on('addnode', nodeToFeature);
|
||||
topo.on('removenode', function(e) {
|
||||
topo.on('removenode', function (e) {
|
||||
removeElementFeature(nodes, e);
|
||||
});
|
||||
topo.on('addedge', edgeToFeature);
|
||||
topo.on('modedge', function(e) {
|
||||
topo.on('modedge', function (e) {
|
||||
const feature = edges.getFeatureById(e.id);
|
||||
feature.setGeometry(new LineString(e.coordinates));
|
||||
});
|
||||
topo.on('removeedge', function(e) {
|
||||
topo.on('removeedge', function (e) {
|
||||
removeElementFeature(edges, e);
|
||||
});
|
||||
topo.on('addface', faceToFeature);
|
||||
topo.on('removeface', function(e) {
|
||||
topo.on('removeface', function (e) {
|
||||
removeElementFeature(faces, e);
|
||||
});
|
||||
|
||||
@@ -119,7 +125,7 @@ function removeElementFeature(source, element) {
|
||||
function nodeToFeature(node) {
|
||||
const feature = new Feature({
|
||||
geometry: new Point(node.coordinate),
|
||||
node: node
|
||||
node: node,
|
||||
});
|
||||
feature.setId(node.id);
|
||||
nodes.addFeature(feature);
|
||||
@@ -128,7 +134,7 @@ function nodeToFeature(node) {
|
||||
function edgeToFeature(edge) {
|
||||
const feature = new Feature({
|
||||
geometry: new LineString(edge.coordinates),
|
||||
edge: edge
|
||||
edge: edge,
|
||||
});
|
||||
feature.setId(edge.id);
|
||||
edges.addFeature(feature);
|
||||
@@ -138,7 +144,7 @@ function faceToFeature(face) {
|
||||
const coordinates = topo.getFaceGeometry(face);
|
||||
const feature = new Feature({
|
||||
geometry: new Polygon(coordinates),
|
||||
face: face
|
||||
face: face,
|
||||
});
|
||||
feature.setId(face.id);
|
||||
faces.addFeature(feature);
|
||||
@@ -166,7 +172,13 @@ function onDrawend(e) {
|
||||
const edgesAtStart = topo.getEdgeByPoint(startCoord, 5);
|
||||
const edgesAtEnd = topo.getEdgeByPoint(endCoord, 5);
|
||||
const crossing = topo.getEdgesByLine(edgeGeom);
|
||||
if (crossing.length === 1 && !start && !end && edgesAtStart.length === 0 && edgesAtEnd.length === 0) {
|
||||
if (
|
||||
crossing.length === 1 &&
|
||||
!start &&
|
||||
!end &&
|
||||
edgesAtStart.length === 0 &&
|
||||
edgesAtEnd.length === 0
|
||||
) {
|
||||
topo.remEdgeNewFace(crossing[0]);
|
||||
start = crossing[0].start;
|
||||
if (start.face) {
|
||||
@@ -193,12 +205,12 @@ function onDrawend(e) {
|
||||
}
|
||||
|
||||
const draw = new Draw({
|
||||
type: 'LineString'
|
||||
type: 'LineString',
|
||||
});
|
||||
draw.on('drawend', onDrawend);
|
||||
map.addInteraction(draw);
|
||||
const snap = new Snap({
|
||||
source: edges
|
||||
source: edges,
|
||||
});
|
||||
map.addInteraction(snap);
|
||||
map.addControl(new MousePosition());
|
||||
|
||||
Reference in New Issue
Block a user