File size: 3,659 Bytes
f0bebf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
```html
<!DOCTYPE html>
<html>
<head>
    <title>Tree Counter</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        .container {
            width: 80%;
            margin: 40px auto;
            text-align: center;
        }
        .button {
            background-color: #4CAF50;
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        .button:hover {
            background-color: #3e8e41;
        }
        #google-earth-map {
            height: 500px;
            width: 100%;
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Tree Counter</h1>
        <button class="button" id="upload-button">Upload Image</button>
        <button class="button" id="crop-button" style="display: none;">Crop Image</button>
        <div id="result"></div>
        <div id="google-earth-map"></div>
    </div>

    <script>
        const uploadButton = document.getElementById('upload-button');
        const cropButton = document.getElementById('crop-button');
        const resultDiv = document.getElementById('result');
        const googleEarthMap = document.getElementById('google-earth-map');

        uploadButton.addEventListener('click', (e) => {
            e.preventDefault();
            const input = document.createElement('input');
            input.type = 'file';
            input.accept = 'image/*';
            input.onchange = (e) => {
                const image = e.target.files[0];
                const formData = new FormData();
                formData.append('image', image);
                fetch('/upload_image', {
                    method: 'POST',
                    body: formData
                })
                .then((response) => response.json())
                .then((data) => {
                    if (data.message.includes('too large')) {
                        cropButton.style.display = 'inline-block';
                    } else {
                        resultDiv.innerText = data.message;
                    }
                });
            };
            input.click();
        });

        cropButton.addEventListener('click', (e) => {
            e.preventDefault();
            const input = document.createElement('input');
            input.type = 'file';
            input.accept = 'image/*';
            input.onchange = (e) => {
                const image = e.target.files[0];
                const formData = new FormData();
                formData.append('image', image);
                fetch('/crop_image', {
                    method: 'POST',
                    body: formData
                })
                .then((response) => response.json())
                .then((data) => {
                    resultDiv.innerText = data.message;
                });
            };
            input.click();
        });

        // Initialize Google Earth map
        const googleEarthOptions = {
            zoom: 4,
            center: { lat: 37.7749, lng: -122.4194 },
            mapTypeId: 'satellite'
        };
        const googleEarthMapInstance = new google.maps.Map(googleEarthMap, googleEarthOptions);

        // Add event listener to Google Earth map
        googleEarthMapInstance.addListener('click', (e) => {
            const lat = e.latLng.lat();
            const lng = e.latLng.lng();
            console.log(`Clicked at (${lat}, ${lng})`);
        });
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
</body>
</html>
```