Skip to content

Commit

Permalink
fixed issues with notification and add replaceOld settings in javascript
Browse files Browse the repository at this point in the history
Added getView : return a bounding box of the current view
  • Loading branch information
SioGabx committed Jul 9, 2023
1 parent 5af4bb4 commit 2557c77
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 44 deletions.
72 changes: 40 additions & 32 deletions MapsInMyFolder.Common/Javascript.Functions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -46,7 +48,6 @@ static public object SetVar(object variablename, object value, bool isglobalvar

static public object GetVar(object variablename, int LayerId = 0)
{
System.Diagnostics.Debug.WriteLine("GetVar + " + variablename.ToString() + " from layer + " + LayerId);
string variablenameString;
if (variablename is null)
{
Expand Down Expand Up @@ -154,6 +155,33 @@ public static Dictionary<string, Dictionary<string, double>> GetSelection()
};
}

public static Dictionary<string, Dictionary<string, double>> GetView()
{
var Middle = Collectif.GetCenterBetweenTwoPoints((Map.CurentView.NO_Latitude, Map.CurentView.NO_Longitude), (Map.CurentView.SE_Latitude, Map.CurentView.SE_Longitude));
return new Dictionary<string, Dictionary<string, double>>
{
{
"SE", new Dictionary<string, double>() {
{"lat",Map.CurentView.SE_Latitude },
{"lng",Map.CurentView.SE_Longitude }
}
},
{
"NO", new Dictionary<string, double>() {
{"lat",Map.CurentView.NO_Latitude },
{"lng",Map.CurentView.NO_Longitude }
}
},
{
"MID", new Dictionary<string, double>() {
{"lat",Middle.Latitude },
{"lng",Middle.Longitude }
}
}
};
}


public static Dictionary<string, int> CoordonneesToTile(object objLatitude, object objLongitude, object objZoom)
{
if (!(int.TryParse(objZoom?.ToString(), out int Zoom)))
Expand Down Expand Up @@ -326,7 +354,7 @@ void Dialog_Closed(object sender, EventArgs e)
}


public static string SendNotification(int LayerId, object texte, object caption = null, object javascriptCallback = null, object notifId = null)
public static string SendNotification(int LayerId, object texte, object caption = null, object javascriptCallback = null, object notifId = null, object doReplaceObj = null)
{
if (LayerId == -2 || LayerId != Layers.Current.class_id)
{
Expand All @@ -335,6 +363,14 @@ public static string SendNotification(int LayerId, object texte, object caption
}
Notification notification = null;

bool doReplace = true;
if (doReplaceObj != null && !bool.TryParse(doReplaceObj.ToString(), out doReplace))
{
PrintError("replaceOld is not a valid boolean.");
}

Debug.WriteLine(doReplace);

void SetupNotification()
{
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
Expand All @@ -349,7 +385,7 @@ void callback()
}
}

notification = new NText(texte.ToString(), caption?.ToString(), "MainPage", callback)
notification = new NText(texte.ToString(), caption?.ToString(), "MainPage", callback, doReplace)
{
NotificationId = NotificationId
};
Expand All @@ -367,35 +403,7 @@ void callback()

static public void Help(int LayerId)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("AIDE");
stringBuilder.AppendLine("À chaque chargement de tuile, la fonction getTile est appelée avec des arguments");
stringBuilder.AppendLine("et doit retourner un objet contenant les remplacements à effectuer.");
stringBuilder.AppendLine("La documentation du logiciel est disponible à cette adresse : ");
stringBuilder.AppendLine("https://github.com/SioGabx/MapsInMyFolder");
stringBuilder.AppendLine("");
stringBuilder.AppendLine("FONCTIONS");
stringBuilder.AppendLine(" - print(string) : Affiche un message dans la console");
stringBuilder.AppendLine(" - printClear() : Efface la console");
stringBuilder.AppendLine(" - cls() : Efface la console");
stringBuilder.AppendLine(" - help() : Affiche cette aide");
stringBuilder.AppendLine(" - setVar(\"nom_variable\",\"valeur\") : Définit la valeur de la variable. Cette variable est conservée durant l'intégralité de l'exécution de l'application");
stringBuilder.AppendLine(" - getVar(\"nom_variable\") : Obtient la valeur de la variable.");
stringBuilder.AppendLine(" - clearVar(\"nom_variable\") : Supprime la variable.");
stringBuilder.AppendLine(" - getTileNumber(latitude, longitude, zoom) : Convertit les coordonnées en tiles");
stringBuilder.AppendLine(" - getLatLong(TileX, TileY, zoom) : Convertit les numéros de tiles en coordonnées");
stringBuilder.AppendLine(" - setSelection(top_latitude, top_longitude, bot_latitude, bot_longitude, zoomToBound) : Définit les coordonnées de la sélection courante");
stringBuilder.AppendLine(" - getSelection() : Obtient les coordonnées de la sélection courante");
stringBuilder.AppendLine(" - alert(\"message\", \"caption\") : Affiche un message à l'écran");
stringBuilder.AppendLine(" - inputbox(\"message\", \"caption\") : Demande une saisie à l'utilisateur");
stringBuilder.AppendLine(" - notification(\"message\", \"caption\", \"callback\", \"notificationId\") : Envoie une notification à l'écran. Un callback peut être attaché et appelé lors du clic sur celle-ci");
stringBuilder.AppendLine(" - refreshMap() : Rafraîchit la carte à l'écran");
stringBuilder.AppendLine(" - clearCache() : Nettoie le cache du calque");
stringBuilder.AppendLine(" - getStyle() : Obtient la valeur du style");
stringBuilder.AppendLine(" - transformLocation(OriginWkt, TargetWkt, projX, projY) : Convertir la position X, Y d'un système de coordonnées vers un autre système (utilise Well Known Text definition)");
stringBuilder.AppendLine(" - transformLocationFromWGS84(TargetWkt, Latitude, Longitude) : Convertir les coordonnées vers un autre système de coordonnées (utilise Well Known Text definition)");

Print(stringBuilder.ToString(), LayerId);
Print(getHelp(), LayerId);
}

static public string Base64Encode(object stringToBeDecoded, int LayerId = -2)
Expand Down
41 changes: 39 additions & 2 deletions MapsInMyFolder.Common/Javascript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using Esprima.Ast;
using Jint;
using Jint.Native;
using MapsInMyFolder.VectorTileRenderer;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -110,10 +112,11 @@ public static Engine SetupFunctions(Engine engine, int LayerId)
engine.SetValue("setSelection", (Action<double, double, double, double, bool>)((NO_Latitude, NO_Longitude, SE_Latitude, SE_Longitude, ZoomToNewLocation) =>
Functions.SetSelection(NO_Latitude, NO_Longitude, SE_Latitude, SE_Longitude, ZoomToNewLocation, LayerId)));
engine.SetValue("getSelection", (Func<object>)(() => Functions.GetSelection()));
engine.SetValue("getView", (Func<object>)(() => Functions.GetView()));
engine.SetValue("alert", (Action<object, object>)((texte, caption) => Functions.Alert(LayerId, texte, caption)));
engine.SetValue("inputbox", (Func<object, object, object>)((texte, caption) => Functions.InputBox(LayerId, texte, caption)));
engine.SetValue("notification", (Func<object, object, object, object, object>)((texte, caption, callback, notifId) =>
Functions.SendNotification(LayerId, texte, caption, callback, notifId)));
engine.SetValue("notification", (Func<object, object, object, object, object, object>)((texte, caption, callback, notifId, doreplace) =>
Functions.SendNotification(LayerId, texte, caption, callback, notifId, doreplace)));
engine.SetValue("refreshMap", (Func<object>)(() =>
{
JavascriptActionEvent?.Invoke(LayerId, JavascriptAction.refreshMap);
Expand All @@ -137,6 +140,40 @@ public static Engine SetupFunctions(Engine engine, int LayerId)
return engine;
}

public static string getHelp()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("AIDE");
stringBuilder.AppendLine("À chaque chargement de tuile, la fonction getTile est appelée avec des arguments");
stringBuilder.AppendLine("et doit retourner un objet contenant les remplacements à effectuer.");
stringBuilder.AppendLine("La documentation du logiciel est disponible à cette adresse : ");
stringBuilder.AppendLine("https://github.com/SioGabx/MapsInMyFolder");
stringBuilder.AppendLine("");
stringBuilder.AppendLine("FONCTIONS");
stringBuilder.AppendLine(" - print(string) : Affiche un message dans la console");
stringBuilder.AppendLine(" - printClear() : Efface la console");
stringBuilder.AppendLine(" - cls() : Efface la console");
stringBuilder.AppendLine(" - help() : Affiche cette aide");
stringBuilder.AppendLine(" - setVar(\"nom_variable\",\"valeur\") : Définit la valeur de la variable. Cette variable est conservée durant l'intégralité de l'exécution de l'application");
stringBuilder.AppendLine(" - getVar(\"nom_variable\") : Obtient la valeur de la variable.");
stringBuilder.AppendLine(" - clearVar(\"nom_variable\") : Supprime la variable.");
stringBuilder.AppendLine(" - getTileNumber(latitude, longitude, zoom) : Convertit les coordonnées en tiles");
stringBuilder.AppendLine(" - getLatLong(TileX, TileY, zoom) : Convertit les numéros de tiles en coordonnées");
stringBuilder.AppendLine(" - setSelection(top_latitude, top_longitude, bot_latitude, bot_longitude, zoomToBound) : Définit les coordonnées de la sélection courante");
stringBuilder.AppendLine(" - getSelection() : Obtient les coordonnées de la sélection courante");
stringBuilder.AppendLine(" - alert(\"message\", \"caption\") : Affiche un message à l'écran");
stringBuilder.AppendLine(" - inputbox(\"message\", \"caption\") : Demande une saisie à l'utilisateur");
stringBuilder.AppendLine(" - notification(\"message\", \"caption\", \"callback\", \"notificationId\", \"replaceOld\") : Envoie une notification à l'écran. Un callback peut être attaché et appelé lors du clic sur celle-ci");
stringBuilder.AppendLine(" - refreshMap() : Rafraîchit la carte à l'écran");
stringBuilder.AppendLine(" - clearCache() : Nettoie le cache du calque");
stringBuilder.AppendLine(" - getStyle() : Obtient la valeur du style");
stringBuilder.AppendLine(" - transformLocation(OriginWkt, TargetWkt, projX, projY) : Convertir la position X, Y d'un système de coordonnées vers un autre système (utilise Well Known Text definition)");
stringBuilder.AppendLine(" - transformLocationFromWGS84(TargetWkt, Latitude, Longitude) : Convertir les coordonnées vers un autre système de coordonnées (utilise Well Known Text definition)");

return stringBuilder.ToString();
}


#region engines
private static readonly Dictionary<int, CancellationTokenSource> JsListCancelTocken = new Dictionary<int, CancellationTokenSource>();
private static readonly Dictionary<int, Engine> ListOfEngines = new Dictionary<int, Engine>();
Expand Down
7 changes: 7 additions & 0 deletions MapsInMyFolder.Common/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ public static class CurentSelection
public static double SE_Latitude;
public static double SE_Longitude;
}
public static class CurentView
{
public static double NO_Latitude;
public static double NO_Longitude;
public static double SE_Latitude;
public static double SE_Longitude;
}
}
}
15 changes: 9 additions & 6 deletions MapsInMyFolder.Common/PageNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ public abstract partial class Notification
public string Destinateur = null;
public bool DisappearAfterAMoment = false;
public bool IsPersistant = false;
public bool replaceOld = true;
protected string Information = "";
protected string Title = "";
protected Action OnClickCallback = null;

public Notification(string Information, string Title, string Destinateur, Action callback = null)
public Notification(string Information, string Title, string Destinateur, Action callback = null, bool doReplace = true)
{
this.Information = Information;
this.Title = Title;
this.OnClickCallback = callback;
this.Destinateur = Destinateur;
this.replaceOld = doReplace;
}

public virtual void Text(string Information = null, string Title = null)
Expand Down Expand Up @@ -101,6 +103,7 @@ public abstract partial class Notification
{
public static class Elements
{

public static Grid ContentGrid(string NotificationId, Action OnClickCallback, Action CloseCallback)
{
Grid ContentGrid = new Grid()
Expand All @@ -110,19 +113,19 @@ public static Grid ContentGrid(string NotificationId, Action OnClickCallback, Ac
};
ContentGrid.RowDefinitions.Add(new RowDefinition());
ContentGrid.ColumnDefinitions.Add(new ColumnDefinition());

ContentGrid.Name = NotificationId;

if (OnClickCallback != null)
{
ContentGrid.MouseLeftButtonUp += ContentGrid_MouseLeftButtonUp;
ContentGrid.MouseLeftButtonDown += ContentGrid_MouseLeftButtonDown;

void ContentGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs o)
void ContentGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs o)
{
o.Handled = true;
CloseCallback();
OnClickCallback();
ContentGrid.MouseLeftButtonUp -= ContentGrid_MouseLeftButtonUp;
ContentGrid.MouseLeftButtonDown -= ContentGrid_MouseLeftButtonDown;

}
}

Expand Down Expand Up @@ -262,7 +265,7 @@ public static ModernWpf.Controls.ProgressBar ContentProgressBar(int ProgressValu

public class NText : Notification
{
public NText(string Information, string Title, string Destinateur, Action callback = null) : base(Information, Title, Destinateur, callback)
public NText(string Information, string Title, string Destinateur, Action callback = null, bool replaceOld = true) : base(Information, Title, Destinateur, callback, replaceOld)
{
}

Expand Down
2 changes: 1 addition & 1 deletion MapsInMyFolder.Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static class Settings
public static bool search_database_update_on_startup = true;

public static SearchEngines search_engine = SearchEngines.OpenStreetMap;
public static Languages.Language application_languages = Languages.Language.English;
public static Languages.Language application_languages = Languages.Language.SystemLanguage;

public static bool editor_autoupdatelayer = true;

Expand Down
7 changes: 7 additions & 0 deletions MapsInMyFolder/LayersPannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MapsInMyFolder.Commun;
using MapsInMyFolder.MapControl;
using ModernWpf.Controls;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
Expand Down Expand Up @@ -661,6 +662,12 @@ public static void DBLayerVisibility(int id, string visibility_state)

public void LayerTilePreview_RequestUpdate()
{
var bbox = mapviewer.ViewRectToBoundingBox(new Rect(0, 0, mapviewer.ActualWidth, mapviewer.ActualHeight));
Commun.Map.CurentView.NO_Latitude = bbox.North;
Commun.Map.CurentView.NO_Longitude = bbox.West;
Commun.Map.CurentView.SE_Latitude = bbox.South;
Commun.Map.CurentView.SE_Longitude = bbox.East;

layer_browser.ExecuteScriptAsyncWhenPageLoaded("UpdatePreview();");
return;
}
Expand Down
8 changes: 6 additions & 2 deletions MapsInMyFolder/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void Layer_searchbar_TextChanged(object sender, TextChangedEventArgs e)
SearchLayerStart();
}

public void UpdateNotification(object sender, (string NotificationId, string Destinateur) NotificationInternalArgs)
public async void UpdateNotification(object sender, (string NotificationId, string Destinateur) NotificationInternalArgs)
{
if (sender is Notification Notif)
{
Expand All @@ -218,6 +218,10 @@ public void UpdateNotification(object sender, (string NotificationId, string Des
Grid ContentGrid = Notif.Get();
if (Collectif.FindChildByName<Grid>(NotificationZone, NotificationInternalArgs.NotificationId) != null)
{
if (Notif.replaceOld == false)
{
return;
}
Grid NotificationZoneContentGrid = Collectif.FindChildByName<Grid>(NotificationZone, NotificationInternalArgs.NotificationId);
NotificationZone.Children.Remove(NotificationZoneContentGrid);
NotificationZone.Children.Insert(Math.Min(Notif.InsertPosition, NotificationZone.Children.Count), ContentGrid);
Expand All @@ -239,8 +243,8 @@ public void UpdateNotification(object sender, (string NotificationId, string Des
void DeleteAfterAnimation(object sender, EventArgs e)
{
ContentGrid?.Children?.Clear();
NotificationZone.Children.Remove(ContentGrid);
ContentGrid = null;
NotificationZone.Children.Remove(ContentGrid);
doubleAnimation.Completed -= DeleteAfterAnimation;
}
doubleAnimation.Completed += DeleteAfterAnimation;
Expand Down
6 changes: 5 additions & 1 deletion MapsInMyFolder/MapLocationSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void MapSearchbarSuggestion_SelectionChanged(object sender, SelectionCha
SetSelection(index);
}

private void SetSelection(int index)
private async void SetSelection(int index)
{
if (index >= 0)
{
Expand All @@ -140,6 +140,10 @@ private void SetSelection(int index)

LayerTilePreview_RequestUpdate();
mapviewer.Cursor = Cursors.Arrow;
await Task.Delay((int)Math.Round(Settings.animations_duration_millisecond * 0.7));
LayerTilePreview_RequestUpdate();
await Task.Delay((int)Math.Round(Settings.animations_duration_millisecond * 0.3));
LayerTilePreview_RequestUpdate();
}
}
}
Expand Down

0 comments on commit 2557c77

Please sign in to comment.