Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: projection support for select mode #285

Merged
merged 5 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions development/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const addModeChangeHandler = (
const getModes = () => {
return [
new TerraDrawSelectMode({
projection: "globe",
flags: {
arbitrary: {
feature: {},
Expand All @@ -99,7 +100,6 @@ const getModes = () => {
midpoints: true,
draggable: true,
deletable: true,
resizable: "center-web-mercator",
},
},
},
Expand All @@ -109,6 +109,8 @@ const getModes = () => {
linestring: {
feature: {
draggable: true,
rotateable: true,
scaleable: true,
coordinates: {
midpoints: true,
draggable: true,
Expand All @@ -122,7 +124,7 @@ const getModes = () => {
coordinates: {
midpoints: false,
draggable: true,
resizable: "center-fixed-web-mercator",
resizable: "center-fixed",
deletable: true,
},
},
Expand All @@ -140,7 +142,7 @@ const getModes = () => {
coordinates: {
midpoints: false,
draggable: true,
resizable: "center-fixed-web-mercator",
resizable: "center-fixed",
deletable: true,
},
},
Expand Down
37 changes: 22 additions & 15 deletions e2e/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ const example = {
lat: 51.509865,
zoom: 12,
initialised: [],
config: null as string | null,
config: null as string[] | null,
initPageConfig() {
const urlParams = new URLSearchParams(window.location.search);
console.log(urlParams);
this.config = urlParams.get("config");
const config = urlParams.get("config");

if (config) {
this.config = config.split(",");
}
},
initLeaflet() {
const { lng, lat, zoom } = this;
Expand Down Expand Up @@ -61,12 +65,12 @@ const example = {
polygon: {
feature: {
validation:
this.config === "validationSuccess" ||
this.config === "validationFailure"
this.config?.includes("validationSuccess") ||
this.config?.includes("validationFailure")
? (feature) => {
return ValidateMaxAreaSquareMeters(
feature,
this.config === "validationFailure"
this.config?.includes("validationFailure")
? 1000000
: 2000000,
);
Expand Down Expand Up @@ -100,7 +104,7 @@ const example = {
draggable: true,
coordinates: {
draggable: true,
resizable: "opposite-web-mercator",
resizable: "opposite",
},
},
},
Expand All @@ -109,7 +113,7 @@ const example = {
draggable: true,
coordinates: {
draggable: true,
resizable: "center-web-mercator",
resizable: "center",
},
},
},
Expand All @@ -122,14 +126,14 @@ const example = {
}),
new TerraDrawPointMode(),
new TerraDrawLineStringMode(
this.config === "insertCoordinates"
this.config?.includes("insertCoordinates")
? {
insertCoordinates: {
strategy: "amount",
value: 10,
},
}
: this.config === "insertCoordinatesGlobe"
: this.config?.includes("insertCoordinatesGlobe")
? {
projection: "globe",
insertCoordinates: {
Expand All @@ -141,24 +145,27 @@ const example = {
),
new TerraDrawPolygonMode({
validation:
this.config === "validationSuccess" ||
this.config === "validationFailure"
this.config?.includes("validationSuccess") ||
this.config?.includes("validationFailure")
? (feature) => {
return ValidateMaxAreaSquareMeters(
feature,
this.config === "validationFailure" ? 1000000 : 2000000,
this.config?.includes("validationFailure")
? 1000000
: 2000000,
);
}
: undefined,
}),
new TerraDrawRectangleMode(),
new TerraDrawCircleMode({
projection:
this.config === "geodesicCircle" ? "globe" : "web-mercator",
projection: this.config?.includes("globeCircle")
? "globe"
: "web-mercator",
}),
new TerraDrawFreehandMode(),
new TerraDrawRenderMode({
modeName: "arbitary",
modeName: "arbitrary",
styles: {
polygonFillColor: "#4357AD",
polygonOutlineColor: "#48A9A6",
Expand Down
Loading
Loading