forked from MapComplete/MapComplete
Merge master
This commit is contained in:
commit
b9fb18ee4c
45 changed files with 1651 additions and 854 deletions
|
@ -38,8 +38,8 @@ export class ExtraFunction {
|
|||
]),
|
||||
"Some advanced functions are available on **feat** as well:"
|
||||
]).SetClass("flex-col").AsMarkdown();
|
||||
|
||||
|
||||
|
||||
|
||||
private static readonly OverlapFunc = new ExtraFunction(
|
||||
"overlapWith",
|
||||
"Gives a list of features from the specified layer which this feature (partly) overlaps with. If the current feature is a point, all features that embed the point are given. The returned value is `{ feat: GeoJSONFeature, overlap: number}[]` where `overlap` is the overlapping surface are (in m²) for areas, the overlapping length (in meter) if the current feature is a line or `undefined` if the current feature is a point",
|
||||
|
|
|
@ -16,7 +16,7 @@ import RegisteringFeatureSource from "./RegisteringFeatureSource";
|
|||
|
||||
export default class FeaturePipeline implements FeatureSource {
|
||||
|
||||
public features: UIEventSource<{ feature: any; freshness: Date }[]>;
|
||||
public features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{feature: any; freshness: Date}[]>([]);
|
||||
|
||||
public readonly name = "FeaturePipeline"
|
||||
|
||||
|
@ -83,7 +83,8 @@ export default class FeaturePipeline implements FeatureSource {
|
|||
selectedElement,
|
||||
merged
|
||||
));
|
||||
this.features = source.features;
|
||||
|
||||
source.features.syncWith(this.features)
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ import State from "../../State";
|
|||
import Hash from "../Web/Hash";
|
||||
import MetaTagging from "../MetaTagging";
|
||||
import ExtractRelations from "../Osm/ExtractRelations";
|
||||
import FeatureSourceMerger from "./FeatureSourceMerger";
|
||||
|
||||
export default class MetaTaggingFeatureSource implements FeatureSource {
|
||||
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>(undefined);
|
||||
|
@ -14,6 +15,10 @@ export default class MetaTaggingFeatureSource implements FeatureSource {
|
|||
const self = this;
|
||||
this.name = "MetaTagging of " + source.name
|
||||
|
||||
if(allFeaturesSource.features === undefined){
|
||||
throw ("Initialize the featuresource fully first!"+allFeaturesSource.name)
|
||||
}
|
||||
|
||||
function update() {
|
||||
const featuresFreshness = source.features.data
|
||||
if (featuresFreshness === undefined) {
|
||||
|
|
|
@ -44,17 +44,16 @@ export class GeoOperations {
|
|||
const coor = feature.geometry.coordinates;
|
||||
for (const otherFeature of otherFeatures) {
|
||||
|
||||
if(feature.id === otherFeature.id){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (otherFeature.geometry === undefined) {
|
||||
console.error("No geometry for feature ", feature)
|
||||
throw "List of other features contains a feature without geometry an undefined"
|
||||
}
|
||||
|
||||
let otherFeatureBBox = BBox.get(otherFeature);
|
||||
if (!featureBBox.overlapsWith(otherFeatureBBox)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.inside(coor, otherFeature)) {
|
||||
if (GeoOperations.inside(coor, otherFeature)) {
|
||||
result.push({feat: otherFeature, overlap: undefined})
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +63,11 @@ export class GeoOperations {
|
|||
if (feature.geometry.type === "LineString") {
|
||||
|
||||
for (const otherFeature of otherFeatures) {
|
||||
|
||||
if(feature.id === otherFeature.id){
|
||||
continue;
|
||||
}
|
||||
|
||||
const otherFeatureBBox = BBox.get(otherFeature);
|
||||
const overlaps = featureBBox.overlapsWith(otherFeatureBBox)
|
||||
if (!overlaps) {
|
||||
|
@ -121,6 +125,18 @@ export class GeoOperations {
|
|||
if (feature.geometry.type === "Polygon" || feature.geometry.type === "MultiPolygon") {
|
||||
|
||||
for (const otherFeature of otherFeatures) {
|
||||
|
||||
if(feature.id === otherFeature.id){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(otherFeature.geometry.type === "Point"){
|
||||
if (this.inside(otherFeature, feature)) {
|
||||
result.push({feat: otherFeature, overlap: undefined})
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const otherFeatureBBox = BBox.get(otherFeature);
|
||||
const overlaps = featureBBox.overlapsWith(otherFeatureBBox)
|
||||
if (!overlaps) {
|
||||
|
@ -154,6 +170,10 @@ export class GeoOperations {
|
|||
if (feature.geometry.type === "Point") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(pointCoordinate.geometry !== undefined){
|
||||
pointCoordinate = pointCoordinate.geometry.coordinates
|
||||
}
|
||||
|
||||
if (feature.geometry.type === "MultiPolygon") {
|
||||
const coordinates = feature.geometry.coordinates[0];
|
||||
|
|
|
@ -3,7 +3,6 @@ import SimpleMetaTagger from "./SimpleMetaTagger";
|
|||
import {ExtraFunction} from "./ExtraFunction";
|
||||
import {Relation} from "./Osm/ExtractRelations";
|
||||
import FeatureSource from "./FeatureSource/FeatureSource";
|
||||
import State from "../State";
|
||||
|
||||
|
||||
interface Params {
|
||||
|
@ -48,32 +47,43 @@ export default class MetaTagging {
|
|||
layerFuncs.set(layer.id, this.createRetaggingFunc(layer));
|
||||
}
|
||||
|
||||
const featuresPerLayer = new Map<string, any[]>();
|
||||
for (const feature of (allKnownFeatures.features?.data ?? features ?? [])) {
|
||||
allKnownFeatures.features.addCallbackAndRun(newFeatures => {
|
||||
|
||||
const key = feature.feature._matching_layer_id;
|
||||
if (!featuresPerLayer.has(key)) {
|
||||
featuresPerLayer.set(key, [])
|
||||
}
|
||||
featuresPerLayer.get(key).push(feature.feature)
|
||||
}
|
||||
|
||||
for (const feature of features) {
|
||||
// @ts-ignore
|
||||
const key = feature.feature._matching_layer_id;
|
||||
const f = layerFuncs.get(key);
|
||||
if (f === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
f({featuresPerLayer: featuresPerLayer, memberships: relations}, feature.feature)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
||||
const featuresPerLayer = new Map<string, any[]>();
|
||||
for (const feature of (newFeatures.concat(features))) {
|
||||
|
||||
const key = feature.feature._matching_layer_id;
|
||||
if (!featuresPerLayer.has(key)) {
|
||||
featuresPerLayer.set(key, [])
|
||||
}
|
||||
featuresPerLayer.get(key).push(feature.feature)
|
||||
}
|
||||
|
||||
}
|
||||
for (const feature of features) {
|
||||
// @ts-ignore
|
||||
const key = feature.feature._matching_layer_id;
|
||||
const f = layerFuncs.get(key);
|
||||
if (f === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
f({featuresPerLayer: featuresPerLayer, memberships: relations}, feature.feature)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -105,7 +115,7 @@ export default class MetaTagging {
|
|||
}
|
||||
if (typeof result !== "string") {
|
||||
// Make sure it is a string!
|
||||
result = "" + result;
|
||||
result = JSON.stringify(result);
|
||||
}
|
||||
feature.properties[key] = result;
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue