I'm having a script to view polygons on google maps, but I want to change my polygon coordinates when I click on hyperlink. This the script which I'm using:
<!DOCTYPE html>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY_IS_HERE&libraries=geometry,places&ext=.js" ></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<div id="map_canvas" ></div>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map_canvas {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<script>
var map;
var bounds = new google.maps.LatLngBounds();
// your POLYGON
var polygonStr = "POLYGON (24.935955 42.32732, 24.943297 42.3268, 24.944593 42.322991, 24.94438 42.317172, 24.940584 42.317919, 24.936224 42.320232, 24.933244 42.322896, 24.927394 42.327057, 24.934312 42.328296, 24.93242 42.326795)";
function initialize() {
map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(42.156801, 24.749468),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
drawPoly(polygonStr);
map.fitBounds(bounds);
}
function drawPoly(multipolygonWKT) {
var polylines = [];
var toReturn = [];
multipolygonWKT = multipolygonWKT.replace("POLYGON ", "");
var formattedValues = multipolygonWKT.replace("))", "");
formattedValues = formattedValues.replace("((", "");
var linesCoords = formattedValues.split("), (");
for (i = 0; i < linesCoords.length; i++) {
polylines[i] = [];
var singleLine = linesCoords[i].split(", ");
for (j = 0; j < singleLine.length; j++) {
var coordinates = singleLine[j].split(" ");
var latlng = new google.maps.LatLng(parseFloat(coordinates[1]), parseFloat(coordinates[0]));
bounds.extend(latlng);
polylines[i].push(latlng);
}
}
toReturn.push(
new google.maps.Polygon({
map: map,
paths: polylines,
strokeColor: 'red',
strokeOpacity: 1,
strokeWeight: 2,
zIndex: 1
}));
return toReturn;
}
google.maps.event.addDomListener(window, "load", initialize);
</script>
</body>
</html>
When I try to call the file with a hyperlink with new coordinates nothing hapens for example 'file:///C:\Users\Desktop\MyfileName.html?q="POLYGON (here I put my new coordinates)" My idea is to change the coordinates which are in the script with the new one from my hyperlink. Is that possible? If it is possible how? Almost forgot to say that the file is on my computer and I want to open it from where it is.
EDIT: Here is some more info about what I want to do.I have created an attribute in the program which I use - Geomedia and I can create a hyperlink with coordinates of the drawn polygon. enter image description here I want when I click link to have the polygon opened in google maps. I tryed to make the hyperlink directly to google , but I couldn't find how to configure the url. I mean that for a single place there is "?q=" , but I didn't find how tell google it is a polygon , so I go ahead and start searching for alternative way. I found the script which is fine if I ad the coordinates manually it's working , but I need to make it work with the given hyperlink. I think that there should be a way to do it , but my javascript skills are very low so please be patient when trying to tell me how to do it :).
NEW EDIT: I'm totaly stuck with this and I realy need some help , bacause I tryed a lot of different examples and functions and still no progres. I'm doing something wrong and I can't get it to work. Probably I must give up since even here I can't get a helpfull soliution.At least if someone can give me a link to an example where I can see how is made and how to modify my file it will be nice.