-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat project details map component #926
Merged
spwoodcock
merged 40 commits into
hotosm:development
from
NSUWAL123:feat-project-details-map-component
Oct 20, 2023
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
a54b024
feat (projectDetails): map - for small screen, full screen map visibl…
NSUWAL123 7f8af19
feat (projectDetails): map - footer added to the map
NSUWAL123 786cc4e
fix (MobileFooter) - border top added
NSUWAL123 651644e
feat (bottomSheet): bottomSheet component made for mobile device
NSUWAL123 70f1dc3
feat (projectDetails): activities - bottomSheet made for activities
NSUWAL123 f545429
feat (projectDetails): project info - added bottom sheet for project …
NSUWAL123 e8008f7
feat (projectDetails) - fmtm logo and back button added for small screen
NSUWAL123 3606915
fix (Accordion): interface added to props
NSUWAL123 bc65a24
feat/fix (projectDetails): projectDetails component projectOption sec…
NSUWAL123 c17cb6d
fix (projectDetails): bottomSheet - converted css to tailwind css, co…
NSUWAL123 807627c
fix (projectDetails): map - mapcontrols button gap reduced for small …
NSUWAL123 d7b59b8
fix (bottomSheet): fmtm logo move bottom sheet expand/contract
NSUWAL123 8c252c9
Merge branch 'development' of https://github.com/hotosm/fmtm into fix…
NSUWAL123 9577d4c
fix (projectDetails): margins/paddings updated for mobile view
NSUWAL123 6610dd9
feat(icons): added new icon
NSUWAL123 a070823
fix (console): console logs removed
NSUWAL123 6855f5e
fix (project details): displaying map using map component
NSUWAL123 3a20b59
fix (project details): MapControl - component to display map controls
NSUWAL123 d299983
fix (projectDetails): UI updated for new project details map
NSUWAL123 416e224
fix (newProjectDetails): map - vectorLayer added for buildings
NSUWAL123 0745baa
fix (vectorLayer): map onClick returns feature as a second argument
NSUWAL123 5e87ef7
fix (newProjectDetials): changes in creating geojson
NSUWAL123 4ac8b20
fix (newProjectDetail): map - chloropeth and styles added
NSUWAL123 a77e1cc
merge conflict resolved
NSUWAL123 fa307ce
fix *(newProjectDetails): map - defaultStyles imported, naming changes
NSUWAL123 2185666
feat (newProjectDetails): map - setting layer style according to the …
NSUWAL123 6ad5364
feat (vectorLayer/newProjectDetials): layerProperties props added to …
NSUWAL123 0c9d22f
fix (newProjectDetails): map - buildingStyles added
NSUWAL123 96e5f24
fix (mobileFooter/bottomSheet): zIndex adjusted
NSUWAL123 3cce23c
(newProjectDetails): mapLegends added for small screen
NSUWAL123 35f2b84
fix (accordion): border width 0 on accordion collapse
NSUWAL123 34f6287
fix (mapLegend): header not shown medium & large devices
NSUWAL123 55a3fcc
fix (newProjectDetails): mapLegend - mapLegend added to devices bigge…
NSUWAL123 686d868
fix (newProjectDetails): mapControlComponent - hover effects added to…
NSUWAL123 7c8f20a
fix (newProjectDetials): imports and states cleanup
NSUWAL123 bbeb137
fix (newProjectDetials): added taskBoundries length as a dependency t…
NSUWAL123 6d5e6af
fix (newProjectDetails): mapLegend - default legend collapsed
NSUWAL123 300e26a
Merge branch 'development' of https://github.com/hotosm/fmtm into fea…
NSUWAL123 5d9c6ed
fix (projectDetails): route - projectDetails route updated
NSUWAL123 9ee31e7
fix (projectDetails): taskSectionPopup - zIndex adjusted
NSUWAL123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/frontend/src/components/ProjectDetails/MapControlComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import AssetModules from '../../shared/AssetModules'; | ||
import { transform } from 'ol/proj'; | ||
import * as ol from 'ol'; | ||
import { Point } from 'ol/geom'; | ||
import Vector from 'ol/layer/Vector'; | ||
import VectorSource from 'ol/source/Vector'; | ||
import { Style } from 'ol/style'; | ||
import { Icon } from 'ol/style'; | ||
import LocationImage from '../../assets/images/location.png'; | ||
import VectorLayer from 'ol/layer/Vector'; | ||
|
||
const MapControlComponent = ({ map }) => { | ||
const btnList = [ | ||
{ | ||
id: 'add', | ||
icon: <AssetModules.AddIcon />, | ||
}, | ||
{ | ||
id: 'minus', | ||
icon: <AssetModules.RemoveIcon />, | ||
}, | ||
{ | ||
id: 'currentLocation', | ||
icon: <AssetModules.MyLocationIcon />, | ||
}, | ||
{ | ||
id: 'taskBoundries', | ||
icon: <AssetModules.CropFreeIcon />, | ||
}, | ||
]; | ||
const [toggleCurrentLoc, setToggleCurrentLoc] = useState(false); | ||
const [currentLocLayer, setCurrentLocLayer] = useState(null); | ||
useEffect(() => { | ||
if (!map) return; | ||
if (!currentLocLayer) return; | ||
map.addLayer(currentLocLayer); | ||
map.getView().fit(currentLocLayer.getSource().getExtent(), { | ||
maxZoom: 18, | ||
duration: 500, | ||
}); | ||
return () => { | ||
map.removeLayer(currentLocLayer); | ||
}; | ||
}, [map, currentLocLayer]); | ||
const handleOnClick = (btnId) => { | ||
if (btnId === 'add') { | ||
const actualZoom = map.getView().getZoom(); | ||
map.getView().setZoom(actualZoom + 1); | ||
} else if (btnId === 'minus') { | ||
const actualZoom = map.getView().getZoom(); | ||
map.getView().setZoom(actualZoom - 1); | ||
} else if (btnId === 'currentLocation') { | ||
setToggleCurrentLoc(!toggleCurrentLoc); | ||
const sourceProjection = 'EPSG:4326'; // The current projection of the coordinates | ||
const targetProjection = 'EPSG:3857'; // The desired projection | ||
var markerStyle = new Style({ | ||
image: new Icon({ | ||
src: LocationImage, // Path to your marker icon image | ||
anchor: [0.5, 1], // Anchor point of the marker icon (center bottom) | ||
scale: 2, // Scale factor for the marker icon | ||
}), | ||
}); | ||
if ('geolocation' in navigator) { | ||
if (!toggleCurrentLoc) { | ||
navigator.geolocation.getCurrentPosition((position) => { | ||
const lat = position.coords.latitude; | ||
const lng = position.coords.longitude; | ||
const convertedCoordinates = transform([lng, lat], sourceProjection, targetProjection); | ||
const positionFeature = new ol.Feature(new Point(convertedCoordinates)); | ||
const positionLayer = new Vector({ | ||
source: new VectorSource({ | ||
features: [positionFeature], | ||
}), | ||
}); | ||
positionFeature.setStyle(markerStyle); | ||
setCurrentLocLayer(positionLayer); | ||
}); | ||
} else { | ||
setCurrentLocLayer(null); | ||
} | ||
} | ||
} else if (btnId === 'taskBoundries') { | ||
const layers = map.getAllLayers(); | ||
let extent; | ||
layers.map((layer) => { | ||
if (layer instanceof VectorLayer) { | ||
const layerName = layer.getProperties().name; | ||
if (layerName === 'project-area') { | ||
extent = layer.getSource().getExtent(); | ||
} | ||
} | ||
}); | ||
map.getView().fit(extent, { | ||
padding: [10, 10, 10, 10], | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="fmtm-absolute fmtm-top-[20px] fmtm-right-5 fmtm-z-[99] fmtm-flex fmtm-flex-col fmtm-gap-4"> | ||
{btnList.map((btn) => ( | ||
<div key={btn.id}> | ||
<div | ||
className="fmtm-bg-white fmtm-rounded-full fmtm-p-2 hover:fmtm-bg-gray-100 fmtm-cursor-pointer fmtm-duration-300" | ||
onClick={() => handleOnClick(btn.id)} | ||
> | ||
{btn.icon} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MapControlComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a seperate dependent added onto the isolated mapcomponent @NSUWAL123 please replace this logic on other PR not this and make it pass through props instead of using it in this component. and dont use new dependncy library like react-router-dom inside any mapcomponent folder map.