Skip to content
Permalink
Browse files

#138:

- Added GoogleApiKey property and CustomGetGoogleApiKey event to the MapViewWebModule
- Added .editorconfig
  • Loading branch information...
derjabkin committed Aug 10, 2018
1 parent 6801dee commit a2f073bd5bfc2ba3f70fc440ccaeb89a66ad9d06
Showing with 28 additions and 2 deletions.
  1. +6 −0 .editorconfig
  2. +22 −2 Xpand/Xpand.ExpressApp.Modules/MapView.Web/MapViewWebModule.cs
@@ -0,0 +1,6 @@
[*.{js,cs}]
csharp_new_line_before_open_brace = none
indent_style = space
# .net code style settings:
[*.{cs,vb}]
dotnet_sort_system_directives_first = true
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
@@ -11,6 +12,8 @@ namespace Xpand.ExpressApp.MapView.Web {
[ToolboxItem(true)]
[ToolboxTabName(XpandAssemblyInfo.TabAspNetModules)]
public sealed class MapViewWebModule : XpandModuleBase {

public event EventHandler<CustomGetApiKeyEventArgs> CustomGetGoogleApiKey;
public MapViewWebModule() {
RequiredModuleTypes.Add(typeof(MapViewModule));
XpandLayoutManager.RegisterListControlAdapter(typeof(MapControl), typeof(GoogleMapListControlAdapter));
@@ -21,17 +24,34 @@ public sealed class MapViewWebModule : XpandModuleBase {
Application.CustomizeTemplate += Application_CustomizeTemplate;
}

public string GoogleApiKey { get; set; }
void Application_CustomizeTemplate(object sender, CustomizeTemplateEventArgs e) {
var page = e.Template as Page;
if (page != null)
page.ClientScript.RegisterClientScriptInclude("GoogleMaps", "https://maps.googleapis.com/maps/api/js?v=3.13&sensor=false");
if (page != null) {
CustomGetApiKeyEventArgs customGetApiKeyEventArgs = new CustomGetApiKeyEventArgs();
CustomGetGoogleApiKey?.Invoke(this, customGetApiKeyEventArgs);
string apiKey = customGetApiKeyEventArgs.ApiKey;
if (string.IsNullOrWhiteSpace(apiKey))
apiKey = GoogleApiKey;

UriBuilder uriBuilder = new UriBuilder("https://maps.googleapis.com/maps/api/js?v=3.13&sensor=false");
if (!string.IsNullOrWhiteSpace(apiKey))
uriBuilder.Query += "&key=" + apiKey;

page.ClientScript.RegisterClientScriptInclude("GoogleMaps", uriBuilder.Uri.ToString());
}
}
protected override void RegisterEditorDescriptors(List<EditorDescriptor> editorDescriptors) {
editorDescriptors.Add(new ListEditorDescriptor(new AliasRegistration("MapListEditor", typeof(object), false)));
editorDescriptors.Add(new ListEditorDescriptor(new EditorTypeRegistration("MapListEditor", typeof(object), typeof(MapListEditor), false)));
}
}


public class CustomGetApiKeyEventArgs : EventArgs {
public string ApiKey { get; set; }
}

public class GoogleMapListControlAdapter : ListControlAdapterBase<MapControl> {

public override string CreateSetBoundsScript(string widthFunc, string heightFunc) {

0 comments on commit a2f073b

Please sign in to comment.
You can’t perform that action at this time.