Skip to content

Commit

Permalink
Merge pull request #7 from mapcomponents/fix/search_demo
Browse files Browse the repository at this point in the history
fix geojson file path
  • Loading branch information
eschuerg committed Dec 7, 2023
2 parents b2bbc54 + ef7d2c8 commit b928083
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
"/src/components/MlComponentTemplate/",
"/src/components/MlAerialPhotograph/",
"/src/components/MapLibreMapDebug/",
"/src/components/MlDemoDashboard/",
"/src/components/MlLaufwettbewerbApp/",
"/src/components/MlLaermkarte/",
"/src/components/MlMobilerImker/",
Expand Down
22 changes: 5 additions & 17 deletions src/applications/MlClientseitigeSuche/lib/SearchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import index from "./searchIndex.json";
import { SearchContextInterface } from "./searchContext.js";
import * as turf from "@turf/turf";
import { MlGeoJsonLayer, useMap } from "@mapcomponents/react-maplibre";
import worldBoundaries from "./world-administrative-boundaries-countries.json";

const SearchContext = React.createContext<SearchContextInterface>(
{} as SearchContextInterface
Expand All @@ -25,6 +26,10 @@ const SearchContextProvider = ({ children }: { children: React.ReactNode }) => {
mapId: undefined,
});

useEffect(() => {
setFeatureCollection(worldBoundaries);
}, []);

const getBoundingBox = (geometry: any): turf.BBox => {
if ("coordinates" in geometry && geometry.coordinates.length === 2) {
geometry = turf.buffer(geometry, 0.03, {
Expand All @@ -34,23 +39,6 @@ const SearchContextProvider = ({ children }: { children: React.ReactNode }) => {
return turf.bbox(geometry);
};

const loadFeatureCollection = useCallback(() => {
fetch(url + "/assets/world-administrative-boundaries-countries.geojson")
.then((res) => {
if (!res.ok) {
throw new Error();
}
return res.json();
})
.then((data) => {
setFeatureCollection(data);
});
}, []);

useEffect(() => {
loadFeatureCollection();
}, [loadFeatureCollection]);

useEffect(() => {
// @ts-ignore
const loadedIndex = elasticlunr.Index.load(index);
Expand Down

0 comments on commit b928083

Please sign in to comment.