JSFiddle - React, Tailwind, and code Playground
by dizzled
HTML
<!DOCTYPE html>
<html>
<head>
<title>Drawing Tools</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<!-- jsFiddle will insert css and js -->
</head>
<body>
<button id="delete-button">Delete Selected Shape</button>
<button id="export">Export</button>
<div id="geoJson"></div>
<div id="map"></div><div id="map2"></div>
<!-- Async script executes immediately and must be after any DOM elements used in callback. -->
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBeSqpJ3oeR0cfinYr8QO1iUFaHEOfnihU&callback=initMap&libraries=drawing&v=weekly"
async
></script>
</body>
</html>
CSS
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 400px;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
let drawingManager;
let selectedShape;
let all_overlays = [];
let map_data = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-112.62436423706745, 42.39568072923476],
[-112.97592673706745, 35.35837559772935],
[-102.42905173706745, 34.05790067272247],
[-112.62436423706745, 42.39568072923476]
],
[
[-108.05405173706745, 35.71597438342231],
[-111.56967673706745, 35.71597438342231],
[-111.83334861206745, 39.20310776569922],
[-108.05405173706745, 35.71597438342231]
]
]
},
"properties": {}
}, {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-100.58334861206745, 41.282560566872476],
[-99.70444236206745, 33.54666732208101],
[-92.84897361206745, 34.85506648681631],
[-100.58334861206745, 41.282560566872476]
],
[
[-96.62827048706745, 35.64458221459782],
[-98.21030173706745, 35.64458221459782],
[-98.12241111206745, 37.5495930752235],
[-96.62827048706745, 35.64458221459782]
]
]
},
"properties": {}
}, {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-107.70248923706745, 42.33073939615952],
[-104.18686423706745, 38.31214456177075],
[-101.90170798706745, 41.80879370932932],
[-107.70248923706745, 42.33073939615952]
]
...