Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5a9479f
feat(Map): add OpenStreetMap (OSM) provider for dxMap
AlisherAmonulloev Jun 17, 2026
584cdb7
Fix Zoom and Center options
AlisherAmonulloev Jun 18, 2026
e6af365
Merge branch '26_1' into osm-research_26_1
AlisherAmonulloev Jun 18, 2026
8230702
Merge branch '26_1' into osm-research_26_1
AlisherAmonulloev Jun 19, 2026
bbfbae7
fix(map): prevent OSM center write-back loop under two-way bindings
AlisherAmonulloev Jun 21, 2026
6bf3526
fix(map): include OSM fallback route in autoAdjust bounds
AlisherAmonulloev Jun 21, 2026
33db8c6
fix(map): reject instead of hanging when OSM Leaflet assets fail to load
AlisherAmonulloev Jun 21, 2026
373de4f
refactor(map): rename OSM* public types to Osm* per acronym convention
AlisherAmonulloev Jun 21, 2026
4c8f29a
docs(map): drop outdated two-way center loop note in OSM story
AlisherAmonulloev Jun 21, 2026
6558afd
fix(map): reject OSM load when Leaflet missing after retry
AlisherAmonulloev Jun 21, 2026
034526b
test(map): remove unused MARKER_CLASS in OSM tests
AlisherAmonulloev Jun 21, 2026
bf16836
test(map): drop unused map var in OSM onClick test
AlisherAmonulloev Jun 21, 2026
5ce799b
test(map): use Osm* casing for OSM test helpers
AlisherAmonulloev Jun 21, 2026
b821633
docs(map): use Osm* casing for OSM story args type
AlisherAmonulloev Jun 21, 2026
e37246a
Merge branch '26_1' into osm-research_26_1
AlisherAmonulloev Jun 21, 2026
8ea66ee
refactor(map): polish OSM provider per code review
AlisherAmonulloev Jun 27, 2026
4e2be18
Merge branch '26_1' into osm-research_26_1
AlisherAmonulloev Jun 27, 2026
94d36d7
fix(map): load Leaflet via CSP-compliant <script>/<link> tags
AlisherAmonulloev Jun 27, 2026
0ee9f69
refactor(map): inline OSM provider callback types in dxMap options
AlisherAmonulloev Jun 27, 2026
c30c409
Merge branch '26_1' into osm-research_26_1
AlisherAmonulloev Jul 10, 2026
7fb655d
feat(map): support client-owned Leaflet in OSM provider
AlisherAmonulloev Jul 12, 2026
64e4d23
fix(map): narrow OSM tile server callback type
AlisherAmonulloev Jul 12, 2026
03d14a2
feat(map): support GeoJSON route results for OSM
AlisherAmonulloev Jul 12, 2026
67b00f5
fix(map): report missing OSM engine as an error
AlisherAmonulloev Jul 12, 2026
b8cc4d3
Fix OSM route callback contract
AlisherAmonulloev Jul 12, 2026
b00e277
Fix OSM Storybook provider attribution
AlisherAmonulloev Jul 13, 2026
c2fc823
Remove OSM tile server hot swapping
AlisherAmonulloev Jul 13, 2026
ec017c3
Narrow map providers with API keys
AlisherAmonulloev Jul 13, 2026
08f4c9a
Limit OSM declaration spellcheck suppressions
AlisherAmonulloev Jul 13, 2026
c3a7066
Fix OSM route rendering rejection
AlisherAmonulloev Jul 13, 2026
f97285d
Avoid caching failed OSM geocoding
AlisherAmonulloev Jul 13, 2026
8122c64
Reuse public OSM tile server types
AlisherAmonulloev Jul 13, 2026
e78c82c
Open initial OSM tooltips synchronously
AlisherAmonulloev Jul 13, 2026
9a2732d
Clean up OSM provider lint warnings
AlisherAmonulloev Jul 13, 2026
bcda20d
Use public Leaflet API for marker anchors
AlisherAmonulloev Jul 13, 2026
f8a218c
Preserve OSM tile layer on type update failure
AlisherAmonulloev Jul 13, 2026
416fb02
Use fixed geometry for OSM marker icons
AlisherAmonulloev Jul 13, 2026
ee3de0b
Use supported marker geometry in OSM Storybook
AlisherAmonulloev Jul 13, 2026
ec203d6
Scope Map declaration spellcheck override
AlisherAmonulloev Jul 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/react-storybook/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Leaflet is a client-owned dependency of the OSM map story. Applications may self-host these assets instead. -->
<link
rel="stylesheet"
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""
>
<script
src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""
></script>
4 changes: 4 additions & 0 deletions apps/react-storybook/stories/assets/images/osm-map-marker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
309 changes: 309 additions & 0 deletions apps/react-storybook/stories/map/OSMMap.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
import type { Meta, StoryObj } from '@storybook/react-webpack5';

import React, { useMemo, useRef } from 'react';
import Button from 'devextreme-react/button';
import Map, { type MapRef } from 'devextreme-react/map';
import type { OsmGetRouteFunction } from 'devextreme/ui/map';

// OpenStreetMap (OSM) provider for the DevExtreme Map — powered by client-owned Leaflet.
// This Storybook loads Leaflet in `.storybook/preview-head.html`, which demonstrates the global
// `window.L` setup. Applications can instead pass an imported API through `providerConfig.mapEngine`.
// The provider needs no API key of its own, but it does not bundle a tile/geocoding/routing service:
// you supply them via `providerConfig` (tileServer / geocodeLocation / getRoute).
//
// This story lets you switch between several commercial OSM-based tile providers and paste your
// own key for each (the "Tile provider" controls). The public OpenStreetMap tile service is
// best-effort and subject to the OSM Tile Usage Policy, so it is intentionally not offered here.
// Routing uses the public OSRM demo server (evaluation only).
//
// NOTE: there is deliberately no "self-hosted" option in this published Storybook — a localhost
// URL would point at the viewer's own machine, not a shared server. For the fully free, no-key,
// self-hosted setup (tiles + routing + geocoding), run the OSM_SelfHosted_Server Docker stack
// locally (see the devextreme-how-to-use-openstreetmap example repo).
const OSM_ATTR = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
const OPENMAPTILES_ATTR = '© <a href="https://openmaptiles.org/">OpenMapTiles</a>';
const STADIA_ATTR = `© <a href="https://stadiamaps.com/">Stadia Maps</a> ${OPENMAPTILES_ATTR} ${OSM_ATTR}`;
const STADIA_SATELLITE_ATTR = `${STADIA_ATTR} © CNES, Distribution Airbus DS, © Airbus DS, © PlanetObserver (Contains Copernicus Data)`;
const markerUrl = 'images/osm-map-marker.svg';

type TileProvider = 'MapTiler' | 'Thunderforest' | 'Stadia Maps';
type MapType = 'roadmap' | 'satellite' | 'hybrid';

interface ProviderKeys {
maptiler: string;
thunderforest: string;
stadia: string;
}

// Resolve a Leaflet tile-layer config for the selected provider and map type. Each provider is a
// function of the type so switching the "Map type" control re-resolves the tiles.
const buildTileServer = (provider: TileProvider, type: string, keys: ProviderKeys) => {
switch (provider) {
case 'Thunderforest': {
// Thunderforest has no satellite/aerial imagery, so the type slots map to distinct
// cartographic styles to demonstrate type switching.
const style = { roadmap: 'atlas', satellite: 'landscape', hybrid: 'outdoors' }[type] ?? 'atlas';
return {
url: `https://{s}.tile.thunderforest.com/${style}/{z}/{x}/{y}.png?apikey=${keys.thunderforest}`,
attribution: `Maps © <a href="https://www.thunderforest.com/">Thunderforest</a>, ${OSM_ATTR}`,
subdomains: 'abc',
maxZoom: 22,
};
}
case 'Stadia Maps': {
const style = { roadmap: 'alidade_smooth', satellite: 'alidade_satellite', hybrid: 'alidade_satellite' }[type] ?? 'alidade_smooth';
return {
url: `https://tiles.stadiamaps.com/tiles/${style}/{z}/{x}/{y}.png?api_key=${keys.stadia}`,
attribution: style === 'alidade_satellite' ? STADIA_SATELLITE_ATTR : STADIA_ATTR,
maxZoom: 20,
};
}
case 'MapTiler':
default: {
const style = { roadmap: 'streets-v2', satellite: 'satellite', hybrid: 'hybrid' }[type] ?? 'streets-v2';
return {
url: `https://api.maptiler.com/maps/${style}/{z}/{x}/{y}.png?key=${keys.maptiler}`,
attribution: `© <a href="https://www.maptiler.com/copyright/">MapTiler</a> ${OSM_ATTR}`,
maxZoom: 20,
};
}
}
};

// Real road routing via the public OSRM demo server (evaluation only; host your own in production).
const getRoute: OsmGetRouteFunction = ({ locations }) => {
const coords = locations.map((l) => `${l.lng},${l.lat}`).join(';');
return fetch(`https://router.project-osrm.org/route/v1/driving/${coords}?overview=full&geometries=geojson`)
.then((r) => r.json())
.then((res) => res.routes[0].geometry);
};

const markersData = [
{ location: { lat: 40.755833, lng: -73.986389 }, tooltip: { text: 'Times Square' } },
{ location: { lat: 40.7825, lng: -73.966111 }, tooltip: { text: 'Central Park' } },
{ location: { lat: 40.753889, lng: -73.981389 }, tooltip: { text: 'Fifth Avenue' } },
{ location: { lat: 40.705748, lng: -73.996299 }, tooltip: { text: 'Brooklyn Bridge' } },
];

const routeWaypoints: [number, number][] = [
[40.7825, -73.966111],
[40.755833, -73.986389],
[40.753889, -73.981389],
[40.705748, -73.996299],
];

const addedMarkerLocation = { lat: 40.748817, lng: -73.985428 };
const addedRouteWaypoints: [number, number][] = [
[40.758896, -73.98513],
[40.748817, -73.985428],
[40.74106, -73.989699],
];

const centers: Record<string, { lat: number; lng: number }> = {
'New York': { lat: 40.74, lng: -73.985 },
London: { lat: 51.5074, lng: -0.1278 },
Tokyo: { lat: 35.6762, lng: 139.7649 },
};

// Custom args (not native Map props) used to drive the story controls.
interface OsmStoryArgs {
tileProvider: TileProvider;
Comment thread
AlisherAmonulloev marked this conversation as resolved.
maptilerKey: string;
thunderforestKey: string;
stadiaKey: string;
type: MapType;
center: keyof typeof centers;
zoom: number;
controls: boolean;
disabled: boolean;
autoAdjust: boolean;
customMarkerIcons: boolean;
showMarkers: boolean;
showRoutes: boolean;
routeColor: string;
height: number;
width: string;
}

const meta: Meta<OsmStoryArgs> = {
title: 'Map/OSM Provider',
component: Map,
parameters: { layout: 'fullscreen' },
argTypes: {
// --- Tile provider ---
tileProvider: {
control: 'select',
options: ['MapTiler', 'Thunderforest', 'Stadia Maps'],
table: { category: 'Tile provider' },
description: 'Which commercial OSM tile provider to render.',
},
maptilerKey: {
control: 'text',
table: { category: 'Tile provider' },
description: 'Your MapTiler API key (https://cloud.maptiler.com). Required to see MapTiler tiles.',
},
thunderforestKey: {
control: 'text',
table: { category: 'Tile provider' },
description: 'Your Thunderforest API key (https://www.thunderforest.com).',
},
stadiaKey: {
control: 'text',
table: { category: 'Tile provider' },
description: 'Your Stadia Maps API key (https://stadiamaps.com).',
},
// --- Map ---
type: { control: 'select', options: ['roadmap', 'satellite', 'hybrid'], table: { category: 'Map' } },
center: {
control: 'select', options: Object.keys(centers), table: { category: 'Map' },
description: 'Initial center — the map can be freely panned afterwards.',
},
zoom: {
control: { type: 'number', min: 1, max: 19 }, table: { category: 'Map' },
description: 'Initial zoom — the map can be freely zoomed afterwards.',
},
controls: { control: 'boolean', table: { category: 'Map' } },
disabled: { control: 'boolean', table: { category: 'Map' } },
autoAdjust: {
control: 'boolean',
table: { category: 'Map' },
description: 'Auto-fit the viewport to the markers/routes.',
},
// --- Markers ---
showMarkers: { control: 'boolean', table: { category: 'Markers' } },
customMarkerIcons: {
control: 'boolean',
table: { category: 'Markers' },
description: 'Use a custom pushpin image instead of the default Leaflet marker.',
},
// --- Routes ---
showRoutes: { control: 'boolean', table: { category: 'Routes' } },
routeColor: {
control: 'select',
options: ['blue', 'green', 'red', 'purple', 'orange'],
table: { category: 'Routes' },
},
// --- Layout ---
height: { control: 'number', table: { category: 'Layout' } },
width: { control: 'text', table: { category: 'Layout' } },
},
};

export default meta;

type Story = StoryObj<OsmStoryArgs>;

const render: Story['render'] = (args) => {
const mapRef = useRef<MapRef>(null);
const {
tileProvider, maptilerKey, thunderforestKey, stadiaKey,
type, center, zoom, controls, disabled, autoAdjust,
customMarkerIcons, showMarkers, showRoutes, routeColor, height, width,
} = args;

// providerConfig identity changes only when the provider or a key changes, so the map provider
// is reinitialized then — not on every unrelated control change.
const providerConfig = useMemo(() => ({
tileServer: (t: string) => buildTileServer(tileProvider, t, {
maptiler: maptilerKey, thunderforest: thunderforestKey, stadia: stadiaKey,
}),
getRoute,
}), [tileProvider, maptilerKey, thunderforestKey, stadiaKey]);

const markers = useMemo(() => (showMarkers ? markersData : []), [showMarkers]);
const routes = useMemo(() => (showRoutes
? [{ weight: 6, opacity: 0.6, color: routeColor, locations: routeWaypoints }]
: []), [showRoutes, routeColor]);

const addMarker = () => {
mapRef.current?.instance().addMarker({
location: addedMarkerLocation,
tooltip: { text: 'Empire State Building' },
});
};

const addRoute = () => {
mapRef.current?.instance().addRoute({
weight: 6,
opacity: 0.7,
color: routeColor,
locations: addedRouteWaypoints,
});
};

const showAllTooltips = () => {
const map = mapRef.current?.instance();
const currentMarkers = map?.option('markers') ?? [];

map?.option('markers', currentMarkers.map((marker) => ({
...marker,
tooltip: {
...((marker.tooltip ?? {}) as Record<string, any>),
isShown: true,
},
})));
};

return (
<>
<div style={{ display: 'flex', gap: 8, padding: 12 }}>
<Button text="Add marker" onClick={addMarker} />
<Button text="Add route" onClick={addRoute} />
<Button text="Show all tooltips" onClick={showAllTooltips} />
</div>
<div style={{ position: 'relative', width }}>
<Map
ref={mapRef}
// Center, zoom, markers, and routes are uncontrolled so the user and the method buttons can
// mutate the Map instance. The key re-mounts it when the corresponding Storybook controls
// change, which re-seeds those defaults.
key={`${center}|${zoom}|${showMarkers}|${showRoutes}|${routeColor}`}
provider="osm"
providerConfig={providerConfig}
defaultCenter={centers[center]}
defaultZoom={zoom}
type={type}
height={height}
width="100%"
controls={controls}
disabled={disabled}
autoAdjust={autoAdjust}
markerIconSrc={customMarkerIcons ? markerUrl : undefined}
defaultMarkers={markers}
defaultRoutes={routes}
/>
{tileProvider === 'MapTiler' && (
<a
href="https://www.maptiler.com"
style={{ position: 'absolute', left: 10, bottom: 10, zIndex: 999 }}
>
<img src="https://api.maptiler.com/resources/logo.svg" alt="MapTiler logo" />
</a>
)}
</div>
</>
);
};

export const Default: Story = {
args: {
tileProvider: 'MapTiler',
// Paste your own keys here in the controls panel to see tiles render.
maptilerKey: 'YOUR_MAPTILER_KEY',
thunderforestKey: 'YOUR_THUNDERFOREST_KEY',
stadiaKey: 'YOUR_STADIA_KEY',
type: 'roadmap',
center: 'New York',
zoom: 12,
controls: true,
disabled: false,
autoAdjust: false,
showMarkers: true,
customMarkerIcons: true,
showRoutes: true,
routeColor: 'blue',
height: 520,
width: '100%',
},
render,
};
8 changes: 4 additions & 4 deletions packages/devextreme-angular/src/ui/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@angular/core';


import type { ClickEvent, DisposingEvent, InitializedEvent, MarkerAddedEvent, MarkerRemovedEvent, OptionChangedEvent, ReadyEvent, RouteAddedEvent, RouteRemovedEvent, MapProvider, RouteMode, MapType } from 'devextreme/ui/map';
import type { ClickEvent, DisposingEvent, InitializedEvent, MarkerAddedEvent, MarkerRemovedEvent, OptionChangedEvent, ReadyEvent, RouteAddedEvent, RouteRemovedEvent, MapProvider, OsmGetRouteParams, OsmTileServer, RouteMode, MapType } from 'devextreme/ui/map';

import DxMap from 'devextreme/ui/map';

Expand Down Expand Up @@ -302,10 +302,10 @@ export class DxMapComponent extends DxComponent implements OnDestroy, OnChanges,

*/
@Input()
get providerConfig(): { mapId?: string, useAdvancedMarkers?: boolean } {
get providerConfig(): { geocodeLocation?: ((query: string) => any) | undefined, getRoute?: ((params: OsmGetRouteParams) => any) | undefined, mapEngine?: Record<string, any> | undefined, mapId?: string, tileServer?: OsmTileServer | undefined, useAdvancedMarkers?: boolean } {
return this._getOption('providerConfig');
}
set providerConfig(value: { mapId?: string, useAdvancedMarkers?: boolean }) {
set providerConfig(value: { geocodeLocation?: ((query: string) => any) | undefined, getRoute?: ((params: OsmGetRouteParams) => any) | undefined, mapEngine?: Record<string, any> | undefined, mapId?: string, tileServer?: OsmTileServer | undefined, useAdvancedMarkers?: boolean }) {
this._setOption('providerConfig', value);
}

Expand Down Expand Up @@ -582,7 +582,7 @@ export class DxMapComponent extends DxComponent implements OnDestroy, OnChanges,
* This member supports the internal infrastructure and is not intended to be used directly from your code.

*/
@Output() providerConfigChange: EventEmitter<{ mapId?: string, useAdvancedMarkers?: boolean }>;
@Output() providerConfigChange: EventEmitter<{ geocodeLocation?: ((query: string) => any) | undefined, getRoute?: ((params: OsmGetRouteParams) => any) | undefined, mapEngine?: Record<string, any> | undefined, mapId?: string, tileServer?: OsmTileServer | undefined, useAdvancedMarkers?: boolean }>;

/**

Expand Down
Loading
Loading