Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package migration

import (
"context"
"fmt"
"log"

"go.mongodb.org/mongo-driver/bson"
)

func ChangeEsriAndStamenToDefault(ctx context.Context, c DBClient) error {
collection := c.WithCollection("property").Client()

filter := bson.M{
"items.groups.fields": bson.M{
"$elemMatch": bson.M{
"field": "tile_type",
"value": bson.M{
"$in": []string{"esri_world_topo", "stamen_watercolor", "stamen_toner"},
},
},
},
}

cursor, err := collection.Find(ctx, filter)
if err != nil {
return fmt.Errorf("failed to find property documents: %w", err)
}
defer func() {
if cerr := cursor.Close(ctx); cerr != nil {
log.Printf("failed to close cursor: %v", cerr)
}
}()

var updatedCount int64 = 0

for cursor.Next(ctx) {
var doc bson.M
if err := cursor.Decode(&doc); err != nil {
return fmt.Errorf("failed to decode document: %w", err)
}

documentID := doc["_id"]
updated := false

if items, ok := doc["items"].(bson.A); ok {
for _, item := range items {
if itemMap, ok := item.(bson.M); ok {
if groups, ok := itemMap["groups"].(bson.A); ok {
for _, group := range groups {
if groupMap, ok := group.(bson.M); ok {
if fields, ok := groupMap["fields"].(bson.A); ok {
for _, field := range fields {
if fieldMap, ok := field.(bson.M); ok {
if fieldMap["field"] == "tile_type" {
value, ok := fieldMap["value"].(string)
if ok && (value == "esri_world_topo" || value == "stamen_watercolor" || value == "stamen_toner") {
fieldMap["value"] = "default"
updated = true
}
}
}
}
}
}
}
}
}
}
}

if updated {
updateFilter := bson.M{"_id": documentID}
updateDoc := bson.M{"$set": bson.M{"items": doc["items"]}}

result, err := collection.UpdateOne(ctx, updateFilter, updateDoc)
if err != nil {
return fmt.Errorf("failed to update document with ID %v: %w", documentID, err)
}

if result.ModifiedCount > 0 {
updatedCount++
fmt.Printf("Updated document ID: %v\n", documentID)
}
}
}

if err := cursor.Err(); err != nil {
return fmt.Errorf("cursor error: %w", err)
}

fmt.Printf("Migration completed. Updated %d documents.\n", updatedCount)
return nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions server/pkg/builtin/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ extensions:
label: Labelled
- key: default_road
label: Road Map
- key: stamen_watercolor
label: Stamen Watercolor
- key: stamen_toner
label: Stamen Toner
- key: open_street_map
label: OpenStreetMap
- key: esri_world_topo
label: ESRI Topography
- key: black_marble
label: Earth at night
- key: japan_gsi_standard
Expand Down
3 changes: 0 additions & 3 deletions server/pkg/builtin/manifest_ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ extensions:
default: デフォルト
default_label: ラベル付き地図
default_road: 道路地図
stamen_watercolor: Stamen Watercolor
stamen_toner: Stamen Toner
open_street_map: OpenStreetMap
esri_world_topo: ESRI Topography
black_marble: Black Marble
japan_gsi_standard: 地理院地図 標準地図
url: URL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
ImageryProvider,
ArcGisMapServerImageryProvider,
IonImageryProvider,
OpenStreetMapImageryProvider,
IonWorldImageryStyle,
Expand All @@ -20,39 +19,21 @@ export const tiles = {
IonImageryProvider.fromAssetId(IonWorldImageryStyle.ROAD, {
accessToken: cesiumIonAccessToken,
}).catch(console.error),
stamen_watercolor: () =>
new OpenStreetMapImageryProvider({
url: "https://stamen-tiles.a.ssl.fastly.net/watercolor/",
credit: "Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.",
fileExtension: "jpg",
}),
stamen_toner: () =>
new OpenStreetMapImageryProvider({
url: "https://stamen-tiles.a.ssl.fastly.net/toner/",
credit: "Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.",
}),
open_street_map: () =>
new OpenStreetMapImageryProvider({
url: "https://a.tile.openstreetmap.org/",
credit:
"Copyright: Tiles © Esri — Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012",
}),
esri_world_topo: () =>
ArcGisMapServerImageryProvider.fromUrl(
"https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",
{
credit:
"Copyright: Tiles © Esri — Esri, DeLorme, NAVTEQ, TomTom, Intermap, iPC, USGS, FAO, NPS, NRCAN, GeoBase, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), and the GIS User Communit",
enablePickFeatures: false,
},
).catch(console.error),
black_marble: ({ cesiumIonAccessToken } = {}) =>
IonImageryProvider.fromAssetId(3812, { accessToken: cesiumIonAccessToken }).catch(
console.error,
),
japan_gsi_standard: () =>
new OpenStreetMapImageryProvider({
url: "https://cyberjapandata.gsi.go.jp/xyz/std/",
credit:
'<a href="https://maps.gsi.go.jp/development/ichiran.html">国土地理院</a>, Shoreline data is derived from: United States. National Imagery and Mapping Agency. "Vector Map Level 0 (VMAP0)." Bethesda, MD: Denver, CO: The Agency; USGS Information Services, 1997.',
}),
url: ({ url } = {}) => (url ? new UrlTemplateImageryProvider({ url }) : null),
} as {
Expand Down
Loading