forked from MapComplete/MapComplete
Merge plant_detection
This commit is contained in:
commit
25ec71aff1
15 changed files with 780 additions and 158 deletions
|
@ -61,6 +61,8 @@ import StatisticsPanel from "./BigComponents/StatisticsPanel";
|
|||
import {OsmFeature} from "../Models/OsmFeature";
|
||||
import EditableTagRendering from "./Popup/EditableTagRendering";
|
||||
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
|
||||
import {ProvidedImage} from "../Logic/ImageProviders/ImageProvider";
|
||||
import PlantNetSpeciesSearch from "./BigComponents/PlantNetSpeciesSearch";
|
||||
|
||||
export interface SpecialVisualization {
|
||||
funcName: string,
|
||||
|
@ -196,7 +198,7 @@ class NearbyImageVis implements SpecialVisualization {
|
|||
new ChangeTagAction(
|
||||
id,
|
||||
new And(tags),
|
||||
tagSource,
|
||||
tagSource.data,
|
||||
{
|
||||
theme: state?.layoutToUse.id,
|
||||
changeType: "link-image"
|
||||
|
@ -1302,6 +1304,53 @@ export default class SpecialVisualizations {
|
|||
const [layerId, __] = tagRenderingId.split(".")
|
||||
return [layerId]
|
||||
}
|
||||
},
|
||||
{
|
||||
funcName: "plantnet_detection",
|
||||
|
||||
docs: "Sends the images linked to the current object to plantnet.org and asks it what plant species is shown on it. The user can then select the correct species; the corresponding wikidata-identifier will then be added to the object (together with `source:species:wikidata=plantnet.org AI`). ",
|
||||
args: [{
|
||||
name: "image_key",
|
||||
defaultValue: AllImageProviders.defaultKeys.join(","),
|
||||
doc: "The keys given to the images, e.g. if <span class='literal-code'>image</span> is given, the first picture URL will be added as <span class='literal-code'>image</span>, the second as <span class='literal-code'>image:0</span>, the third as <span class='literal-code'>image:1</span>, etc... Multiple values are allowed if ';'-separated "
|
||||
}],
|
||||
constr: (state, tags, args) => {
|
||||
let imagePrefixes: string[] = undefined;
|
||||
if (args.length > 0) {
|
||||
imagePrefixes = [].concat(...args.map(a => a.split(",")));
|
||||
}
|
||||
|
||||
const detect = new UIEventSource(false)
|
||||
const toggle = new Toggle(
|
||||
new Lazy(() => {
|
||||
const allProvidedImages: Store<ProvidedImage[]> = AllImageProviders.LoadImagesFor(tags, imagePrefixes)
|
||||
const allImages: Store<string[]> = allProvidedImages.map(pi => pi.map(pi => pi.url))
|
||||
return new PlantNetSpeciesSearch(allImages, async selectedWikidata => {
|
||||
selectedWikidata = Wikidata.ExtractKey(selectedWikidata)
|
||||
const change = new ChangeTagAction(tags.data.id,
|
||||
new And([new Tag("species:wikidata", selectedWikidata),
|
||||
new Tag("source:species:wikidata","PlantNet.org AI")
|
||||
]),
|
||||
tags.data,
|
||||
{
|
||||
theme: state.layoutToUse.id,
|
||||
changeType: "plantnet-ai-detection"
|
||||
}
|
||||
)
|
||||
await state.changes.applyAction(change)
|
||||
})
|
||||
}),
|
||||
new SubtleButton(undefined, "Detect plant species with plantnet.org").onClick(() => detect.setData(true)),
|
||||
detect
|
||||
)
|
||||
|
||||
return new Combine([
|
||||
toggle,
|
||||
new Combine([Svg.plantnet_logo_svg().SetClass("w-10 h-10 p-1 mr-1 bg-white rounded-full"),
|
||||
Translations.t.plantDetection.poweredByPlantnet])
|
||||
.SetClass("flex p-2 bg-gray-200 rounded-xl self-end")
|
||||
]).SetClass("flex flex-col")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue