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

Add a Terratype to Our.Umbraco.GMaps Migrator #285

Merged
merged 2 commits into from
Feb 28, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Newtonsoft.Json.Linq;

namespace uSync.Migrations.Migrators.Community.TerraType;

[SyncMigrator("Terratype")]
public class TerratypeToGMapsMigrator : SyncPropertyMigratorBase
{
private const string DefaultPosition = "55.406321,10.387015";
public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
=> "Our.Umbraco.GMaps";

public override object? GetConfigValues(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
{
var oldConfig = base.GetConfigValues(dataTypeProperty, context) as JObject;
if (oldConfig == null) return new JObject();

var config = JObject.FromObject(new
{
location = oldConfig.SelectToken("definition.position.datum") ?? DefaultPosition,
zoom = oldConfig.SelectToken("zoom") ?? 12,
maptype = "roadmap"
});

return config;
}

public override string? GetContentValue(SyncMigrationContentProperty contentProperty, SyncMigrationContext context)
{
var oldStringValue = base.GetContentValue(contentProperty, context);
var oldValue = JObject.Parse(oldStringValue ?? "{}");

var zoom = oldValue.SelectToken("zoom") ?? "12";

var latLng = oldValue.SelectToken("position.datum") ?? DefaultPosition;
var parts = latLng.ToString().Split(',').Select(double.Parse).ToArray();


var newValue = JObject.FromObject(new
{
address = new
{
coordinates = new
{
lat = parts[0],
lng = parts[1]
}
},
mapconfig = new
{
zoom = zoom,
maptype = "roadmap",
centerCoordinates = new
{
lat = parts[0],
lng = parts[1]
}
}
});

return newValue.ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace uSync.Migrations.Migrators.Community.TerraType;

[SyncMigrator("Terratype")]
[SyncDefaultMigrator]
public class TerratypeToOpenStreetmapMigrator : SyncPropertyMigratorBase
{
public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
Expand Down