geolocation-map.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * GNU MediaGoblin -- federated, autonomous media hosting
  3. * Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. $(document).ready(function () {
  19. if (!$('#tile-map').length) {
  20. return;
  21. }
  22. console.log('Initializing map');
  23. var longitude = Number(
  24. $('#tile-map #gps-longitude').val());
  25. var latitude = Number(
  26. $('#tile-map #gps-latitude').val());
  27. // Get a new map instance attached and element with id="tile-map"
  28. var map = new L.Map('tile-map');
  29. var mqtileUrl = 'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg';
  30. var mqtileAttrib = '<a id="osm_license_link">see map license</a>';
  31. var mqtile = new L.TileLayer(
  32. mqtileUrl,
  33. {maxZoom: 18,
  34. attribution: mqtileAttrib,
  35. subdomains: '1234'});
  36. map.attributionControl.setPrefix('');
  37. var location = new L.LatLng(latitude, longitude);
  38. map.setView(location, 13).addLayer(mqtile);
  39. var marker = new L.Marker(location);
  40. map.addLayer(marker);
  41. });