I am trying to display a simple map in an ASP.NET page that has a Master Page. Everything works fine when I put the code in a static HTML page but nothing displays when using asp.net not even an error. When comparing the request/response in fiddler I can see that google is not sending any images back when using asp.net master page.
Here's my client side code (I can hit a break point here):
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100%; background-color:#eeeeee;}
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapDiv = document.getElementById("map_canvas");
var map = new google.maps.Map(mapDiv, myOptions);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div id="map_canvas" style="width:100%; height:100%"></div>
</asp:Content>
I call the script from the server:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim mybodytag As HtmlGenericControl
mybodytag = Page.Master.FindControl("mainbody")
mybodytag.Attributes.Add("onload", "initialize()")
End Sub
Found the solution. I changed the div % to a fixed px size and it worked:
<div id="map_canvas" style="width:800px; height:600px"></div>
Related
I'm having a hard time initializing a leaflet map in fullscreen in a jquery mobile project.
When I init the map from a $(document).on('pagecreate')-event the map starts as a very small layer sitting on the left top of the browser, and if I resize the browser just a little, the map pops into fullscreen and stays there.
On the other hand, when i init the map from a window.onload-event - everything inits perfect.
As i understand it using pagecreate is preferable, so i wanna use it.
aspx:LeafletLoad.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="LeafletLoad.aspx.cs" Inherits="RadikaleNu.LeafletLoad" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Leflet load</title>
<link href="Content/jquery.mobile-1.4.5.css" rel="stylesheet" />
<link href="Content/leaflet.css" rel="stylesheet" />
<link href="Content/leafletload.css" rel="stylesheet" />
<!-- Javascript libraies -->
<script src="Scripts/jquery-2.1.3.js"></script>
<!--<script src="Scripts/jquery-2.1.3.min.js"></script>-->
<script src="Scripts/jquery.mobile-1.4.5.js"></script>
<script src="Scripts/leaflet-src.js"></script>
<script src="Scripts/leafletload.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div data-role="page" id="MapPage" >
<div role="main" class="ui-map">
<!-- Map -->
<div id="map"></div>
</div>
</div>
</form>
</body>
</html>
Javascript: leafletload.js
var map = null;
var osm = null;
//This works perfectly - the map starts fullscreen
/*
window.onload = function () {
InitMap();
};
*/
//This works not so perfectly - the leflet map starts very minimized in the top left corneruntil browser resize.
$(document).on('pagecreate', function(){
InitMap();
});
function InitMap() {
// set up the map
map = new L.Map('map');
osm = new L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.{ext}', {
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20,
ext: 'png'
});
// start the map in Copenhagen, Denmark
map.setView(new L.LatLng(55.682665, 12.536639), 9);
map.addLayer(osm);
}
CSS: leafletload.css
body {
margin: 0;
}
#map {
height: 100%;
}
.ui-map {
position: absolute;
top: 0px;
right: 0;
bottom: 0px;
left: 0;
padding: 0 !important;
}
On the other hand, when i init the map from a window.onload-event - everything inits perfect.
You'll want to use onload. The gist of it is that events like pagecreate and ready (also known as $(function(){}) fire when the page's content is loaded but the page isn't laid out - your browser doesn't know yet what size the map will be. Leaflet needs that size in order to draw the map, and since pagecreate doesn't let it know that, it draws a tiny, cropped map as you see currently.
I am using this jQuery splitter library because on a non-master aspx web form I am able to duplicate this example and insert gridviews, ajax tabs, etc and all the other content I need no problem. But, I am unable to do the same thing using a content page from the VS2012 ASP.NET Web Forms Site template. If anyone is aware of a better splitter option that can create a layout that can incorporate asp controls with ajax, please let me know. I have tried w2ui but I can't insert asp controls. I have also been able to insert asp controls using jeasyui and dhtml-suite. But can't get any working in the content page. Thanks for any input...
link to jquery-dev demo page
and a rough idea of what I am going for is something like this:
link to complex layout using splitters
I have been reading a lot of the other answers based on applying javascript to a content page and it seems the most straightforward method is to link to the css in the content page header and reference the javascript in the content page content section. So my master page is unchanged from the template default .
Here is the code for my content page:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="nested_sidebars_master.aspx.cs" Inherits="layout_master_demos_nested_sidebars_master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<link type="text/css" rel="stylesheet" href="css/layout-default-latest.css" />
<style type="text/css">
html, body {
background: #666;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: auto; /* when page gets too small */
}
#container {
background: #999;
height: 100%;
margin: 0 auto;
width: 100%;
max-width: 900px;
min-width: 700px;
_width: 700px; /* min-width for IE6 */
}
.pane {
display: none; /* will appear when layout inits */
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<script type="text/javascript" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery-ui-latest.js"></script>
<script type="text/javascript" src="js/jquery.layout-latest.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#container").layout();
});
</script>
<div id="container">
<div class="ui-layout-center">
Center
<p><B>Go to the Demos page</B></p>
</div>
<div class="ui-layout-north">North</div>
<div class="ui-layout-south">South</div>
<div class="ui-layout-east">East</div>
<div class="ui-layout-west">West</div>
</div>
</asp:Content>
When I run without without
$(document).ready(function () {
$("#container").layout();
I can at least see my divs:
But when I include the that javascript, I get nothing:
When I run a simple alert javascript like:
> $(document).ready(function () {;
> alert('hey!');
I get a result, so I know the javascript is running:
So, it seems something is wrong with the .layout method. If anyone can tip me off as to a good way to trouble shoot javascript (I am a newbie) that would be helpful, like writing to a label in asp.net or using a message box in C#.net.
Found out what I was going wrong:
I needed to reference the css from the same content place holder. The was referenced at:
http://forums.asp.net/t/1581173.aspx?Jquery+UI+layout+and+Asp+net+master+page
For some reason, it didn't accept 100% as the height in the css applied to the content container and was considering it 0. Once I changed the height to pixels, it worked.
The updated working code:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="nested_sidebars_master.aspx.cs" Inherits="layout_master_demos_nested_sidebars_master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<link type="text/css" rel="stylesheet" href="css/layout-default-latest.css"/>
<style type="text/css">
html, body {
background: #666;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: auto; /* when page gets too small */
}
#container {
background: #999;
height: 250px;
margin: 0 auto;
width: 100%;
max-width: 900px;
min-width: 700px;
_width: 700px; /* min-width for IE6 */
}
.pane {
display: none; /* will appear when layout inits */
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="../source/stable/jquery.layout.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#container').layout();
//alert('hey!');
});
</script>
<div id="container">
<div class="ui-layout-center">Center</div>
<div class="ui-layout-north">North</div>
<div class="ui-layout-south">South</div>
<div class="ui-layout-east">East</div>
<div class="ui-layout-west">West</div>
</div>
</asp:Content>
and the result:
I am trying to display Google Map in my ASP.net web form page.
The javascript is as below:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=xxxxx&sensor=false">
</script>
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapcv = document.getElementById('map-canvas');
map = new google.maps.Map(mapcv,
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
I used the following HTML and it doesn't work if I put the Div Tag within the form tag.
<form id="form1" runat="server">
<div id="map-canvas" ></div>
</form>
But if I move Div tag outside of the form tag as below, it works
<div id="map-canvas" ></div>
<form id="form1" runat="server">
</form>
I want to put the Div tag inside the form. Could you please help me how I could do that? Thanks.
Simply set the div width and height to see it! Your map is there but not visible :)
<div id="map_canvas" style="width:600px;height:400px"></div>
You could also set them in css in the header:
<style>
html, body, #form1, #map_canvas
{
margin: 0;
padding: 0;
height: 100%;
}
</style>
There should not be any problem if it is inside form tag. I have posted a example here.. Can you take a look http://deepumi.wordpress.com/2010/03/28/google-map-3-with-multiple-locations-in-asp-net-c/
I have a jsp page which includes a another jsp file which has a google map. But when I access the parent page the div in which the jsp file is included is getting a CSS property value "overflow: hidden" due to which the map is not shown.
Code for parent jsp:
<!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=iso-8859-1" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css" />
<script src="<%=request.getContextPath()%>/scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
function showHeatMap(){
$('#heatDiv').toggle(true);
$('#exportToCSVHeatMap').removeAttr('disabled');
$('#dummyFenceMap').style.overflow="visible";
}
</script>
</head>
<body>
<div id="heatMapDiv" style="display:none">
heat map
<div class="div-inline">
<div class="div-daily">From Date (MM/DD/YYYY)</div>
<input type="text" name="fromDateHM" id="datepicker4" class="input-inline" />
</div>
<div class="div-inline">
<div class="div-daily">To Date (MM/DD/YYYY)</div>
<input type="text" name="toDateHM" id="datepicker5" class="input-inline" />
</div>
<div id="buttonDiv">
<input type="button" value="Show Heat Map" onclick="showHeatMap()" />
<input type="button" value="Export To CSV" id="exportToCSVHeatMap" onclick="exportToCSVHeatMap()" disabled="disabled"/>
</div> <!-- buttonDiv -->
<div id="heatDiv" class="heat-map">
<div class="div-daily">Heat Map</div>
<div id="heatMap" style="display= block; width= 800px; height= 800px; "><jsp:include page="../jsp/dummyheatmap.jsp?name=test&id=1001"></jsp:include></div>
</div> <!-- footTraffic -->
</div> <!-- heatMapDiv -->
</body>
</html>
Included jsp file code:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>dummy heat map</title>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#fenceMap { height: 50% }
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
/* For Google Map.*/
function googleMapinitialize(){
var fenceAdd=new google.maps.LatLng(37.2146,121.5545);
var mapProp = {
center:fenceAdd,
zoom:30,
mapTypeId:google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("dummyFenceMap"),mapProp);
var geocoder = new google.maps.Geocoder();
var location = "2001 Gateway PI, San Jose, CA";
if(!geocoder) {
geocoder = new google.maps.Geocoder();
}
var geocoderRequest = {
address: location
};
var myCity = null;
var marker = null;
var infowindow = null;
geocoder.geocode(geocoderRequest, function(results, status) {
if (status =="" || status == google.maps.GeocoderStatus.ZERO_RESULTS){
alert("'" + location + "' not found!!!");
} else if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
fenceAdd = new google.maps.LatLng(results[0].geometry.location.hb,results[0].geometry.location.ib);
if (!marker) {
marker = new google.maps.Marker({
map: map,
raiseOnDrag:false,
draggable:true
});
marker.setPosition(results[0].geometry.location);
google.maps.event.addListener(marker,'click',function(){
if (!infowindow) {
infowindow = new google.maps.InfoWindow({
disableAutoPan:true,
maxWidth:100
});
}
var content = '<strong>' + results[0].formatted_address + '</strong>';
infowindow.setContent(content);
infowindow.setPosition(results[0].geometry.location);
infowindow.open(map, marker);
});
}
}
myCity = new google.maps.Circle({
center:fenceAdd,
radius:125,
strokeColor:"#0000ff",
strokeOpacity:0.1,
strokeWeight:0.1,
fillColor:"#0000ff",
fillOpacity:0.20,
map:map
});
google.maps.event.addListener(map, 'click', function(){
infowindow.close();
});
google.maps.event.addListener(map, 'dblclick', function(){
window.open("<%=request.getContextPath() %>/jsp/googleMapPopup.jsp?fenceAddress="+$('#haddr').val(),'ADDRESSMAP','height=400,width=600');
});
google.maps.event.trigger(map,'resize');
});
}
google.maps.event.addDomListener(window, 'load', googleMapinitialize);
</script>
</head>
<body onload="googleMapinitialize()">
<h1>Name : <%=request.getParameter("name")%> & id : <%=request.getParameter("id")%></h1>
<div id="dummyFenceMap" style="height=80%;border:1px solid #ff0000;overflow:visible;">
</div><!-- new-div-tag2 -->
<h1>Map end</h1>
</body>
</html>
The #heatMap div has a height of 2 / 11px and overflow: hidden. When I edit the overflow property to visible I see the google logo & map type
Can anyone help me what is wrong in my code?
I solved the issue by adding following style to the included JSP file's 'dummyFenceMap' div.
style="border:1px solid #ff0000;position:relative; left:150px; top:10px; width:500px; height:400px;padding-left:15px;padding-right:15px"
After adding the above style the Map is shown in the embedded JSP file.
But facing a new issue that is - the Google map is shown in 3/4th part of the div rest is blank. But when I resize the browser window the Google Map is redrawn properly. How to resolve this issue?
This question is specific to the design. I have an application that displays positions on a map all works "fine". But now I need to design the user interface, that goes beyond the map (buttons, forms, etc.) these will be located on one side of the map, but under any reason the map is displayed once change some of the CSS page.
I'm a bit desperate since neither my own CSS, or bootstrap (2.3.0), foundation (3.2.5) works. The map simply not displayed, in the console there are no errors. Event in the better case the map is displayed but with graphics glitchs (zoom controls messed, bad markers position, etc) That may be happening and how I can fix this. Will I have to use an iframe? or is there a better solution?
I've readed about max-width: none fix but this is solving nothing. To clarify that I am using the maps are not static.
I can get work perfectly the maps if try with a simple markup and styles
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My App</title>
<link rel="stylesheet" href="/css/styles.css" media="all">
</head>
<body>
<div id="map" class="map_canvas"></div>
<script src="https://maps.googleapis.com/maps/api/js?&v=3.exp&sensor=false"></script>
<script src="/js/app.js"></script>
</body>
</html>
styles.css
html, body, .map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
app.js
google.maps.event.addDomListener(window, 'load', function() {
options = {
zoom: 15,
center: new google.maps.LatLng(10.472937,-73.262308),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
});
But obviously it'snt enough for build the application.
A solution that includes the use of iframes, since it seems that is the only way that the map is not affected by the rest of the CSS
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My App</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3"></div>
<div class="span9">
<iframe id="map_container" src="/map.html" frameborder="0"></iframe>
</div>
</div>
</div>
<script src="https://maps.googleapis.com/maps/api/js?&v=3.exp&sensor=false"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="/js/app.js"></script>
</body>
</html>
map.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mapa</title>
<link rel="stylesheet" href="/css/map-styles.css" media="all">
</head>
<body>
<div id="map" class="map_canvas"></div>
</body>
</html>
map-styles.css
html, body, .map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
app.js
google.maps.event.addDomListener(window, 'load', function() {
var options = {
zoom: 15,
center: new google.maps.LatLng(10.472937,-73.262308),
mapTypeId: google.maps.MapTypeId.ROADMAP
},
$iframe = $('#map_container'),
map_el = $iframe.contents().find('#map')[0],
map = new google.maps.Map(map_el, options);
// Match iframe size to parent
$iframe.width($iframe.parent().width());
$iframe.height($iframe.parent().height());
});