react-leaflet#ZoomControl JavaScript Examples
The following examples show how to use
react-leaflet#ZoomControl.
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: CustomZoomControl.js From react-sample-projects with MIT License | 6 votes |
CustomZoomControl = () => {
const position = [28.7041, 77.1025];
return (
<Map center={position} zoom={13} zoomControl={false}>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<ZoomControl position="bottomright" zoomInText="?" zoomOutText="?️" />
</Map>
);
}
Example #2
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 #3
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 #4
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>
)
}
Example #5
Source File: MissionView.js From DMS_React with GNU Affero General Public License v3.0 | 4 votes |
MissionView = props => {
const dispatch = useDispatch();
const classes = useStyles();
const modalStyle = getModalStyle();
const [openMissionList, setOpenMissionList] = React.useState(false);
const [draggable, setDraggable] = React.useState(false);
const [create, setCreate] = React.useState(false);
const [currWaypointIndex, setCurrWaypointIndex] = React.useState(0);
const [action, setAction] = React.useState("create");
const openMissionDetail = useSelector(({ mission }) => mission.missionDetail);
const state = {
lat: 26.818123,
lng: 87.281345,
zoom: 17,
}
const initialMissionDetail = { name: '', radius: null, speed: null, home: '', destination: '', waypoints: [] };
const [missionDetail, setMissionDetail] = React.useState({ name: '', radius: null, speed: null, home: '', destination: '', waypoints: [] });
//to update the localstate by the missionDetails sourced from server
useEffect(() => {
if (openMissionDetail !== null) {
setMissionDetail(openMissionDetail);
setCreate(true);
}
}, [openMissionDetail]);
//close the modal after choosing the mission
const handleCloseMission = () => {
setAction('create');
setOpenMissionList(false);
};
//callback function to update position after the marker is dragged
const updatePosition = (event, index) => {
if (event.target !== undefined && event.target !== null) {
console.log(event.target.getLatLng());
const m = { ...missionDetail };
m.waypoints[index].lat = event.target.getLatLng().lat;
m.waypoints[index].lng = event.target.getLatLng().lng;
setMissionDetail(m);
}
}
//callback function for placing markers on the map and update the latitude and longitude of the waypoint
const handleClick = (event) => {
if (create) {
if (event.latlng !== undefined && event.latlng !== null) {
console.log(event.latlng);
const m = { ...missionDetail };
m.waypoints.push({
altitude: 0, radius: 0,
action: 'waypoint', lat: event.latlng.lat,
lng: event.latlng.lng
});
// console.log(mission, m);
setCurrWaypointIndex(m.waypoints.length - 1);
setMissionDetail(m);
}
}
}
//on create mission
const startMissionCreation = () => {
setDraggable(true);
setCreate(true);
setAction('create');
}
//callback function for click on confirm button
const createUpdateMission = () => {
console.log("Create Mission");
setCreate(false);
setDraggable(false);
setMissionDetail(initialMissionDetail);
dispatch(actions.createUpdateMission(missionDetail,action));
setAction('create');
}
//callback function for change in parameter of a particular waypoint provided by index
const onChange = (event, key) => {
console.log(event.target.value, key);
console.log(currWaypointIndex);
const m = {
...missionDetail,
};
m.waypoints[currWaypointIndex] = {
...m.waypoints[currWaypointIndex],
[key]: event.target.value
}
console.log(m.waypoints[currWaypointIndex]);
setMissionDetail(m);
}
//callback function for updating the change in details other than waypoints
const onChangeMission = (event, key) => {
const m = {
...missionDetail,
[key]: event.target.value
};
console.log("value of m", m)
setMissionDetail(m);
}
//callback function for click on a marker
const onClick = (index) => {
console.log("Marker Clicked", index);
setCurrWaypointIndex(index);
console.log(index, currWaypointIndex, "current waypoint")
}
//open mission list in a modal
const openMission = () => {
setOpenMissionList(true);
}
//set the mission details and waypoints to intial value of empty
const onCancel = () => {
setAction('create');
setCreate(false);
setDraggable(false);
setMissionDetail(initialMissionDetail);
}
const selectMission = (missionId) => {
setAction('edit');
console.log(missionId);
dispatch(actions.getMission(missionId));
setOpenMissionList(false);
}
return (
<Grid container className={classes.root}>
<Grid item xs={3}>
<MissionData data-test="missionData"
action={action} //touched
onCancel={onCancel}
onChangeMission={onChangeMission} //done
onChange={onChange} //done
createUpdateMission={createUpdateMission}
mission={missionDetail} //done
waypoint={missionDetail.waypoints[currWaypointIndex]}
onCreateMission={startMissionCreation}
openMission={openMission} //done
create={create} //done
/>
</Grid>
<Grid item xs={9}>
<Map
center={[state.lat, state.lng]}
zoom={state.zoom}
style={{ width: '100%', height: '100%' }}
zoomControl={false}
onClick={handleClick} data-test="mapComp"
>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{missionDetail !== null && missionDetail !== undefined ?
missionDetail.waypoints.map((miss, i, array) => {
// console.log(miss);
return (<span key={i}><Marker
draggable={draggable}
onDragend={(event) => updatePosition(event, i)}
position={[miss.lat, miss.lng]}
data-test="markerComp"
onClick={() => onClick(i)}>
<Popup minWidth={90}>
<span >
<span>{miss.action} </span>
<br />
<span>Alt: {miss.altitude}m</span><br />
</span>
</Popup>
</Marker>
{/* for lines between markers */}
{array[i - 1] ? <Polyline weight={1} positions={[
[array[i - 1].lat, array[i - 1].lng], [array[i].lat, array[i].lng],
]} color={'red'} /> : null}
}
</span>
)
}) : null
}
<ZoomControl position="topright" />
</Map>
</Grid>
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
className={classes.modal}
open={openMissionList}
onClose={handleCloseMission}
closeAfterTransition
data-test="modalComp"
>
<Fade in={openMissionList}>
<div className={classes.paper} style={modalStyle}>
<MissionList abort={handleCloseMission} select={selectMission} data-test="missionList" />
</div>
</Fade>
</Modal>
</Grid>)
}