Add icons to search result markers

This commit is contained in:
2026-03-22 12:21:27 +04:00
parent af57e7fe57
commit 438bf0c31c
3 changed files with 264 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
import arrowLeft from 'feather-icons/dist/icons/arrow-left.svg?raw';
import activity from 'feather-icons/dist/icons/activity.svg?raw';
import arrowLeft from 'feather-icons/dist/icons/arrow-left.svg?raw';
import bookmark from 'feather-icons/dist/icons/bookmark.svg?raw';
import checkSquare from 'feather-icons/dist/icons/check-square.svg?raw';
import clock from 'feather-icons/dist/icons/clock.svg?raw';
@@ -20,53 +20,109 @@ import menu from 'feather-icons/dist/icons/menu.svg?raw';
import navigation from 'feather-icons/dist/icons/navigation.svg?raw';
import phone from 'feather-icons/dist/icons/phone.svg?raw';
import plus from 'feather-icons/dist/icons/plus.svg?raw';
import server from 'feather-icons/dist/icons/server.svg?raw';
import search from 'feather-icons/dist/icons/search.svg?raw';
import server from 'feather-icons/dist/icons/server.svg?raw';
import settings from 'feather-icons/dist/icons/settings.svg?raw';
import target from 'feather-icons/dist/icons/target.svg?raw';
import user from 'feather-icons/dist/icons/user.svg?raw';
import x from 'feather-icons/dist/icons/x.svg?raw';
import zap from 'feather-icons/dist/icons/zap.svg?raw';
import angelfish from '@waysidemapping/pinhead/dist/icons/angelfish.svg?raw';
import beachUmbrellaInGround from '@waysidemapping/pinhead/dist/icons/beach_umbrella_in_ground.svg?raw';
import beerMugWithFoam from '@waysidemapping/pinhead/dist/icons/beer_mug_with_foam.svg?raw';
import burgerAndDrinkCupWithStraw from '@waysidemapping/pinhead/dist/icons/burger_and_drink_cup_with_straw.svg?raw';
import camera from '@waysidemapping/pinhead/dist/icons/camera.svg?raw';
import classicalBuilding from '@waysidemapping/pinhead/dist/icons/classical_building.svg?raw';
import classicalBuildingWithDomeAndFlag from '@waysidemapping/pinhead/dist/icons/classical_building_with_dome_and_flag.svg?raw';
import classicalBuildingWithFlag from '@waysidemapping/pinhead/dist/icons/classical_building_with_flag.svg?raw';
import cleaver from '@waysidemapping/pinhead/dist/icons/cleaver.svg?raw';
import coffeeBean from '@waysidemapping/pinhead/dist/icons/coffee_bean.svg?raw';
import comedyMaskAndTragedyMask from '@waysidemapping/pinhead/dist/icons/comedy_mask_and_tragedy_mask.svg?raw';
import croissant from '@waysidemapping/pinhead/dist/icons/croissant.svg?raw';
import cupAndSaucer from '@waysidemapping/pinhead/dist/icons/cup_and_saucer.svg?raw';
import donut from '@waysidemapping/pinhead/dist/icons/donut.svg?raw';
import film from '@waysidemapping/pinhead/dist/icons/film.svg?raw';
import flagCheckered from '@waysidemapping/pinhead/dist/icons/flag_checkered.svg?raw';
import fort from '@waysidemapping/pinhead/dist/icons/fort.svg?raw';
import forkAndKnife from '@waysidemapping/pinhead/dist/icons/fork_and_knife.svg?raw';
import iceCreamOnCone from '@waysidemapping/pinhead/dist/icons/ice_cream_on_cone.svg?raw';
import memorialStoneWithInscription from '@waysidemapping/pinhead/dist/icons/memorial_stone_with_inscription.svg?raw';
import palace from '@waysidemapping/pinhead/dist/icons/palace.svg?raw';
import personCricketBattingAtCricketBall from '@waysidemapping/pinhead/dist/icons/person_cricket_batting_at_cricket_ball.svg?raw';
import personJockeyingRacehorse from '@waysidemapping/pinhead/dist/icons/person_jockeying_racehorse.svg?raw';
import personRunning from '@waysidemapping/pinhead/dist/icons/person_running.svg?raw';
import personSleepingInBed from '@waysidemapping/pinhead/dist/icons/person_sleeping_in_bed.svg?raw';
import personSwimmingInWater from '@waysidemapping/pinhead/dist/icons/person_swimming_in_water.svg?raw';
import personSwingingGolfClub from '@waysidemapping/pinhead/dist/icons/person_swinging_golf_club.svg?raw';
import roundStructureWithFlag from '@waysidemapping/pinhead/dist/icons/round_structure_with_flag.svg?raw';
import sailingShipInWater from '@waysidemapping/pinhead/dist/icons/sailing_ship_in_water.svg?raw';
import shoppingBasket from '@waysidemapping/pinhead/dist/icons/shopping_basket.svg?raw';
import shoppingCart from '@waysidemapping/pinhead/dist/icons/shopping_cart.svg?raw';
import wallHangingWithMountainsAndSun from '@waysidemapping/pinhead/dist/icons/wall_hanging_with_mountains_and_sun.svg?raw';
import wikipedia from '../icons/wikipedia.svg?raw';
const ICONS = {
'arrow-left': arrowLeft,
activity,
angelfish,
'arrow-left': arrowLeft,
'beach-umbrella-in-ground': beachUmbrellaInGround,
'beer-mug-with-foam': beerMugWithFoam,
bookmark,
'burger-and-drink-cup-with-straw': burgerAndDrinkCupWithStraw,
camera,
'check-square': checkSquare,
'classical-building': classicalBuilding,
'classical-building-with-dome-and-flag': classicalBuildingWithDomeAndFlag,
'classical-building-with-flag': classicalBuildingWithFlag,
cleaver,
clock,
'coffee-bean': coffeeBean,
'comedy-mask-and-tragedy-mask': comedyMaskAndTragedyMask,
croissant,
'cup-and-saucer': cupAndSaucer,
donut,
edit,
facebook,
film,
'flag-checkered': flagCheckered,
'fork-and-knife': forkAndKnife,
fort,
gift,
globe,
heart,
home,
'ice-cream-on-cone': iceCreamOnCone,
info,
instagram,
'fork-and-knife': forkAndKnife,
'log-in': logIn,
'log-out': logOut,
mail,
map,
'map-pin': mapPin,
'memorial-stone-with-inscription': memorialStoneWithInscription,
menu,
navigation,
palace,
'person-cricket-batting-at-cricket-ball': personCricketBattingAtCricketBall,
'person-jockeying-racehorse': personJockeyingRacehorse,
'person-running': personRunning,
'person-sleeping-in-bed': personSleepingInBed,
'person-swimming-in-water': personSwimmingInWater,
'person-swinging-golf-club': personSwingingGolfClub,
phone,
plus,
server,
'round-structure-with-flag': roundStructureWithFlag,
'sailing-ship-in-water': sailingShipInWater,
search,
server,
settings,
'shopping-basket': shoppingBasket,
'shopping-cart': shoppingCart,
target,
user,
'wall-hanging-with-mountains-and-sun': wallHangingWithMountainsAndSun,
wikipedia,
x,
zap,
@@ -76,6 +132,7 @@ const FILLED_ICONS = [
'fork-and-knife',
'wikipedia',
'cup-and-saucer',
'coffee-bean',
'shopping-basket',
'camera',
'person-sleeping-in-bed',

131
app/utils/osm-icons.js Normal file
View File

@@ -0,0 +1,131 @@
import { getIcon } from './icons';
// Rules for mapping OSM tags to icons.
// Rules are evaluated in order. The first rule where all specified tags match is used.
export const POI_ICON_RULES = [
// Specific Cuisine
{ tags: { cuisine: 'donut' }, icon: 'donut' },
{ tags: { cuisine: 'doughnut' }, icon: 'donut' },
{ tags: { cuisine: 'coffee_shop' }, icon: 'coffee-bean' },
{ tags: { cuisine: 'coffee' }, icon: 'coffee-bean' },
// General Amenity/Shop Types
{ tags: { amenity: 'ice_cream' }, icon: 'ice-cream-on-cone' },
{ tags: { cuisine: 'ice_cream' }, icon: 'ice-cream-on-cone' },
{ tags: { shop: 'ice_cream' }, icon: 'ice-cream-on-cone' },
{ tags: { amenity: 'cafe' }, icon: 'cup-and-saucer' },
{ tags: { amenity: 'restaurant' }, icon: 'fork-and-knife' },
{ tags: { amenity: 'fast_food' }, icon: 'burger-and-drink-cup-with-straw' },
{ tags: { amenity: 'pub' }, icon: 'beer-mug-with-foam' },
{ tags: { amenity: 'food_court' }, icon: 'fork-and-knife' },
{ tags: { shop: 'coffee' }, icon: 'coffee-bean' },
{ tags: { shop: 'tea' }, icon: 'coffee-bean' },
{ tags: { shop: 'pastry' }, icon: 'donut' }, // Pastry shops often have donuts
// Groceries
{ tags: { shop: 'supermarket' }, icon: 'shopping-cart' },
{ tags: { shop: 'convenience' }, icon: 'shopping-basket' },
{ tags: { shop: 'grocery' }, icon: 'shopping-basket' },
{ tags: { shop: 'greengrocer' }, icon: 'shopping-basket' },
{ tags: { shop: 'bakery' }, icon: 'croissant' },
{ tags: { shop: 'butcher' }, icon: 'cleaver' },
{ tags: { shop: 'deli' }, icon: 'shopping-basket' },
// Natural
{ tags: { natural: 'beach' }, icon: 'beach-umbrella-in-ground' },
// Tourism
{ tags: { tourism: 'museum' }, icon: 'classical-building' },
{ tags: { tourism: 'gallery' }, icon: 'wall-hanging-with-mountains-and-sun' },
{ tags: { tourism: 'aquarium' }, icon: 'angelfish' },
{ tags: { tourism: 'theme_park' }, icon: 'camera' },
{ tags: { tourism: 'attraction' }, icon: 'camera' },
{ tags: { tourism: 'viewpoint' }, icon: 'camera' },
{ tags: { tourism: 'zoo' }, icon: 'camera' },
{ tags: { tourism: 'artwork' }, icon: 'camera' },
{ tags: { amenity: 'cinema' }, icon: 'film' },
{ tags: { amenity: 'theatre' }, icon: 'camera' },
{ tags: { amenity: 'arts_centre' }, icon: 'comedy-mask-and-tragedy-mask' },
{ tags: { amenity: 'arts_center' }, icon: 'comedy-mask-and-tragedy-mask' },
// Historic
{ tags: { historic: 'fort' }, icon: 'fort' },
{ tags: { historic: 'castle' }, icon: 'palace' },
{ tags: { historic: 'building' }, icon: 'classical-building-with-flag' },
{ tags: { historic: 'archaeological_site' }, icon: 'camera' },
{ tags: { historic: 'memorial' }, icon: 'memorial-stone-with-inscription' },
{
tags: { historic: 'monument' },
icon: 'classical-building-with-dome-and-flag',
},
{ tags: { historic: 'ship' }, icon: 'sailing-ship-in-water' },
// Accommodation
{ tags: { tourism: 'hotel' }, icon: 'person-sleeping-in-bed' },
{ tags: { tourism: 'hostel' }, icon: 'person-sleeping-in-bed' },
{ tags: { tourism: 'motel' }, icon: 'person-sleeping-in-bed' },
{ tags: { tourism: 'guest_house' }, icon: 'person-sleeping-in-bed' },
// Sports / Motorsports
{ tags: { sport: 'motor' }, icon: 'flag-checkered' },
{ tags: { sport: 'karting' }, icon: 'flag-checkered' },
{ tags: { sport: 'motocross' }, icon: 'flag-checkered' },
{
tags: { sport: 'cricket' },
icon: 'person-cricket-batting-at-cricket-ball',
},
{ tags: { leisure: 'water_park' }, icon: 'person-swimming-in-water' },
{ tags: { sport: 'golf' }, icon: 'person-swinging-golf-club' },
{ tags: { leisure: 'golf_course' }, icon: 'person-swinging-golf-club' },
{ tags: { sport: 'horse_racing' }, icon: 'person-jockeying-racehorse' },
{ tags: { leisure: 'stadium' }, icon: 'round-structure-with-flag' },
{ tags: { sport: 'stadium' }, icon: 'round-structure-with-flag' },
{ tags: { leisure: 'sports_centre' }, icon: 'person-running' },
{ tags: { sport: 'fitness_centre' }, icon: 'person-running' },
];
/**
* Finds the appropriate icon name based on the place's OSM tags.
* @param {Object} tags - The OSM tags of the place.
* @returns {string|null} - The name of the icon or null if no match found.
*/
export function getIconNameForTags(tags) {
if (!tags) return null;
for (const rule of POI_ICON_RULES) {
let match = true;
for (const [key, expectedValue] of Object.entries(rule.tags)) {
const tagValue = tags[key];
if (!tagValue) {
match = false;
break;
}
// Check for exact match or if value is in a semicolon-separated list
// e.g. "donut;coffee_shop"
const values = tagValue.split(';').map((v) => v.trim());
if (!values.includes(expectedValue)) {
match = false;
break;
}
}
if (match) {
return rule.icon;
}
}
return null;
}
/**
* Returns the raw SVG string for the icon corresponding to the given tags.
* @param {Object} tags - The OSM tags.
* @returns {string|null} - The raw SVG string or null.
*/
export function getIconSvgForTags(tags) {
const iconName = getIconNameForTags(tags);
if (!iconName) return null;
return getIcon(iconName);
}