forked from transit-appliance/Transit-Board-Hotel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapView.js
49 lines (40 loc) · 1.68 KB
/
mapView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$(document).ready(function () {
// parse down the query string
// drop the ?, thanks SO
var qsPairs = window.location.search.substring(1).split('&');
var qsPairsLen = qsPairs.length;
var query = {};
for (var i = 0; i < qsPairsLen; i++) {
var splitPair = qsPairs[i].split('=')
query[splitPair[0]] = splitPair[1];
}
var mapId = query.mapId?query.mapId:'46244';
// config section
// it'd be better if the key was left as is, so that we can track traffic
// style #46244 is the one Matt built for this project
var tileUrl = 'http://{s}.tile.cloudmade.com/2d634343963a4426b126ab70b62bba2a/' + mapId + '/256/{z}/{x}/{y}.png';
var tileAttr = 'Basemap data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade';
var baseLayer = new L.TileLayer(tileUrl,
{maxZoom: 18, attribution: tileAttr});
var transitLayer = new L.TileLayer("gis/trimetTiles/{z}/{x}/{y}.png",
{maxZoom: 18, attribution: 'Transit data courtesy TriMet'});
var lat = query.lat?Number(query.lat):45.5240;
var longitude = query.lon?Number(query.lon):-122.6810;
var zoom = query.zoom?Number(query.zoom):14;
var map = new L.Map(
'map')
.setView(new L.LatLng(lat, longitude), zoom)
.addLayer(baseLayer)
.addLayer(transitLayer);
// update the link
map.on('moveend', function (e) {
// this gets just the URL up the the query string exclusive
var url = window.location.href.replace(window.location.search, '') +
'?lon=' + map.getCenter().lng +
'&lat=' + map.getCenter().lat +
'&zoom=' + map.getZoom() +
'&mapId=' + mapId;
// update the href and the link text
$('#link').attr('href', url).text(url);
});
});