leaflet cloudmade and live pageinit
I use maps from the leaflet cloudmade and for them to be displayed correctly when I load the page, I get to use $ ('# MyLocation'). Live ("pageinit", function () {, the first map is loaded properly but I can not get the second map to display correctly, it just gets a little bit visible. Looks like $ ('# mylocation1'). live ("pageinit", function () {does not work the second time.
Grateful for the tip!
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>Kartfunktioner</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="apple-touch-icon" href="images/apple-touch-icon.png" />
- <link rel="shortcut icon" href="favicon.ico" />
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
- <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
- <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
- <link rel="stylesheet" href="http://leaflet.cloudmade.com/dist/leaflet.css" />
- <!--[if lte IE 8]><link rel="stylesheet" href="http://leaflet.cloudmade.com/dist/leaflet.ie.css" /><![endif]-->
- <script src="http://leaflet.cloudmade.com/dist/leaflet.js"></script>
- <style>
- body {
- padding: 0;
- margin: 0;
- }
- html, body, #map, #map1 {
- height: 500px;
- }
- </style>
-
- </head>
- <body>
-
- <div data-role="page" data-theme="c" id="hem">
- <div data-role="header" data-theme="b">
- <h1>Kartor</h1>
- </div><!-- /header -->
- <div data-role="content">
- <ul data-role="listview" data-inset="true" data-filter="false" data-theme="c">
- <li><a data-transition="slide" href="#mylocation">Nuvarande plats</a></li>
- <li><a data-transition="slide" href="#mylocation1">Markeringar på karta</a></li>
- </ul>
- </div><!-- /content -->
-
- </div><!-- /page -->
- <div data-role="page" data-theme="c" id="mylocation">
-
- <div data-role="header" data-theme="b">
- <a href="#hem" data-ajax="false" data-direction="reverse" data-transition="slide" data-theme="c">Tillbaka</a>
- <h1>Nuvarande plats</h1>
- </div><!-- /header -->
- <div data-role="content" id="map">
-
- <script>
-
- jQuery(document).on('pageinit', '#mylocation', function() {
- var cloudmade = new L.TileLayer('http://{s}.tile.cloudmade.com/d116731b41464275bb37693a2f8cfe89/997/256/{z}/{x}/{y}.png');
- var map = L.map('map');
-
- L.tileLayer('http://{s}.tile.cloudmade.com/d116731b41464275bb37693a2f8cfe89/997/256/{z}/{x}/{y}.png', {
- maxZoom: 18,
- attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>'
- }).addTo(map);
-
- function onLocationFound(e) {
- var radius = e.accuracy / 2;
-
- L.marker(e.latlng).addTo(map)
- .bindPopup("Du är " + radius + " meter från den här platsen").openPopup();
-
- L.circle(e.latlng, radius).addTo(map);
- }
-
- function onLocationError(e) {
- alert(e.message);
- }
-
- map.on('locationfound', onLocationFound);
- map.on('locationerror', onLocationError);
-
- map.locate({setView: true, maxZoom: 16});
-
- });
- </script>
- </div><!-- /content -->
-
- <div data-role="footer" data-position="fixed" data-theme="b" class="classFooter">
- <h1>Copyright © 2012</h1>
- </div>
- </div><!-- /page -->
- <div data-role="page" data-theme="c" id="mylocation1">
-
- <div data-role="header" data-theme="b">
- <a href="#hem" data-ajax="false" data-direction="reverse" data-transition="slide" data-theme="c">Tillbaka</a>
- <h1>Nuvarande plats</h1>
- </div><!-- /header -->
- <div data-role="content" id="map1">
-
- <script>
-
-
- $('#mylocation1').live('pagecreate',function(event){
- var map1 = L.map('map1').setView([51.505, -0.09], 13);
-
- L.tileLayer('http://{s}.tile.cloudmade.com/d116731b41464275bb37693a2f8cfe89/997/256/{z}/{x}/{y}.png', {
- attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
- maxZoom: 18
- }).addTo(map1);
-
- });
- </script>
- </div><!-- /content -->
-
- <div data-role="footer" data-position="fixed" data-theme="b" class="classFooter">
- <h1>Copyright © 2012</h1>
- </div>
- </div><!-- /page -->
-
- </body>
- </html>
-