Skip to content
Browse files

modularize

  • Loading branch information...
1 parent 27ed83b commit d37e4788181e1a8813b5a4f45cac6568d883340f @simon04 committed Apr 21, 2012
Showing with 18 additions and 79 deletions.
  1. +6 −35 aed.html
  2. +6 −0 map.js
  3. +6 −44 restaurant.html
View
41 aed.html
@@ -6,37 +6,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://leaflet.cloudmade.com/dist/leaflet.js"></script>
+ <script src="map.js"></script>
<script>
- function initMap() {
- var attr_osm = 'Map data &copy; <a href="http://openstreetmap.org/">OpenStreetMap</a> contributors',
- attr_mapbox = 'Imagery &copy; <a href="http://mapbox.com/about/maps/">MapBox</a>'
- attr_overpass = 'POI via <a href="http://www.overpass-api.de/">Overpass API</a>';
-
- var osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: [attr_osm, attr_overpass].join(', ')}),
- mapbox_streets = new L.TileLayer("http://{s}.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png", {attribution: [attr_mapbox, attr_osm, attr_overpass].join(', ')}),
- mapbox_light = new L.TileLayer("http://{s}.tiles.mapbox.com/v3/mapbox.mapbox-light/{z}/{x}/{y}.png", {attribution: [attr_mapbox, attr_osm, attr_overpass].join(', ')}),
- mapbox_simple = new L.TileLayer("http://{s}.tiles.mapbox.com/v3/mapbox.mapbox-simple/{z}/{x}/{y}.png", {attribution: [attr_mapbox, attr_osm, attr_overpass].join(', ')});
-
- map = new L.Map('map', {
- center: new L.LatLng(47.25, 11.3),
- zoom: 13,
- layers: mapbox_light,
- });
-
- map.addControl(new L.Control.Layers({
- 'MapBox Streets': mapbox_streets,
- 'MapBox Light': mapbox_light,
- 'MapBox Simple': mapbox_simple,
- 'OpenSteetMap': osm,
- }));
-
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(function(position) {
- var center = new L.LatLng(position.coords.latitude, position.coords.longitude);
- map.setView(center, 13);
- });
- }
- }
+ var map;
+ $(function () {
+ map = initMap();
+ loadAed();
+ });
function loadAed() {
var AedIcon = L.Icon.extend({
@@ -79,11 +55,6 @@
</head>
<body>
<div id="map"></div>
-
- <script>
- initMap();
- loadAed();
- </script>
</body>
</html>
View
6 map.js
@@ -27,6 +27,12 @@ function initMap() {
}();
map.addControl(map.getControl());
+ L.LatLngBounds.prototype.toOverpassBBoxString = function(){
+ var a = this._southWest,
+ b = this._northEast;
+ return [a.lat, a.lng, b.lat, b.lng].join(",");
+ }
+
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var center = new L.LatLng(position.coords.latitude, position.coords.longitude);
View
50 restaurant.html
@@ -6,49 +6,15 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://leaflet.cloudmade.com/dist/leaflet.js"></script>
+ <script src="map.js"></script>
<script>
- function initMap() {
- var attr_osm = 'Map data &copy; <a href="http://openstreetmap.org/">OpenStreetMap</a> contributors',
- attr_mapbox = 'Imagery &copy; <a href="http://mapbox.com/about/maps/">MapBox</a>'
- attr_overpass = 'POI via <a href="http://www.overpass-api.de/">Overpass API</a>';
-
- var osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom:18, attribution: [attr_osm, attr_overpass].join(', ')}),
- mapbox_streets = new L.TileLayer("http://{s}.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png", {maxZoom:17, attribution: [attr_mapbox, attr_osm, attr_overpass].join(', ')}),
- mapbox_light = new L.TileLayer("http://{s}.tiles.mapbox.com/v3/mapbox.mapbox-light/{z}/{x}/{y}.png", {maxZoom:17, attribution: [attr_mapbox, attr_osm, attr_overpass].join(', ')}),
- mapbox_simple = new L.TileLayer("http://{s}.tiles.mapbox.com/v3/mapbox.mapbox-simple/{z}/{x}/{y}.png", {maxZoom:17, attribution: [attr_mapbox, attr_osm, attr_overpass].join(', ')});
-
- map = new L.Map('map', {
- center: new L.LatLng(47.25, 11.3),
- zoom: 13,
- layers: mapbox_light,
- });
-
- ids = {};
-
- L.LatLngBounds.prototype.toOverpassBBoxString = function(){
- var a = this._southWest,
- b = this._northEast;
- return [a.lat, a.lng, b.lat, b.lng].join(",");
- }
-
- map.addControl(new L.Control.Layers({
- 'MapBox Streets': mapbox_streets,
- 'MapBox Light': mapbox_light,
- 'MapBox Simple': mapbox_simple,
- 'OpenSteetMap': osm,
- }));
-
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(function(position) {
- var center = new L.LatLng(position.coords.latitude, position.coords.longitude);
- map.setView(center, 14);
- });
- }
-
+ var map, ids = {};
+ $(function () {
+ map = initMap();
+ map.zoomIn();
loadPoi();
-
map.on('moveend', loadPoi);
- }
+ });
function loadPoi() {
if (map.getZoom() < 14) {
@@ -100,10 +66,6 @@
</head>
<body>
<div id="map"></div>
-
- <script>
- initMap();
- </script>
</body>
</html>

0 comments on commit d37e478

Please sign in to comment.
Something went wrong with that request. Please try again.