Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Google Map in jQuery dialog box</title>
- <script src="http://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" type="text/javascript"></script>
- <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/ui-darkness/jquery-ui.css" />
- <style>
- .gBubble
- {
- color:black;
- font-family:Tahoma, Geneva, sans-serif;
- font-size:12px;
- }
- </style>
- <script>
- //container to hold gmap object
- var map;
- $(document).ready(function()
- {
- //define the map dialog box
- $( "#map_container" ).dialog({
- autoOpen:false,
- modal: true,
- width: 555,
- height: 400,
- resizeStop: function(event, ui) {google.maps.event.trigger(map, 'resize') },
- open: function(event, ui) {
- //get the encoded form data from the bound information, and deserialize into a hashmap/object
- formData = QueryStringToHash($(this).data('formData'));
- //plot a point on the map with the new data
- plotPoint(formData.lat,formData.lng,formData.title,'<span class="gBubble"><b>'+formData.title+'</b><br>'+formData.desc+'</span>');
- //resize the map to fix weird grey block bug
- google.maps.event.trigger(map, 'resize');
- //set center of the map
- map.setCenter(new google.maps.LatLng(formData.lat,formData.lng), 10);
- }
- });
- //runs when the show map button is clicked
- $( "#showMap" ).click(function() {
- //serialize the data in the parent form of the button and include it for the dialoge to use
- $( "#map_container" ).data('formData', $(this).closest('form').serialize());
- //open the dialog
- $( "#map_container" ).dialog( "open" );
- return false;
- });
- $( "input:submit,input:button, a, button", "#controls" ).button();
- initialize();
- });
- //plots a single point on the global map object
- function plotPoint(srcLat,srcLon,title,popUpContent,markerIcon)
- {
- //create a latitude longitude point to add to the gmap
- var myLatlng = new google.maps.LatLng(srcLat, srcLon);
- //create a marker from the latitude longitude object
- var marker = new google.maps.Marker({
- position: myLatlng,
- map: map,
- title:title,
- icon: markerIcon
- });
- //create info window object
- var infowindow = new google.maps.InfoWindow({
- content: popUpContent
- });
- //when marker is clicked, display the info window
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.open(map,marker);
- });
- }
- function initialize()
- {
- //create default latitude longitude
- var latlng = new google.maps.LatLng(0, 0);
- //setup map options
- var myOptions = {
- zoom: 10,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- //create the map
- map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
- }
- //function for converting URL encoded string into object/hashmmap. Used to deserialize serialized form data.
- function QueryStringToHash(query)
- {
- var query_string = {};
- var vars = query.split("&");
- for (var i=0;i<vars.length;i++)
- {
- var pair = vars[i].split("=");
- pair[0] = decodeURIComponent(pair[0]).replace(/\+/g, ' ');
- pair[1] = decodeURIComponent(pair[1]).replace(/\+/g, ' ');
- // If first entry with this name
- if (typeof query_string[pair[0]] === "undefined")
- {
- query_string[pair[0]] = pair[1];
- // If second entry with this name
- }
- else if (typeof query_string[pair[0]] === "string")
- {
- var arr = [ query_string[pair[0]], pair[1] ];
- query_string[pair[0]] = arr;
- // If third or later entry with this name
- }
- else
- {
- query_string[pair[0]].push(pair[1]);
- }
- }
- return query_string;
- }
- </script>
- </head>
- <body>
- <div id="map_container" title="Location Map">
- <div id="map_canvas" style="width:100%;height:100%;"></div>
- </div>
- <div id="controls">
- <form id="mapTestForm">
- <label for="title">Title:</label> <input type="text" id="title" name="title" value="Custom Point" /><br />
- <label for="desc">Description:</label> <input type="text" id="desc" name="desc" value="Description of Custom points" /><br />
- <label for="lat">Latitude:</label> <input type="text" id="lat" name="lat" value="44.856051" /><br />
- <label for="lng">Longitude:</label> <input type="text" id="lng" name="lng" value="-93.242539" /><br />
- <input type="button" name="showMap" value="Show Map" id="showMap" />
- </form>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment