aboutsummaryrefslogtreecommitdiff
path: root/src/js/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/app')
-rw-r--r--src/js/app/mapfactory.js26
-rw-r--r--src/js/app/places.js16
-rw-r--r--src/js/app/position.js21
3 files changed, 63 insertions, 0 deletions
diff --git a/src/js/app/mapfactory.js b/src/js/app/mapfactory.js
new file mode 100644
index 0000000..8d8bb0e
--- /dev/null
+++ b/src/js/app/mapfactory.js
@@ -0,0 +1,26 @@
+define(['leaflet'], function(L) {
+ // base config
+ var attribOSM = '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
+ OSMLayer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
+ attribution: attribOSM
+ }),
+ scale = L.control.scale({
+ imperial: false
+ });
+
+ return function(id, bounds) {
+ var map = L.map(id, {
+ layers: [OSMLayer]
+ })
+ if (bounds) {
+ map.fitBounds(L.latLngBounds(bounds));
+ } else {
+ map.fitWorld().zoomIn();
+ }
+ map.attributionControl.setPrefix(false);
+
+ scale.addTo(map);
+
+ return map;
+ };
+});
diff --git a/src/js/app/places.js b/src/js/app/places.js
new file mode 100644
index 0000000..9b915cb
--- /dev/null
+++ b/src/js/app/places.js
@@ -0,0 +1,16 @@
+define(['leaflet'], function(L) {
+
+ // GeoJSON feature grouping
+ function returnMarker(feature, latlng) {
+ return L.marker(latlng);
+ };
+
+ var place = L.geoJson([], {
+ pointToLayer: returnMarker
+ });
+
+ return function(data) {
+ place.addData(data);
+ return L.layerGroup().addLayer(place);
+ };
+});
diff --git a/src/js/app/position.js b/src/js/app/position.js
new file mode 100644
index 0000000..0e9bfb2
--- /dev/null
+++ b/src/js/app/position.js
@@ -0,0 +1,21 @@
+define(['leaflet'], function(L) {
+
+ // position popup
+ function round(n,d) {
+ return Math.round(Math.pow(10,d)*n)/Math.pow(10,d)
+ };
+ function lngLatString(latLng) {
+ return round(latLng.lng,5) + ", " + round(latLng.lat,5)
+ };
+ var popup = L.popup();
+
+ return function positionHook(map) {
+ function positionPopup(e) {
+ popup
+ .setLatLng(e.latlng)
+ .setContent("Position (long, lat):<br>" + lngLatString(e.latlng))
+ .openOn(map);
+ }
+ map.on('contextmenu', positionPopup);
+ }
+});