UNPKG

@pnp/spfx-controls-react

Version:

Reusable React controls for SharePoint Framework solutions

163 lines 6.16 kB
"use strict"; // Example usage of WorldMapControl with search functionality Object.defineProperty(exports, "__esModule", { value: true }); exports.ExampleWithDemoMap = exports.ExampleWithCustomKeyAndStyle = exports.ExampleWithCustomMapKey = exports.ExampleWithTopRightSearch = exports.ExampleWithoutSearch = exports.ExampleWithCustomSearch = exports.ExampleWithSearch = void 0; var tslib_1 = require("tslib"); var WorldMapControl_1 = require("./WorldMapControl"); var react_1 = tslib_1.__importDefault(require("react")); var ExampleWithSearch = function () { var mapData = [ { id: '1', name: 'New York', imageUrl: 'https://example.com/ny.jpg', link: 'https://example.com/ny', coordinates: [-74.006, 40.7128] }, { id: '2', name: 'London', imageUrl: 'https://example.com/london.jpg', link: 'https://example.com/london', coordinates: [-0.1276, 51.5074] }, { id: '3', name: 'Tokyo', imageUrl: 'https://example.com/tokyo.jpg', link: 'https://example.com/tokyo', coordinates: [139.6917, 35.6895] } ]; var handleLocationClick = function (location) { console.log('Location clicked:', location.name); }; var handleSearchChange = function (searchTerm, filteredData) { console.log('Search term:', searchTerm); console.log('Filtered results:', filteredData); if (!searchTerm) { console.log('Search cleared - map reset to initial view'); } }; return (react_1.default.createElement(WorldMapControl_1.MaplibreWorldMap, { data: mapData, onClick: handleLocationClick, title: "World Locations with Search", search: { enabled: true, placeholder: "Search for a city...", zoomLevel: 10, onSearchChange: handleSearchChange, searchField: 'name', // Can also be a function: (item) => item.name position: { top: '10px', left: '10px' } }, style: { width: '100%', height: '500px' } })); }; exports.ExampleWithSearch = ExampleWithSearch; // Example with custom positioning (top-right) var ExampleWithTopRightSearch = function () { var mapData = [ { id: '1', name: 'New York', imageUrl: 'https://example.com/ny.jpg', link: 'https://example.com/ny', coordinates: [-74.006, 40.7128] } ]; return (react_1.default.createElement(WorldMapControl_1.MaplibreWorldMap, { data: mapData, search: { enabled: true, placeholder: "Search...", position: { top: '10px', right: '10px' } } })); }; exports.ExampleWithTopRightSearch = ExampleWithTopRightSearch; // Example with custom MapTiler API key var ExampleWithCustomMapKey = function () { var mapData = [ { id: '1', name: 'New York', imageUrl: 'https://example.com/ny.jpg', link: 'https://example.com/ny', coordinates: [-74.006, 40.7128] } ]; return (react_1.default.createElement(WorldMapControl_1.MaplibreWorldMap, { data: mapData, mapKey: "your-maptiler-api-key-here" // Uses streets style by default , search: { enabled: true, placeholder: "Search with custom map..." } })); }; exports.ExampleWithCustomMapKey = ExampleWithCustomMapKey; // Example with custom MapTiler API key and specific style var ExampleWithCustomKeyAndStyle = function () { var mapData = [ { id: '1', name: 'New York', imageUrl: 'https://example.com/ny.jpg', link: 'https://example.com/ny', coordinates: [-74.006, 40.7128] } ]; return (react_1.default.createElement(WorldMapControl_1.MaplibreWorldMap, { data: mapData, mapKey: "your-maptiler-api-key-here", mapStyleUrl: "https://api.maptiler.com/maps/satellite/style.json" // Will automatically append the key , search: { enabled: true } })); }; exports.ExampleWithCustomKeyAndStyle = ExampleWithCustomKeyAndStyle; // Example using demo map (no key required) var ExampleWithDemoMap = function () { var mapData = [ { id: '1', name: 'New York', imageUrl: 'https://example.com/ny.jpg', link: 'https://example.com/ny', coordinates: [-74.006, 40.7128] } ]; return (react_1.default.createElement(WorldMapControl_1.MaplibreWorldMap, { data: mapData, // No mapKey or mapStyleUrl provided - uses free demo map search: { enabled: true, placeholder: "Search demo map..." } })); }; exports.ExampleWithDemoMap = ExampleWithDemoMap; // Example with search disabled var ExampleWithoutSearch = function () { var mapData = [ // ... your data ]; return (react_1.default.createElement(WorldMapControl_1.MaplibreWorldMap, { data: mapData, search: { enabled: false // Disables the search feature } })); }; exports.ExampleWithoutSearch = ExampleWithoutSearch; // Example with custom search field var ExampleWithCustomSearch = function () { var mapData = [ { id: '1', name: 'New York', imageUrl: 'https://example.com/ny.jpg', link: 'https://example.com/ny', coordinates: [-74.006, 40.7128] } ]; return (react_1.default.createElement(WorldMapControl_1.MaplibreWorldMap, { data: mapData, search: { enabled: true, placeholder: "Search by location or description...", zoomLevel: 8, // Custom search function that searches across multiple fields searchField: function (item) { return "".concat(item.name, " ").concat(item.link); }, } })); }; exports.ExampleWithCustomSearch = ExampleWithCustomSearch; //# sourceMappingURL=examples.js.map