update properties stuff
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useRef } from 'react';
|
||||||
import { MapContainer, TileLayer, Marker, Popup, useMapEvents } from 'react-leaflet';
|
import { MapContainer, TileLayer, Marker, Popup, useMapEvents } from 'react-leaflet';
|
||||||
import { Icon } from 'leaflet';
|
import { Icon } from 'leaflet';
|
||||||
import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
import toast from 'react-hot-toast';
|
|
||||||
|
|
||||||
// Fix for default markers in react-leaflet
|
// Fix for default markers in react-leaflet
|
||||||
delete Icon.Default.prototype._getIconUrl;
|
delete Icon.Default.prototype._getIconUrl;
|
||||||
@@ -14,7 +13,7 @@ Icon.Default.mergeOptions({
|
|||||||
|
|
||||||
// Component to handle map clicks and update marker position
|
// Component to handle map clicks and update marker position
|
||||||
function LocationMarker({ position, setPosition }) {
|
function LocationMarker({ position, setPosition }) {
|
||||||
const map = useMapEvents({
|
useMapEvents({
|
||||||
click(e) {
|
click(e) {
|
||||||
setPosition([e.latlng.lat, e.latlng.lng]);
|
setPosition([e.latlng.lat, e.latlng.lng]);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ const PropertyDetail = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchPropertyDetails();
|
fetchPropertyDetails();
|
||||||
}, [id]);
|
}, [id]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const fetchPropertyDetails = async () => {
|
const fetchPropertyDetails = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -180,6 +180,19 @@ const PropertyDetail = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate coordinates and provide fallbacks
|
||||||
|
const hasValidCoordinates = property &&
|
||||||
|
property.latitude !== undefined &&
|
||||||
|
property.longitude !== undefined &&
|
||||||
|
property.latitude !== null &&
|
||||||
|
property.longitude !== null &&
|
||||||
|
!isNaN(property.latitude) &&
|
||||||
|
!isNaN(property.longitude);
|
||||||
|
|
||||||
|
const mapCenter = hasValidCoordinates
|
||||||
|
? [property.latitude, property.longitude]
|
||||||
|
: [40.7128, -74.0060]; // Default to NYC
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6">
|
<div className="p-6">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
@@ -195,8 +208,11 @@ const PropertyDetail = () => {
|
|||||||
<h1 className="text-2xl font-bold text-gray-900">{property.name}</h1>
|
<h1 className="text-2xl font-bold text-gray-900">{property.name}</h1>
|
||||||
<p className="text-gray-600 flex items-center gap-1">
|
<p className="text-gray-600 flex items-center gap-1">
|
||||||
<MapPinIcon className="h-4 w-4" />
|
<MapPinIcon className="h-4 w-4" />
|
||||||
{property.address}
|
{property.address || 'No address specified'}
|
||||||
</p>
|
</p>
|
||||||
|
{!hasValidCoordinates && (
|
||||||
|
<p className="text-red-600 text-sm">⚠️ Property coordinates not set - using default location</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
@@ -214,8 +230,8 @@ const PropertyDetail = () => {
|
|||||||
<div className="card p-0 overflow-hidden">
|
<div className="card p-0 overflow-hidden">
|
||||||
<div style={{ height: '600px', width: '100%' }}>
|
<div style={{ height: '600px', width: '100%' }}>
|
||||||
<MapContainer
|
<MapContainer
|
||||||
center={[property.latitude, property.longitude]}
|
center={mapCenter}
|
||||||
zoom={19}
|
zoom={hasValidCoordinates ? 19 : 13}
|
||||||
style={{ height: '100%', width: '100%' }}
|
style={{ height: '100%', width: '100%' }}
|
||||||
>
|
>
|
||||||
<TileLayer
|
<TileLayer
|
||||||
@@ -223,9 +239,11 @@ const PropertyDetail = () => {
|
|||||||
url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
|
url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Marker position={[property.latitude, property.longitude]}>
|
{hasValidCoordinates && (
|
||||||
<Popup>{property.name}</Popup>
|
<Marker position={mapCenter}>
|
||||||
</Marker>
|
<Popup>{property.name}</Popup>
|
||||||
|
</Marker>
|
||||||
|
)}
|
||||||
|
|
||||||
{lawnSections.map((section) => (
|
{lawnSections.map((section) => (
|
||||||
<Polygon
|
<Polygon
|
||||||
|
|||||||
Reference in New Issue
Block a user