Skip to content

Commit

Permalink
Export map (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristineguadelupe authored Jan 16, 2024
1 parent 31db285 commit cc8366a
Show file tree
Hide file tree
Showing 7 changed files with 665 additions and 71 deletions.
21 changes: 20 additions & 1 deletion assets/maplibre/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as maplibregl from "maplibre-gl";
import VectorTextProtocol from "maplibre-gl-vector-text-protocol";
import MaplibreGeocoder from "@maplibre/maplibre-gl-geocoder";
import * as MaplibreExportControl from "@watergis/maplibre-gl-export";

import "@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css";
import "maplibre-gl/dist/maplibre-gl.css";
import "@watergis/maplibre-gl-export/dist/maplibre-gl-export.css";

export function init(ctx, data) {
ctx.importCSS("main.css");
Expand All @@ -22,6 +25,7 @@ export function init(ctx, data) {
geocode = [],
fullscreen = [],
scale = [],
export_map = [],
hover = [],
center = [],
info = [],
Expand Down Expand Up @@ -58,6 +62,9 @@ export function init(ctx, data) {
scale.forEach((options) => {
addScale(options);
});
export_map.forEach((options) => {
addExportMap(options);
});
hover.forEach((layer) => {
addHover(layer);
});
Expand Down Expand Up @@ -109,7 +116,11 @@ export function init(ctx, data) {
});

ctx.handleEvent("add_scale", (options) => {
addScale();
addScale(options);
});

ctx.handleEvent("add_export_map", (options) => {
addExportMap(options);
});

ctx.handleEvent("clusters_expansion", (clusters) => {
Expand Down Expand Up @@ -181,6 +192,14 @@ export function init(ctx, data) {
map.addControl(scale);
}

function addExportMap({ filename, options }) {
const export_map = new MaplibreExportControl.MaplibreExportControl({
Filename: filename,
...options,
});
map.addControl(export_map);
}

function loadImage({ name, url, options }) {
map.loadImage(url, (error, image) => {
if (error) throw error;
Expand Down
Loading

0 comments on commit cc8366a

Please sign in to comment.