Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
fcos-suite-map
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fab City OS Suite
fcos-suite-map
Commits
6f5aaf7d
Commit
6f5aaf7d
authored
3 years ago
by
Moritz Stückler
Browse files
Options
Downloads
Patches
Plain Diff
feat: always fit all pois into the map view
parent
300550ab
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/Map/Map.tsx
+14
-9
14 additions, 9 deletions
src/components/Map/Map.tsx
src/components/Map/MapViewController.tsx
+4
-5
4 additions, 5 deletions
src/components/Map/MapViewController.tsx
with
18 additions
and
14 deletions
src/components/Map/Map.tsx
+
14
−
9
View file @
6f5aaf7d
import
type
{
LatLngTuple
}
from
'
leaflet
'
;
import
{
divIcon
,
DivIconOptions
}
from
'
leaflet
'
;
import
React
,
{
use
Memo
}
from
'
react
'
;
import
React
,
{
use
Effect
,
useMemo
,
useState
}
from
'
react
'
;
import
{
MapContainer
,
Marker
,
TileLayer
}
from
'
react-leaflet
'
;
import
{
useStore
}
from
'
../../hooks
'
;
import
MapViewController
from
'
./MapViewController
'
;
...
...
@@ -30,22 +30,27 @@ export const Map: React.FC<Props> = ({ createMode }) => {
);
const
{
data
}
=
useFilteredPoiData
();
const
draftPoi
=
useStore
((
state
)
=>
state
.
draftPoi
);
const
[
mapBounds
,
setMapBounds
]
=
useState
<
Array
<
LatLngTuple
>>
([
DEFAULT_CENTER
]);
const
hoveredPoi
=
useStore
((
state
)
=>
state
.
hoveredPoi
);
const
setHoveredPoi
=
useStore
((
state
)
=>
state
.
setHoveredPoi
);
const
selectedPoi
=
useStore
((
state
)
=>
state
.
selectedPoi
);
const
history
=
useHistory
();
const
selectedLatlng
:
LatLngTuple
|
undefined
=
selectedPoi
?
[
selectedPoi
?.
lat
,
selectedPoi
?.
lng
]
:
undefined
;
useEffect
(()
=>
{
let
newBounds
=
[
DEFAULT_CENTER
];
if
(
selectedPoi
)
{
newBounds
=
[[
selectedPoi
.
lat
,
selectedPoi
.
lng
]
as
LatLngTuple
];
}
else
if
(
data
?.
length
)
{
newBounds
=
data
?.
map
((
poi
)
=>
[
poi
.
lat
,
poi
.
lng
]
as
LatLngTuple
)
||
[];
}
setMapBounds
(
newBounds
);
},
[
data
,
selectedPoi
]);
return
(
<
div
className
=
"relative h-full w-full z-0"
>
{
!
createMode
&&
<
MapLayerControl
/>
}
<
MapContainer
id
=
{
'
mapid
'
}
className
=
{
'
h-full w-full z-0
'
}
center
=
{
DEFAULT_CENTER
}
zoom
=
{
13
}
scrollWheelZoom
=
{
true
}
>
<
MapContainer
id
=
{
'
mapid
'
}
className
=
{
'
h-full w-full z-0
'
}
scrollWheelZoom
=
{
true
}
>
<
TileLayer
attribution
=
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url
=
"https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}"
...
...
@@ -55,7 +60,7 @@ export const Map: React.FC<Props> = ({ createMode }) => {
zoomOffset
=
{
-
1
}
maxZoom
=
{
18
}
/>
<
MapViewController
center
=
{
selectedLatlng
??
DEFAULT_CENTER
}
zoom
=
{
13
}
createPoiMode
=
{
createMode
}
/>
<
MapViewController
bounds
=
{
mapBounds
}
createPoiMode
=
{
createMode
}
/>
{
/* Single marker when creating a new POI */
}
{
!!
(
createMode
&&
draftPoi
)
&&
<
Marker
icon
=
{
greenLargeIcon
}
position
=
{
draftPoi
}
/>
}
{
/* Single marker when POI is selected */
}
...
...
This diff is collapsed.
Click to expand it.
src/components/Map/MapViewController.tsx
+
4
−
5
View file @
6f5aaf7d
...
...
@@ -4,12 +4,11 @@ import { useMap, useMapEvent } from 'react-leaflet';
import
{
useStore
}
from
'
../../hooks
'
;
interface
Props
{
center
:
LatLngTuple
;
zoom
:
number
;
bounds
:
Array
<
LatLngTuple
>
;
createPoiMode
?:
boolean
;
}
const
MapViewController
:
React
.
FC
<
Props
>
=
({
center
,
zoom
,
createPoiMode
})
=>
{
const
MapViewController
:
React
.
FC
<
Props
>
=
({
bounds
,
createPoiMode
})
=>
{
const
setDraftPoi
=
useStore
((
state
)
=>
state
.
setDraftPoi
);
const
map
=
useMap
();
...
...
@@ -20,8 +19,8 @@ const MapViewController: React.FC<Props> = ({ center, zoom, createPoiMode }) =>
});
useEffect
(()
=>
{
map
.
setView
(
center
,
zoom
);
},
[
center
,
zoom
]);
map
.
fitBounds
(
bounds
,
{
maxZoom
:
16
}
);
},
[
bounds
]);
return
<></>;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment