forked from MapComplete/MapComplete
More refactoring
This commit is contained in:
parent
849c61c8a1
commit
e4a2fd1daf
15 changed files with 75 additions and 44 deletions
|
@ -33,7 +33,7 @@ export default class AvailableBaseLayers {
|
|||
public availableEditorLayers: UIEventSource<BaseLayer[]>;
|
||||
|
||||
constructor(location: UIEventSource<{ lat: number, lon: number, zoom: number }>,
|
||||
bm: Basemap) {
|
||||
currentBackgroundLayer: UIEventSource<BaseLayer>) {
|
||||
const self = this;
|
||||
this.availableEditorLayers =
|
||||
location.map(
|
||||
|
@ -59,8 +59,7 @@ export default class AvailableBaseLayers {
|
|||
|
||||
// Change the baselayer back to OSM if we go out of the current range of the layer
|
||||
this.availableEditorLayers.addCallbackAndRun(availableLayers => {
|
||||
const layerControl = bm.CurrentLayer;
|
||||
const currentLayer = layerControl.data.id;
|
||||
const currentLayer = currentBackgroundLayer.data.id;
|
||||
for (const availableLayer of availableLayers) {
|
||||
if (availableLayer.id === currentLayer) {
|
||||
|
||||
|
|
|
@ -12,16 +12,16 @@ export class Basemap {
|
|||
public readonly map: Map;
|
||||
|
||||
public readonly LastClickLocation: UIEventSource<{ lat: number, lon: number }> = new UIEventSource<{ lat: number, lon: number }>(undefined)
|
||||
public readonly CurrentLayer: UIEventSource<BaseLayer> = new UIEventSource(AvailableBaseLayers.osmCarto);
|
||||
|
||||
|
||||
constructor(leafletElementId: string,
|
||||
location: UIEventSource<Loc>,
|
||||
currentLayer: UIEventSource<BaseLayer>,
|
||||
extraAttribution: UIElement) {
|
||||
this.map = L.map(leafletElementId, {
|
||||
center: [location.data.lat ?? 0, location.data.lon ?? 0],
|
||||
zoom: location.data.zoom ?? 2,
|
||||
layers: [ AvailableBaseLayers.osmCarto.layer],
|
||||
layers: [AvailableBaseLayers.osmCarto.layer],
|
||||
});
|
||||
|
||||
L.control.scale(
|
||||
|
@ -30,11 +30,12 @@ export class Basemap {
|
|||
}
|
||||
).addTo(this.map)
|
||||
|
||||
|
||||
// Users are not allowed to zoom to the 'copies' on the left and the right, stuff goes wrong then
|
||||
// We give a bit of leeway for people on the edges
|
||||
// Also see: https://www.reddit.com/r/openstreetmap/comments/ih4zzc/mapcomplete_a_new_easytouse_editor/g31ubyv/
|
||||
this.map.setMaxBounds(
|
||||
[[-100,-200],[100,200]]
|
||||
[[-100, -200], [100, 200]]
|
||||
);
|
||||
this.map.attributionControl.setPrefix(
|
||||
extraAttribution.Render() + " | <a href='https://osm.org'>OpenStreetMap</a>");
|
||||
|
@ -42,6 +43,19 @@ export class Basemap {
|
|||
this.map.zoomControl.setPosition("bottomright");
|
||||
const self = this;
|
||||
|
||||
let previousLayer = currentLayer.data;
|
||||
currentLayer.addCallbackAndRun(layer => {
|
||||
if (layer === previousLayer) {
|
||||
return;
|
||||
}
|
||||
if (previousLayer !== undefined) {
|
||||
self.map.removeLayer(previousLayer.layer);
|
||||
}
|
||||
previousLayer = layer;
|
||||
self.map.addLayer(layer.layer);
|
||||
})
|
||||
|
||||
|
||||
this.map.on("moveend", function () {
|
||||
location.data.zoom = self.map.getZoom();
|
||||
location.data.lat = self.map.getCenter().lat;
|
||||
|
@ -57,6 +71,8 @@ export class Basemap {
|
|||
self.LastClickLocation.setData({lat: e.latlng.lat, lon: e.latlng.lng});
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import {And, Tag, TagsFilter} from "../Tags";
|
|||
import State from "../../State";
|
||||
import {Utils} from "../../Utils";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import Constants from "../../Models/Constants";
|
||||
|
||||
export class Changes {
|
||||
|
||||
|
@ -181,7 +182,7 @@ export class Changes {
|
|||
}
|
||||
|
||||
|
||||
let changes = `<osmChange version='0.6' generator='Mapcomplete ${State.vNumber}'>`;
|
||||
let changes = `<osmChange version='0.6' generator='Mapcomplete ${Constants.vNumber}'>`;
|
||||
|
||||
if (creations.length > 0) {
|
||||
changes +=
|
||||
|
|
|
@ -5,6 +5,8 @@ import {ElementStorage} from "../ElementStorage";
|
|||
import State from "../../State";
|
||||
import Locale from "../../UI/i18n/Locale";
|
||||
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
|
||||
import Constants from "../../Models/Constants";
|
||||
import {Basemap} from "../Leaflet/Basemap";
|
||||
|
||||
export class ChangesetHandler {
|
||||
|
||||
|
@ -101,12 +103,14 @@ export class ChangesetHandler {
|
|||
path: '/api/0.6/changeset/create',
|
||||
options: {header: {'Content-Type': 'text/xml'}},
|
||||
content: [`<osm><changeset>`,
|
||||
`<tag k="created_by" v="MapComplete ${State.vNumber}" />`,
|
||||
`<tag k="created_by" v="MapComplete ${Constants.vNumber}" />`,
|
||||
`<tag k="comment" v="Adding data with #MapComplete for theme #${layout.id}${commentExtra}"/>`,
|
||||
`<tag k="theme" v="${layout.id}"/>`,
|
||||
`<tag k="language" v="${Locale.language.data}"/>`,
|
||||
`<tag k="host" v="${escapeHtml(window.location.host)}"/>`,
|
||||
`<tag k="imagery" v="${State.state.backgroundLayer.data.id}/>`,
|
||||
surveySource,
|
||||
layout.maintainer !== undefined ? `<tag k="theme-creator" v="${escapeHtml(layout.maintainer)}"/>` : "",
|
||||
(layout.maintainer ?? "") !== "" ? `<tag k="theme-creator" v="${escapeHtml(layout.maintainer)}"/>` : "",
|
||||
`</changeset></osm>`].join("")
|
||||
}, function (err, response) {
|
||||
if (response === undefined) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue