Skip to content

Commit

Permalink
made icons URL configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
zdila committed Jun 15, 2023
1 parent 1b851fd commit 263cf36
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ For examples without using bundler see `demo-maplibregl.html` or `demo-leaflet.h
- `limit`: `number` - Maximum number of results to show. Default `5`.
- `country`: `string | string[]` - Limit search to specified country(ies). Default `undefined` (use all countries). Specify as [alpha-2 ISO 3166](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) lowercase code.
- `types`: `string[]` - Filter of feature types to return. Default `undefined` (all available feature types are returned).
- `apiUrl`: `string` - Geocoding API URL. Default MapTiler Geocoding API URL.
- `fetchParameters`: `RequestInit` - Extra fetch parameters. Default `undefined`.
- `iconsBaseUrl`: `string` - Base URL for POI icons. Default `"icons/"`.

### Methods

Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maptiler/geocoding-control",
"version": "0.0.91",
"version": "0.0.92",
"type": "module",
"author": {
"name": "Martin Ždila",
Expand Down Expand Up @@ -35,7 +35,7 @@
"build-svelte": "svelte-package -o dist.svelte",
"build-maptilersdk": "FLAVOUR=maptilersdk vite build",
"build-maplibre": "FLAVOUR=maplibre vite build",
"build-maplibre-controller": "FLAVOUR=maplibregl-controller vite build ",
"build-maplibre-controller": "FLAVOUR=maplibregl-controller vite build",
"build-leaflet": "FLAVOUR=leaflet vite build",
"build-leaflet-controller": "FLAVOUR=leaflet-controller vite build",
"build-react": "FLAVOUR=react vite build",
Expand Down Expand Up @@ -98,14 +98,14 @@
"concurrently": "^8.2.0",
"esm-env": "^1.0.0",
"leaflet": "^1.9.4",
"maplibre-gl": "^3.0.1",
"maplibre-gl": "^3.1.0",
"prettier": "^2.8.8",
"prettier-plugin-organize-imports": "^3.2.2",
"prettier-plugin-svelte": "^2.10.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"renamer": "^4.0.0",
"sass": "^1.63.3",
"sass": "^1.63.4",
"svelte": "^3.59.1",
"svelte-check": "^3.4.3",
"svelte-preprocess": "^5.0.4",
Expand Down
16 changes: 9 additions & 7 deletions src/lib/FeatureItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
export let missingIconsCache: Set<string>;
export let iconsBaseUrl: string;
const categories = feature.properties?.categories;
let category: string | undefined;
Expand All @@ -24,7 +26,7 @@
category = categories?.[index];
imageUrl = category
? `/icons/${category.replace(/ /g, "_")}.svg`
? iconsBaseUrl + category.replace(/ /g, "_") + ".svg"
: undefined;
} while (index > -1 && (!imageUrl || missingIconsCache.has(imageUrl)));
}
Expand All @@ -51,17 +53,17 @@
on:error={(e) => handleImgError(e.currentTarget)}
/>
{:else if feature.address}
<img src="/icons/housenumber.svg" alt={placeType} />
<img src={iconsBaseUrl + "housenumber.svg"} alt={placeType} />
{:else if feature.properties?.kind === "road" || feature.properties?.kind === "road_relation"}
<img src="/icons/road.svg" alt={placeType} />
<img src={iconsBaseUrl + "road.svg"} alt={placeType} />
{:else if feature.id.startsWith("address.")}
<img src="/icons/street.svg" alt={placeType} />
<img src={iconsBaseUrl + "street.svg"} alt={placeType} />
{:else if feature.id.startsWith("postal_code.")}
<img src="/icons/postal_code.svg" alt={placeType} />
<img src={iconsBaseUrl + "postal_code.svg"} alt={placeType} />
{:else if feature.id.startsWith("poi.")}
<img src="/icons/poi.svg" alt={placeType} />
<img src={iconsBaseUrl + "poi.svg"} alt={placeType} />
{:else}
<img src="/icons/area.svg" alt={placeType} />
<img src={iconsBaseUrl + "area.svg"} alt={placeType} />
{/if}

<span class="texts">
Expand Down
3 changes: 3 additions & 0 deletions src/lib/GeocodingControl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
export let fetchParameters: RequestInit = {};
export let iconsBaseUrl = "icons/";
export function focus() {
input.focus();
}
Expand Down Expand Up @@ -642,6 +644,7 @@
on:mouseenter={() => (selectedItemIndex = i)}
on:focus={() => pick(feature)}
{missingIconsCache}
{iconsBaseUrl}
/>
{/each}
</ul>
Expand Down
9 changes: 8 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export type ControlOptions = {
/**
* Geocoding API URL.
*
* @default MapTiler Geocoding API URL
* @default MapTiler Geocoding API URL.
*/
apiUrl?: string;

Expand All @@ -256,6 +256,13 @@ export type ControlOptions = {
*/
fetchParameters?: RequestInit;

/**
* Base URL for POI icons.
*
* @default "icons/"
*/
iconsBaseUrl?: string;

// TODO - missing but useful from maplibre-gl-geocoder
// popup // If true, a Popup will be added to the map when clicking on a marker using a default set of popup options. If the value is an object, the popup will be constructed using these options. If false, no popup will be added to the map. Requires that options.maplibregl also be set. (optional, default true)
// render // A function that specifies how the results should be rendered in the dropdown menu. This function should accepts a single Carmen GeoJSON object as input and return a string. Any HTML in the returned string will be rendered.
Expand Down

0 comments on commit 263cf36

Please sign in to comment.