Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29699eaf52 | ||
|
|
6b5f008478 | ||
|
|
89ddf994dc | ||
|
|
a285dd0752 |
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@worldwideview/wwv-plugin-osm-search",
|
"name": "@worldwideview/wwv-plugin-osm-search",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "OSM Search Plugin for WorldWideView",
|
"description": "OSM Search Plugin for WorldWideView",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -4,9 +4,20 @@ import { Eye, EyeOff } from "lucide-react";
|
|||||||
import { useOsmStore } from "../store";
|
import { useOsmStore } from "../store";
|
||||||
|
|
||||||
const COMMON_TAGS = [
|
const COMMON_TAGS = [
|
||||||
"amenity=hospital", "amenity=school", "amenity=police", "amenity=fire_station",
|
// Military & Security
|
||||||
"shop=supermarket", "highway=bus_stop", "building=house", "tourism=hotel",
|
"military=base", "military=bunker", "amenity=police", "amenity=prison",
|
||||||
"man_made=tower", "industrial=factory"
|
// Aviation & Maritime
|
||||||
|
"aeroway=aerodrome", "aeroway=helipad", "aeroway=hangar", "man_made=pier", "harbour=yes",
|
||||||
|
// Infrastructure & Utilities
|
||||||
|
"power=plant", "power=substation", "telecom=antenna", "man_made=communications_tower", "man_made=water_tower",
|
||||||
|
// Transport
|
||||||
|
"highway=bus_stop", "railway=station", "amenity=fuel", "amenity=parking",
|
||||||
|
// Medical & Emergency
|
||||||
|
"amenity=hospital", "amenity=fire_station", "amenity=clinic",
|
||||||
|
// General Commercial & Industrial
|
||||||
|
"shop=supermarket", "tourism=hotel", "industrial=factory", "landuse=industrial",
|
||||||
|
// Education & Amenities
|
||||||
|
"amenity=school", "amenity=university", "amenity=cafe", "building=house"
|
||||||
];
|
];
|
||||||
|
|
||||||
interface OSMSidebarProps {
|
interface OSMSidebarProps {
|
||||||
@@ -23,6 +34,39 @@ export function OSMSidebar({ plugin }: OSMSidebarProps) {
|
|||||||
const [distance, setDistance] = useState(500);
|
const [distance, setDistance] = useState(500);
|
||||||
const [isScanning, setIsScanning] = useState(false);
|
const [isScanning, setIsScanning] = useState(false);
|
||||||
|
|
||||||
|
// Taginfo dynamic search states
|
||||||
|
const [dynamicTags, setDynamicTags] = useState<string[]>([]);
|
||||||
|
const [isSearchingApi, setIsSearchingApi] = useState(false);
|
||||||
|
|
||||||
|
// Fetch dynamic tags when search text changes
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (searchText.length < 3) {
|
||||||
|
setDynamicTags([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timer = setTimeout(async () => {
|
||||||
|
setIsSearchingApi(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch(`https://taginfo.openstreetmap.org/api/4/search/by_keyword?query=${encodeURIComponent(searchText)}`);
|
||||||
|
const data = await res.json();
|
||||||
|
if (data && data.data) {
|
||||||
|
const tags = data.data
|
||||||
|
.filter((item: any) => item.key && item.value)
|
||||||
|
.map((item: any) => `${item.key}=${item.value}`)
|
||||||
|
.slice(0, 15);
|
||||||
|
setDynamicTags(tags);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Taginfo fetch failed", err);
|
||||||
|
} finally {
|
||||||
|
setIsSearchingApi(false);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [searchText]);
|
||||||
|
|
||||||
const toggleLock = () => {
|
const toggleLock = () => {
|
||||||
if (!bboxLocked) {
|
if (!bboxLocked) {
|
||||||
setLockedBbox(currentBbox);
|
setLockedBbox(currentBbox);
|
||||||
@@ -106,10 +150,13 @@ out center;`;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderedTags = searchText
|
// Combine filtered common tags with newly fetched dynamic tags, removing duplicates
|
||||||
|
const filteredCommon = searchText
|
||||||
? COMMON_TAGS.filter(t => t.toLowerCase().includes(searchText.toLowerCase()))
|
? COMMON_TAGS.filter(t => t.toLowerCase().includes(searchText.toLowerCase()))
|
||||||
: COMMON_TAGS;
|
: COMMON_TAGS;
|
||||||
|
|
||||||
|
const renderedTags = Array.from(new Set([...filteredCommon, ...dynamicTags]));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ display: "flex", flexDirection: "column", gap: "10px" }}>
|
<div style={{ display: "flex", flexDirection: "column", gap: "10px" }}>
|
||||||
<div style={{ background: "rgba(255,255,255,0.05)", padding: "10px", borderRadius: "6px", border: "1px solid rgba(255,255,255,0.1)" }}>
|
<div style={{ background: "rgba(255,255,255,0.05)", padding: "10px", borderRadius: "6px", border: "1px solid rgba(255,255,255,0.1)" }}>
|
||||||
@@ -200,20 +247,35 @@ out center;`;
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<input
|
<div style={{ position: "relative" }}>
|
||||||
style={{
|
<input
|
||||||
width: "100%",
|
style={{
|
||||||
padding: "8px",
|
width: "100%",
|
||||||
backgroundColor: "rgba(0,0,0,0.3)",
|
padding: "8px",
|
||||||
color: "#fff",
|
paddingRight: "24px",
|
||||||
border: "1px solid var(--border-subtle)",
|
backgroundColor: "rgba(0,0,0,0.3)",
|
||||||
borderRadius: "4px",
|
color: "#fff",
|
||||||
fontSize: "13px"
|
border: "1px solid var(--border-subtle)",
|
||||||
}}
|
borderRadius: "4px",
|
||||||
placeholder="Filter tags (e.g. amenity=...)"
|
fontSize: "13px"
|
||||||
value={searchText}
|
}}
|
||||||
onChange={e => setSearchText(e.target.value)}
|
placeholder="Filter or search OSM for tags..."
|
||||||
/>
|
value={searchText}
|
||||||
|
onChange={e => setSearchText(e.target.value)}
|
||||||
|
/>
|
||||||
|
{isSearchingApi && (
|
||||||
|
<span style={{
|
||||||
|
position: "absolute",
|
||||||
|
right: "8px",
|
||||||
|
top: "50%",
|
||||||
|
transform: "translateY(-50%)",
|
||||||
|
fontSize: "10px",
|
||||||
|
color: "var(--text-muted)"
|
||||||
|
}}>
|
||||||
|
⏳
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div style={{ display: "flex", flexWrap: "wrap", gap: "6px", maxHeight: "150px", overflowY: "auto", padding: "4px" }}>
|
<div style={{ display: "flex", flexWrap: "wrap", gap: "6px", maxHeight: "150px", overflowY: "auto", padding: "4px" }}>
|
||||||
{renderedTags.map(tag => {
|
{renderedTags.map(tag => {
|
||||||
const isActive = activeTags.includes(tag);
|
const isActive = activeTags.includes(tag);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "dist/",
|
"noEmit": true
|
||||||
"rootDir": "src/",
|
|
||||||
"jsx": "react-jsx"
|
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"]
|
"include": [
|
||||||
|
"src"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user