Various gmaps HTML pages and scripts.
4 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 <title>Rectangle Overlay</title>
7 <style type="text/css">
24 font-family: Arial, sans-serif;
28 <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
30 <script type="text/javascript">
38 * Called on the initial page load.
42 var qs = GetQueryString();
44 //Set map width if specified
45 if (!(typeof qs.width === "undefined")) {
46 document.getElementById('map').style.width=qs.width[0].concat("px");
47 //window.alert("width");
50 //Set map height if specified
51 if (!(typeof qs.height === "undefined")) {
52 document.getElementById('map').style.height=qs.height[0].concat("px");
53 //window.alert("height");
56 //Display help if expected parameters are not specified
57 if ( typeof qs.s === "undefined" || typeof qs.w === "undefined" || typeof qs.n === "undefined" || typeof qs.e === "undefined") {
58 document.getElementById('help').innerHTML='Pass the URI parameters as follow: \
60 <li>\'s\' for southernmost latitude.</li>\
61 <li>\'n\' for northernmost latitude.</li>\
62 <li>\'e\' for easternmost longitude.</li>\
63 <li>\'w\' for westernmost longitude.</li>\
64 <li>\'c\' Specify a <a href="http://www.w3schools.com/cssref/css_colornames.asp">color name</a> for your rectangles.</li>\
65 <li>\'width\' Map width in pixels, default is 1200.</li>\
66 <li>\'height\' Map heigh in pixels, default is 800.</li>\
68 You can specify any number of rectangles.<br />\
69 Map will be centered on the first rectangle.<br />\
70 Click <a href="rectangle-overlay-params.html?w=8.619000&n=50.134350&e=8.714110&s=50.091180&w=8.657227&n=50.119630&e=8.673706&s=50.108644&w=8.652547&n=50.109318&e=8.658400&s=50.105320&c=black&c=red&c=green">here</a> for an example.';
72 //Still display the map
73 map = new google.maps.Map(document.getElementById('map'), {
75 'center': new google.maps.LatLng(45,0),
76 'mapTypeId': google.maps.MapTypeId.ROADMAP
84 var latLngBounds = new google.maps.LatLngBounds(
85 new google.maps.LatLng(qs.s[0], qs.w[0]),
86 new google.maps.LatLng(qs.n[0], qs.e[0])
89 map = new google.maps.Map(document.getElementById('map'), {
91 'center': new google.maps.LatLng(latLngBounds.getCenter().lat(),latLngBounds.getCenter().lng()),
92 'mapTypeId': google.maps.MapTypeId.ROADMAP
96 //Create all our rectangles
97 rectangles = []; //Create rentangles array
98 for (var i = 0; i < qs.s.length; i++) {
99 rectangles.push(new google.maps.Rectangle({map: map,fillColor: (typeof qs.c === "undefined" || typeof qs.c[i] === "undefined"?'#666666':qs.c[i]) }));
100 //window.alert(qs.c[i]);
107 * Updates the Rectangle's bounds to resize its dimensions.
110 var qs = GetQueryString();
111 for (var i = 0; i < qs.s.length; i++) {
112 var latLngBounds = new google.maps.LatLngBounds(
113 new google.maps.LatLng(qs.s[i], qs.w[i]),
114 new google.maps.LatLng(qs.n[i], qs.e[i])
116 rectangles[i].setBounds(latLngBounds);
121 * This function is anonymous, is executed immediately and
122 * the return value is assigned to QueryString!
124 function GetQueryString() {
125 var query_string = {};
126 var query = window.location.search.substring(1);
127 var vars = query.split("&");
128 for (var i=0;i<vars.length;i++) {
129 var pair = vars[i].split("=");
130 // If first entry with this name
131 if ((typeof query_string[pair[0]] === "undefined") ) {
132 query_string[pair[0]] = pair[1];
133 var arr = [ query_string[pair[0]], pair[1] ];
134 query_string[pair[0]] = arr;
136 query_string[pair[0]].push(pair[1]);
142 // Register an event listener to fire when the page finishes loading.
143 google.maps.event.addDomListener(window, 'load', init);
147 <h2>Google maps rectangle overlay</h2>
148 <div id="help"><a href='rectangle-overlay-params.html'>help</a></div>