Polygon Auto-Completion
HTML
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">
</script>
CSS
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
// Viggen ELINT plot example
function initMap() {
// Somewhere PG ish
var TL_Y = 28.5375;
var TL_X = 56.245;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: {lat: TL_Y, lng: TL_X},
mapTypeId: 'hybrid'
});
// Replace these examples below if you want your own plots..
// First emitter Freq: A PRF: 967
var elintLine1 = "NW: 28:32:15 056:14:42 SE: 26:13:30 058:13:06";
var elintFreq1 = "Freq: A PRF: 967";
plotOnMap(map, elintLine1, elintFreq1);
// Second emitter Freq: A PRF: 1763
var elintLine2 = "NW: 27:00:15 056:16:16 SE: 26:13:56 056:47:57";
var elintFreq2 = "Freq: A PRF: 1763";
plotOnMap(map, elintLine2, elintFreq2);
}
// Example: elintLine: "NW: 28:32:15 056:14:42 SE: 26:13:30 058:13:06"
function plotOnMap(map, elintLine, elintFreq){
// Parse output string from Viggen
var spaceBits = elintLine.split(' ');
var tl_lat = spaceBits[1].split(":");
var tl_lng = spaceBits[2].split(":");
var br_lat = spaceBits[4].split(":");
var br_lng = spaceBits[5].split(":");
var tl_y = ConvertDMSToDD(tl_lat[0], tl_lat[1], tl_lat[2], 'N');
var tl_x = ConvertDMSToDD(tl_lng[0], tl_lng[1], tl_lng[2], 'N');
var br_y = ConvertDMSToDD(br_lat[0], br_lat[1], br_lat[2], 'N');
var br_x = ConvertDMSToDD(br_lng[0], br_lng[1], br_lng[2], 'N');
var boxCoords = [
{lat: tl_y, lng: tl_x},
{lat: tl_y, lng: br_x},
{lat: br_y, lng: br_x},
{lat: br_y, lng: tl_x},
];
var elintBox = new google.maps.Polygon({
paths: boxCoords,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: '#FF0000',
fillOpacity: 0.35
});
elintBox.setMap(map);
var center_x = tl_x + ((br_x - tl_x) / 2);
var center_y = tl_y + ((br_y - tl_y) / 2);
var markerPos = new google.maps.LatLng(center_y, center_x);
var marker = new google.maps.Marker({
position: markerPos,
title: LookupFreq(elintFreq)
});
marker.setMap(map);
}
// DMS to...