From 30ebf71c153ade22338ac7fb389d0ff593dc114d Mon Sep 17 00:00:00 2001 From: Per Ploug Date: Tue, 11 Jun 2013 17:30:00 +0200 Subject: [PATCH] Google maps editor --- .../Js/googlemaps.controller.js | 78 +++++++++++++++++++ .../PropertyEditors/Views/googlemaps.html | 3 + .../App_Plugins/GoogleMaps/package.manifest | 19 +++++ .../App_Plugins/Umbraco/Package.manifest | 8 +- 4 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js create mode 100644 src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html create mode 100644 src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest diff --git a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js new file mode 100644 index 0000000000..707e084840 --- /dev/null +++ b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js @@ -0,0 +1,78 @@ +define(['app', 'angular'], function (app, angular) { + +angular.module("umbraco") +.controller("Umbraco.Editors.GoogleMapsController", + function ($rootScope, $scope, notificationsService, dialogService, $log, $timeout) { + + require( + [ + 'async!http://maps.google.com/maps/api/js?sensor=false' + ], + function () { + + //Google maps is available and all components are ready to use. + //var valueArray = $scope.model.value.split(','); + var latLng = new google.maps.LatLng(-34.397, 150.644); + + var mapDiv = document.getElementById($scope.model.alias + '_map'); + var mapOptions = { + zoom: 4, + center: latLng, + mapTypeId: google.maps.MapTypeId.ROADMAP + }; + + var geocoder = new google.maps.Geocoder(); + var map = new google.maps.Map(mapDiv, mapOptions); + + google.maps.event.addListener(map, 'click', function(event) { + + dialogService.mediaPicker({scope: $scope, callback: function(data){ + var image = data.selection[0].src; + + var latLng = event.latLng; + var marker = new google.maps.Marker({ + map: map, + icon: image, + position: latLng, + draggable: true + }); + + google.maps.event.addListener(marker, "dragend", function(e){ + var newLat = marker.getPosition().lat(); + var newLng = marker.getPosition().lng(); + + codeLatLng(marker.getPosition()); + + //set the model value + $scope.model.value = newLat + "," + newLng; + + }); + + }}); + }); + + + function codeLatLng(latLng) { + geocoder.geocode({'latLng': latLng}, + function(results, status) { + if (status == google.maps.GeocoderStatus.OK) { + var location = results[0].formatted_address; + $rootScope.$apply(function () { + notificationsService.success("Peter just went to: ", location); + }); + } + }); + } + + //hack to hook into tab switching for map resizing + $('a[data-toggle="tab"]').on('shown', function (e) { + google.maps.event.trigger(map, 'resize'); + }); + + } + ); +}); + +return angular; + +}); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html new file mode 100644 index 0000000000..6c5f0b74d7 --- /dev/null +++ b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html @@ -0,0 +1,3 @@ +
+
+
\ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest new file mode 100644 index 0000000000..de862448fe --- /dev/null +++ b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest @@ -0,0 +1,19 @@ +{ + propertyEditors: [ + { + id: "0BA0F832-D759-4526-9B3E-94BBFC98F82E", + name: "Google Maps", + editor: { + view: "~/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html" + } + } + ], + config: { + paths: { + 'googleMapsController': '~/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller' + } + }, + init: [ + 'googleMapsController' + ] +} \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/Umbraco/Package.manifest b/src/Umbraco.Web.UI/App_Plugins/Umbraco/Package.manifest index 93c2fd95b3..cd70184bff 100644 --- a/src/Umbraco.Web.UI/App_Plugins/Umbraco/Package.manifest +++ b/src/Umbraco.Web.UI/App_Plugins/Umbraco/Package.manifest @@ -4,14 +4,14 @@ id: "ec15c1e5-9d90-422a-aa52-4f7622c63bea", name: "Textstring", editor: { - view: "~/umbraco/Views/propertyeditors/umbraco/textstring/editor.html" + view: "~/umbraco/Views/propertyeditors/umbraco/textstring/editor.html" } }, { id: "67db8357-ef57-493e-91ac-936d305e0f2a", - name: "textarea", + name: "Textarea", editor: { - view: "~/umbraco/Views/propertyeditors/umbraco/textarea/editor.html" + view: "~/umbraco/Views/propertyeditors/umbraco/textarea/editor.html" } }, { @@ -22,7 +22,7 @@ } }, { - id: "67db8357-ef57-493e-91ac-936d305e0f2a", + id: "7e062c13-7c41-4ad9-b389-41d88aeef87c", name: "Content Picker", editor: { view: "~/umbraco/Views/propertyeditors/umbraco/contentpicker/editor.html"