+ var csrf_param = $("meta[name=csrf-param]").attr("content"),
+ csrf_token = $("meta[name=csrf-token]").attr("content");
+
+ $("<input>")
+ .attr("name", csrf_param)
+ .attr("value", csrf_token)
+ .attr("type", "hidden")
+ .appendTo($form);
+
+ var args = {
+ width: "<span id=\"mapnik_image_width\"></span>",
+ height: "<span id=\"mapnik_image_height\"></span>"
+ };
+
+ $("<p>")
+ .attr("class", "text-muted")
+ .html(I18n.t("javascripts.share.image_dimensions", args))
+ .appendTo($form);
+
+ $("<input>")
+ .attr("type", "submit")
+ .attr("class", "btn btn-primary")
+ .attr("value", I18n.t("javascripts.share.download"))
+ .appendTo($form);
+
+ locationFilter
+ .on("change", update)
+ .addTo(map);
+
+ marker.on("dragend", movedMarker);
+ map.on("move", movedMap);
+ map.on("moveend layeradd layerremove", update);
+
+ $ui
+ .on("show", shown)
+ .on("hide", hidden);
+
+ function shown() {
+ $("#mapnik_scale").val(getScale());
+ update();
+ }
+
+ function hidden() {
+ map.removeLayer(marker);
+ map.options.scrollWheelZoom = map.options.doubleClickZoom = true;
+ locationFilter.disable();
+ update();
+ }
+
+ function toggleMarker() {
+ if ($(this).is(":checked")) {
+ marker.setLatLng(map.getCenter());
+ map.addLayer(marker);
+ map.options.scrollWheelZoom = map.options.doubleClickZoom = "center";
+ } else {
+ map.removeLayer(marker);
+ map.options.scrollWheelZoom = map.options.doubleClickZoom = true;
+ }
+ update();
+ }
+
+ function toggleFilter() {
+ if ($(this).is(":checked")) {
+ locationFilter.setBounds(map.getBounds().pad(-0.2));
+ locationFilter.enable();
+ } else {
+ locationFilter.disable();
+ }
+ update();
+ }
+
+ function movedMap() {
+ marker.setLatLng(map.getCenter());
+ update();
+ }
+
+ function movedMarker() {
+ if (map.hasLayer(marker)) {
+ map.off("move", movedMap);
+ map.on("moveend", updateOnce);
+ map.panTo(marker.getLatLng());
+ }
+ }
+
+ function updateOnce() {
+ map.off("moveend", updateOnce);
+ map.on("move", movedMap);
+ update();
+ }
+
+ function escapeHTML(string) {
+ var htmlEscapes = {
+ "&": "&",
+ "<": "<",
+ ">": ">",
+ "\"": """,
+ "'": "'"
+ };
+ return string === null ? "" : String(string).replace(/[&<>"']/g, function (match) {
+ return htmlEscapes[match];
+ });