Skip to content

Commit

Permalink
improved map functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
midhun-aot committed Aug 30, 2023
1 parent 97241c5 commit 54300ba
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
14 changes: 7 additions & 7 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react-icons": "^4.6.0",
"react-leaflet": "^4.2.1",
"react-oidc-context": "^2.2.0",
"react-parcelmap-bc": "^1.0.4",
"react-parcelmap-bc": "^1.1.3",
"react-redux": "^8.0.2",
"react-router-dom": "^6.4.1",
"react-scripts": "5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/features/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Map from "../../../../node_modules/react-parcelmap-bc/dist/Map";

export default React.memo(() => {
const [data, setData] = useState();
const [location, setLocation] = useState([49, -123]);
const [location, setLocation] = useState([48.41974533439947, -123.36781242160622]);
const [readOnly, setReadOnly] = useState(false);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion map-package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-parcelmap-bc",
"version": "1.0.4",
"version": "1.0.8",
"private": false,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
Expand Down
33 changes: 21 additions & 12 deletions map-package/src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ const Map = (props) => {
let map;
let routeLayer, waypointsLayer;
const identifyBufferDistance = 4;
const [show, setShow] = useState(true);
const [show, setShow] = useState(false);
const [address, setAddress] = useState("");
const [location, setLocation] = useState([ 48.419, -123.37]);
const [location, setLocation] = useState([ 48.46762, -123.25458 ]);
const [zoom, setZoom] = useState(13);
const [searchTrue, setSerachTrue] = useState(false);
//const [info, setInfo] = useState({});
let info;

useEffect(() => {
if (props.initLocation.length > 0 && props.initLocation !== null && props.initLocation !== undefined) {
setZoom(13);
if (props.initLocation.length > 0 && props.initLocation !== null && props.initLocation !== undefined && ( location[0] !== props.initLocation[0] || location[1] !== props.initLocation[1] )) {

setSerachTrue(false);
setZoom(18);
setLocation(props.initLocation);
if(props.readOnly)
if(!props.readOnly)
{
setShow(false);
setShow(true);
}
}
}, [props]);
Expand Down Expand Up @@ -171,7 +174,7 @@ const Map = (props) => {
.setLatLng(e.latlng)
.setContent(
"Site ID:" +
feature.properties[targetLayer.topLineProperty] +
feature.properties[targetLayer.tsopLineProperty] +
"<br/>" +
"Lat: " +
feature.properties[targetLayer.latitude] +
Expand Down Expand Up @@ -295,11 +298,12 @@ const Map = (props) => {
getGeoCode(address).then((x) => {
if (x.features.length > 0) {
console.log(x.features[0].geometry.coordinates);
setZoom(50);
setZoom(20);
setLocation([
x.features[0].geometry.coordinates[1],
x.features[0].geometry.coordinates[0],
]);
setSerachTrue(true);
}
});
};
Expand Down Expand Up @@ -338,14 +342,19 @@ const Map = (props) => {

const RecenterAutomatically = () => {
const map = useMap();
useEffect(() => {
//map.setZoom(zoom);
useEffect(() => {
map.setZoom(zoom);

if(searchTrue)
{
map.setView(location,zoom);
}

map.fire("click", {
latlng: L.latLng(location),
});
}, [location]);

}, [map]);
return null;
};

Expand Down Expand Up @@ -426,7 +435,7 @@ const Map = (props) => {
)}
</div>
<br />
<MapContainer center={location} zoom={zoom} minZoom={10} scrollWheelZoom={false} maxBounds={maxBounds} bounds={maxBounds} maxBoundsViscosity={1.0}>
<MapContainer center={location} zoom={zoom} minZoom={10} maxBounds={maxBounds} bounds={maxBounds} maxBoundsViscosity={1.0} >
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
Expand Down

0 comments on commit 54300ba

Please sign in to comment.