hooks#useMapServices JavaScript Examples
The following examples show how to use
hooks#useMapServices.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Map.js From coronavirus-map-dashboard with MIT License | 5 votes |
Map = ( props ) => {
const { children, className, defaultBaseMap = 'OpenStreetMap', mapEffect, ...rest } = props;
const mapRef = useRef();
useConfigureLeaflet();
useRefEffect({
ref: mapRef,
effect: mapEffect,
});
const services = useMapServices({
names: [defaultBaseMap],
});
const basemap = services.find(( service ) => service.name === defaultBaseMap );
let mapClassName = `map`;
if ( className ) {
mapClassName = `${mapClassName} ${className}`;
}
if ( !isDomAvailable()) {
return (
<div className={mapClassName}>
<p className="map-loading">Loading map...</p>
</div>
);
}
const mapSettings = {
className: 'map-base',
zoomControl: false,
...rest,
};
return (
<div className={mapClassName}>
<BaseMap ref={mapRef} {...mapSettings}>
{ children }
{ basemap && <TileLayer {...basemap} /> }
<ZoomControl position="bottomright" />
</BaseMap>
</div>
);
}
Example #2
Source File: Map.js From my-coronavirus-map with MIT License | 5 votes |
Map = ( props ) => {
const { children, className, defaultBaseMap = 'OpenStreetMap', mapEffect, ...rest } = props;
const mapRef = useRef();
useConfigureLeaflet();
useRefEffect({
ref: mapRef,
effect: mapEffect,
});
const services = useMapServices({
names: ['OpenStreetMap'],
});
const basemap = services.find(( service ) => service.name === defaultBaseMap );
let mapClassName = `map`;
if ( className ) {
mapClassName = `${mapClassName} ${className}`;
}
if ( !isDomAvailable()) {
return (
<div className={mapClassName}>
<p className="map-loading">Loading map...</p>
</div>
);
}
const mapSettings = {
className: 'map-base',
zoomControl: false,
...rest,
};
return (
<div className={mapClassName}>
<BaseMap ref={mapRef} {...mapSettings}>
{ children }
{ basemap && <TileLayer {...basemap} /> }
<ZoomControl position="bottomright" />
</BaseMap>
</div>
);
}
Example #3
Source File: Map.js From gatsby-map with MIT License | 5 votes |
Map = props => {
const {
children,
className,
defaultBaseMap = 'OpenStreetMap',
mapEffect,
...rest
} = props
const mapRef = useRef()
useConfigureLeaflet()
useRefEffect({
ref: mapRef,
effect: mapEffect
})
const services = useMapServices({
names: ['OpenStreetMap']
})
const basemap = services.find(service => service.name === defaultBaseMap)
let mapClassName = `map`
if (className) {
mapClassName = `${mapClassName} ${className}`
}
if (!isDomAvailable()) {
return (
<div className={mapClassName}>
<p className="map-loading">Laddar karta...</p>
</div>
)
}
const mapSettings = {
className: 'map-base',
zoomControl: false,
attributionControl: true,
...rest
}
return (
<div className={mapClassName}>
<BaseMap ref={mapRef} {...mapSettings}>
{children}
{basemap && <TileLayer {...basemap} />}
<ZoomControl position="topright" />
</BaseMap>
</div>
)
}