Serve embedded maps through the assets pipeline
This commit is contained in:
parent
d04e3ac9f8
commit
c0b47c0c2a
8 changed files with 91 additions and 67 deletions
38
app/assets/javascripts/embed.js
Normal file
38
app/assets/javascripts/embed.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
//= require leaflet
|
||||
//= require leaflet.osm
|
||||
|
||||
window.onload = function () {
|
||||
var query = (window.location.search || '?').substr(1),
|
||||
args = {};
|
||||
|
||||
query.replace(/([^&=]+)=?([^&]*)(?:&+|$)/g, function(match, key, value) {
|
||||
value = value.split(",");
|
||||
if (value.length == 1)
|
||||
value = value[0];
|
||||
args[key] = value;
|
||||
});
|
||||
|
||||
var map = L.map("map");
|
||||
map.attributionControl.setPrefix('');
|
||||
|
||||
if (!args.layer || args.layer == "mapnik" || args.layer == "osmarender") {
|
||||
new L.OSM.Mapnik().addTo(map);
|
||||
} else if (args.layer == "cyclemap" || args.layer == "cycle map") {
|
||||
new L.OSM.CycleMap().addTo(map);
|
||||
} else if (args.layer == "transportmap") {
|
||||
new L.OSM.TransportMap().addTo(map);
|
||||
} else if (args.layer == "mapquest") {
|
||||
new L.OSM.MapQuestOpen().addTo(map);
|
||||
}
|
||||
|
||||
if (args.marker) {
|
||||
L.marker(args.marker).addTo(map);
|
||||
}
|
||||
|
||||
if (args.bbox) {
|
||||
map.fitBounds([L.latLng(args.bbox[1], args.bbox[0]),
|
||||
L.latLng(args.bbox[3], args.bbox[2])])
|
||||
} else {
|
||||
map.fitWorld();
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue