Skip to content

Commit

Permalink
fixed regex bugs. Made search results display and node clustering wor…
Browse files Browse the repository at this point in the history
…k together. Fixed refreshContent() bug. Made radio buttons for full circuit vs. search results display
  • Loading branch information
ASC95 committed May 21, 2024
1 parent c667298 commit f579413
Show file tree
Hide file tree
Showing 11 changed files with 506 additions and 348 deletions.
37 changes: 18 additions & 19 deletions omf/static/geoJsonMap/v3/clusterControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ClusterControlClass = L.Control.extend({
throw TypeError('The "controller" argument must be instanceof FeatureController.');
}
this._controller = controller;
this._on = false;
// - Create div
this._div = L.DomUtil.create('div', 'leaflet-bar');
this._div.classList.add('leaflet-customControlDiv');
Expand All @@ -24,33 +25,31 @@ const ClusterControlClass = L.Control.extend({
// - Add a tooltip
this._div.title = '- The node grouping tool allows you to group nodes into a cluster\n- Click this button to enable\n- Click this button to disable'
// - Attach listeners
this._on = false;
this._div.addEventListener('click', () => {
LeafletLayer.map.removeLayer(LeafletLayer.nodeLayers);
const overlayMap = [];
for (const layer of LeafletLayer.control._layers) {
if (layer.overlay === true) {
overlayMap.push(layer);
}
}
overlayMap.forEach(layer => LeafletLayer.control.removeLayer(layer.layer));
if (LeafletLayer.nodeLayers instanceof L.MarkerClusterGroup) {
// - Clustering was enabled, so disable it
if (this._on) {
this._div.style.removeProperty('border');
this._div.replaceChildren(this._getExpandSvg());
LeafletLayer.nodeLayers = L.featureGroup(LeafletLayer.nodeLayers.getLayers());
for (const node of LeafletLayer.nodeClusterLayers.getLayers()) {
LeafletLayer.nodeLayers.addLayer(node);
}
LeafletLayer.nodeClusterLayers.clearLayers();
this._on = false;
// - Clustering was disabled, so enable it
} else {
this._div.style.border = '2px solid #7FFF00';
this._div.replaceChildren(this._getCompressSvg());
const nodeLayers = LeafletLayer.nodeLayers.getLayers();
LeafletLayer.nodeLayers = L.markerClusterGroup();
nodeLayers.forEach(l => LeafletLayer.nodeLayers.addLayer(l));
for (const node of LeafletLayer.nodeLayers.getLayers()) {
LeafletLayer.nodeClusterLayers.addLayer(node);
}
LeafletLayer.nodeLayers.clearLayers();
this._on = true;
}
const nodeLayerIndex = overlayMap.findIndex(layer => layer.name === 'Nodes');
overlayMap[nodeLayerIndex] = {layer: LeafletLayer.nodeLayers, name: 'Nodes'};
for (const layer of overlayMap) {
LeafletLayer.control.addOverlay(layer.layer, layer.name);
// - Force redraw
for (const layer of [LeafletLayer.nodeLayers, LeafletLayer.nodeClusterLayers]) {
LeafletLayer.map.removeLayer(layer);
LeafletLayer.map.addLayer(layer);
}
LeafletLayer.map.addLayer(LeafletLayer.nodeLayers);
});
if (options !== null) {
L.setOptions(this, options);
Expand Down
57 changes: 15 additions & 42 deletions omf/static/geoJsonMap/v3/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Feature {
#feature;
#graph;
#observers;
#originalFeature;

/**
* @param {Object} feature - a standard GeoJSON feature
Expand All @@ -16,7 +15,6 @@ class Feature {
this.#feature = feature;
this.#graph = null
this.#observers = [];
this.#originalFeature = structuredClone(feature);
}

// *********************************
Expand All @@ -34,10 +32,10 @@ class Feature {
deleteProperty(propertyKey, namespace='treeProps') {
// - The function signature above is part of the ObservableInterface API. The implementation below is not
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be a string.');
throw TypeError('The "propertyKey" argument must be a string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string.');
throw TypeError('The "namespace" argument must be a string.');
}
if (['treeProps', 'formProps', 'urlProps'].includes(namespace)) {
if (this.#feature.properties.hasOwnProperty(namespace)) {
Expand Down Expand Up @@ -146,7 +144,7 @@ class Feature {
getProperties(namespace) {
// - The function signature above is part of the ObservableInterface API. The implementation below is not
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string');
throw TypeError('The "namespace" argument must be a string');
}
if (['treeProps', 'formProps', 'urlProps'].includes(namespace)) {
if (this.#feature.properties.hasOwnProperty(namespace)) {
Expand All @@ -172,10 +170,10 @@ class Feature {
getProperty(propertyKey, namespace='treeProps') {
// - The function signature above is part of the ObservableInterface API. The implementation below is not
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be a string.');
throw TypeError('The "propertyKey" argument must be a string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string.');
throw TypeError('The "namespace" argument must be a string.');
}
if (['treeProps', 'formProps', 'urlProps'].includes(namespace)) {
if (this.#feature.properties.hasOwnProperty(namespace)) {
Expand Down Expand Up @@ -234,10 +232,10 @@ class Feature {
hasProperty(propertyKey, namespace='treeProps') {
// - The function signature above is part of the ObservableInterface API. The implementation below is not
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be a string.');
throw TypeError('The "propertyKey" argument must be a string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string.');
throw TypeError('The "namespace" argument must be a string.');
}
if (['treeProps', 'formProps', 'urlProps'].includes(namespace)) {
if (this.#feature.properties.hasOwnProperty(namespace)) {
Expand Down Expand Up @@ -299,7 +297,7 @@ class Feature {
setCoordinates(coordinates) {
// - The function signature above is part of the ObservableInterface API. The implementation below is not
if (!(coordinates instanceof Array)) {
throw TypeError('"coordinates" argument must be instanceof Array.');
throw TypeError('The "coordinates" argument must be instanceof Array.');
}
// - Check that all coordinate values are valid numbers
const flatCoordinates = coordinates.flat(3);
Expand Down Expand Up @@ -376,10 +374,10 @@ class Feature {
setProperty(propertyKey, propertyValue, namespace='treeProps') {
// - The function signature above is part of the ObservableInterface API. The implementation below is not
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be a string.');
throw TypeError('The "propertyKey" argument must be a string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string.');
throw TypeError('The "namespace" argument must be a string.');
}
if (['treeProps', 'formProps', 'urlProps'].includes(namespace)) {
if (this.#feature.properties.hasOwnProperty(namespace)) {
Expand Down Expand Up @@ -431,10 +429,10 @@ class Feature {
updatePropertyOfObservers(propertyKey, oldPropertyValue, namespace='treeProps') {
// - The function signature above is part of the ObservableInterface API. The implementation below is not
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be typeof string.');
throw TypeError('The "propertyKey" argument must be typeof string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be typeof string.');
throw TypeError('The "namespace" argument must be typeof string.');
}
this.#observers.forEach(ob => ob.handleUpdatedProperty(this, propertyKey, oldPropertyValue, namespace));
if (this.#graph instanceof FeatureGraph) {
Expand Down Expand Up @@ -473,7 +471,7 @@ class Feature {
handleUpdatedCoordinates(observable, oldCoordinates) {
// - The function signature above is part of the ObserverInterface API. The implementation below is not
if (!(oldCoordinates instanceof Array)) {
throw TypeError('"oldCoordinates" argument must be an array.');
throw TypeError('The "oldCoordinates" argument must be an array.');
}
const observableName = observable.getProperty('name');
const thisName = this.getProperty('name');
Expand Down Expand Up @@ -511,10 +509,10 @@ class Feature {
handleUpdatedProperty(observable, propertyKey, oldPropertyValue, namespace='treeProps') {
// - The function signature above is part of the ObserverInterface API. The implementation below is not
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be a string.');
throw TypeError('The "propertyKey" argument must be a string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string.');
throw TypeError('The "namespace" argument must be a string.');
}
if (propertyKey === 'name') {
['from', 'to', 'parent'].forEach(k => {
Expand Down Expand Up @@ -601,31 +599,6 @@ class Feature {
isPolygon() {
return this.#feature.geometry.type === 'Polygon' && !this.isConfigurationObject();
}

/**
* - Reset this Feature's coordinates and properties to how they were when the page was loaded
* @returns {undefined}
*/
resetState() {
this.setCoordinates(structuredClone(this.#originalFeature.geometry.coordinates));
for (const [key, val] of Object.entries(this.#feature.properties)) {
if (!this.#originalFeature.properties.hasOwnProperty(key)) {
this.deleteProperty(key, 'meta');
} else {
this.setProperty(key, this.#originalFeature.properties[key], 'meta');
}
if (key === 'treeProps') {
for (const [tKey, tVal] of Object.entries(this.#feature.properties.treeProps)) {
if (!this.#originalFeature.properties.treeProps.hasOwnProperty(tKey)) {
this.deleteProperty(tKey);
} else {
this.setProperty(tKey, this.#originalFeature.properties.treeProps[tKey]);
}
}
}
// - Modal features can't be edited by the user, so I don't need to deal with formProps or urlProps
}
}
}

class UnsupportedOperationError extends Error {
Expand Down
26 changes: 13 additions & 13 deletions omf/static/geoJsonMap/v3/featureController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FeatureController { // implements ControllerInterface
*/
constructor(observableGraph) {
if (!(observableGraph instanceof FeatureGraph)) {
throw TypeError('"observableGraph" argument must be instanceof FeatureGraph.')
throw TypeError('The "observableGraph" argument must be instanceof FeatureGraph.')
}
this.observableGraph = observableGraph;
}
Expand Down Expand Up @@ -56,13 +56,13 @@ class FeatureController { // implements ControllerInterface
*/
deleteProperty(observables, propertyKey, namespace='treeProps') {
if (!(observables instanceof Array)) {
throw TypeError('"observables" argument must be instanceof Array.');
throw TypeError('The "observables" argument must be instanceof Array.');
}
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be a string.');
throw TypeError('The "propertyKey" argument must be a string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string.');
throw TypeError('The "namespace" argument must be a string.');
}
observables.forEach(ob => {
if (ob.hasProperty(propertyKey, namespace)) {
Expand All @@ -80,7 +80,7 @@ class FeatureController { // implements ControllerInterface
*/
deleteObservables(observables) {
if (!(observables instanceof Array)) {
throw TypeError('"observables" argument must be instanceof Array.');
throw TypeError('The "observables" argument must be instanceof Array.');
}
const observablesCopy = [...observables];
for (const ob of observablesCopy) {
Expand All @@ -100,10 +100,10 @@ class FeatureController { // implements ControllerInterface
*/
setCoordinates(observables, coordinates) {
if (!(observables instanceof Array)) {
throw TypeError('"observables" argument must be instanceof Array.');
throw TypeError('The "observables" argument must be instanceof Array.');
}
if (!(coordinates instanceof Array)) {
throw TypeError('"coordinates" argument must be instanceof Array.');
throw TypeError('The "coordinates" argument must be instanceof Array.');
}
observables.forEach(ob => {
ob.setCoordinates(coordinates);
Expand All @@ -125,13 +125,13 @@ class FeatureController { // implements ControllerInterface
*/
setProperty(observables, propertyKey, propertyValue, namespace='treeProps') {
if (!(observables instanceof Array)) {
throw TypeError('"observables" argument must be instanceof Array.');
throw TypeError('The "observables" argument must be instanceof Array.');
}
if (typeof propertyKey !== 'string') {
throw TypeError('"propertyKey" argument must be a string.');
throw TypeError('The "propertyKey" argument must be a string.');
}
if (typeof namespace !== 'string') {
throw TypeError('"namespace" argument must be a string.');
throw TypeError('The "namespace" argument must be a string.');
}
observables.forEach(ob => {
ob.setProperty(propertyKey, propertyValue, namespace);
Expand Down Expand Up @@ -180,13 +180,13 @@ class FeatureController { // implements ControllerInterface
throw TypeError('"observable" argument must be instanceof Feature.');
}
if (!(modal instanceof Modal)) {
throw TypeError('"modal" argument must be instanceof Modal.');
throw TypeError('The "modal" argument must be instanceof Modal.');
}
if (!(submitButton instanceof HTMLButtonElement) && !(submitButton === null)) {
throw TypeError('"submitButton" argument must be instanceof HTMLButtonElement or null');
throw TypeError('The "submitButton" argument must be instanceof HTMLButtonElement or null');
}
if (typeof reload !== 'boolean') {
throw TypeError('"reload" argument must be a boolean.');
throw TypeError('The "reload" argument must be a boolean.');
}
if (submitButton !== null) {
submitButton.disabled = true;
Expand Down
Loading

0 comments on commit f579413

Please sign in to comment.