From 77bcefb5e267538c585a5297a5d3ac2453621985 Mon Sep 17 00:00:00 2001 From: Herve PUSSET Date: Thu, 6 Jun 2019 17:58:52 +0200 Subject: [PATCH 1/3] remove default location and fix zoom level --- djangocms_maps/static/djangocms_maps/js/bingmaps.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/djangocms_maps/static/djangocms_maps/js/bingmaps.js b/djangocms_maps/static/djangocms_maps/js/bingmaps.js index d122e35..e783c9d 100644 --- a/djangocms_maps/static/djangocms_maps/js/bingmaps.js +++ b/djangocms_maps/static/djangocms_maps/js/bingmaps.js @@ -51,7 +51,6 @@ djangocms.Maps = { var that = this; var container = instance; var data = container.data(); - var options = { credentials: data.api_key, navigationBarMode: Microsoft.Maps.NavigationBarMode.compact, @@ -64,9 +63,7 @@ djangocms.Maps = { showMapTypeSelector: data.layers_control, showScalebar: data.scale_bar, styles: data.style, - center: new Microsoft.Maps.Location(46.94708, 7.445975) // default to switzerland; }; - var map = new Microsoft.Maps.Map(container[0], options); // latitute or longitute have precedence over the address when provided @@ -88,13 +85,12 @@ djangocms.Maps = { bounds: map.getBounds(), where: data.address, callback: function (answer, userData) { - map.setView({ bounds: answer.results[0].bestView }); - that.addMarker(map, answer.results[0].location, data); - // use user-set zoom level for displaying result - var options = map.getOptions(); - options.zoom = data.zoom; + var options = Object.assign(map.getOptions(), { + center: answer.results[0].location + }); map.setView(options); + that.addMarker(map, answer.results[0].location, data); } }; searchManager.geocode(requestOptions); From 780803482baa13309be682161eed0e482440593d Mon Sep 17 00:00:00 2001 From: Herve PUSSET Date: Fri, 7 Jun 2019 14:05:42 +0200 Subject: [PATCH 2/3] Refactoring JavaScript and remove maps_title template --- .../static/djangocms_maps/js/bingmaps.js | 103 +++++++++--------- .../templates/djangocms_maps/maps.html | 9 +- .../templates/djangocms_maps/maps_title.html | 1 - 3 files changed, 56 insertions(+), 57 deletions(-) delete mode 100644 djangocms_maps/templates/djangocms_maps/maps_title.html diff --git a/djangocms_maps/static/djangocms_maps/js/bingmaps.js b/djangocms_maps/static/djangocms_maps/js/bingmaps.js index e783c9d..e8f8b35 100644 --- a/djangocms_maps/static/djangocms_maps/js/bingmaps.js +++ b/djangocms_maps/static/djangocms_maps/js/bingmaps.js @@ -15,67 +15,52 @@ var djangocms = window.djangocms || {}; * @class Maps * @namespace djangocms */ - djangocms.Maps = { - options: { - container: '.djangocms-maps-container' - }, + container: '.djangocms-maps-container', + options: {}, /** * Initializes all Map instances. * * @method init - * @private * @param {Object} opts overwrite default options */ - init: function init(opts) { - var that = this; - var options = $.extend(true, {}, this.options, opts); - + init: function () { // loop through every instance - var containers = $(options.container); - containers.each(function (index, container) { - that._loadMap($(container)); + var _this = this; + $(this.container).each(function (index, container) { + _this.initializeMap($(container)); }); }, /** * Loads a single Map instance provided by ``init``. * - * @method _loadMap - * @private + * @method initializeMap * @param {jQuery} instance jQuery element used for initialization */ - _loadMap: function _loadMap(instance) { - var that = this; - var container = instance; - var data = container.data(); - var options = { - credentials: data.api_key, - navigationBarMode: Microsoft.Maps.NavigationBarMode.compact, - showLocateMeButton: false, - zoom: data.zoom, - disableScrollWheelZoom: !data.scrollwheel, - disableZooming: !data.double_click_zoom && !data.scrollwheel, - disablePanning: !data.draggable, - showZoomButtons: data.zoom_control, - showMapTypeSelector: data.layers_control, - showScalebar: data.scale_bar, - styles: data.style, - }; - var map = new Microsoft.Maps.Map(container[0], options); - - // latitute or longitute have precedence over the address when provided - // inside the plugin form - data.lat = data.lat.toString(); - data.lng = data.lng.toString(); - if (data.lat.length && data.lng.length) { - var coords = { - lat: parseFloat(data.lat.replace(',', '.')), - lng: parseFloat(data.lng.replace(',', '.')) - }; - var location = new Microsoft.Maps.Location(coords.lat, coords.lng); + initializeMap: function ($container) { + var _this = this, + data = $container.data(), + options = { + credentials: data.api_key, + navigationBarMode: Microsoft.Maps.NavigationBarMode.compact, + showLocateMeButton: false, + zoom: data.zoom, + disableScrollWheelZoom: !data.scrollwheel, + disableZooming: !data.double_click_zoom && !data.scrollwheel, + disablePanning: !data.draggable, + showZoomButtons: data.zoom_control, + showMapTypeSelector: data.layers_control, + showScalebar: data.scale_bar, + styles: data.style + }, + map = new Microsoft.Maps.Map($container[0], options); + + if (data.latlng) { + var location = Microsoft.Maps.Location.parseLatLong(data.latlng); + this.displayMap(map, location); this.addMarker(map, location, data); } else { // load latlng from given address @@ -86,11 +71,8 @@ djangocms.Maps = { where: data.address, callback: function (answer, userData) { // use user-set zoom level for displaying result - var options = Object.assign(map.getOptions(), { - center: answer.results[0].location - }); - map.setView(options); - that.addMarker(map, answer.results[0].location, data); + _this.displayMap(map, answer.results[0].location); + _this.addMarker(map, answer.results[0].location, data); } }; searchManager.geocode(requestOptions); @@ -98,15 +80,29 @@ djangocms.Maps = { } }, + /** + * Display a single Map instance provided by ``initinitlizeMap``. + * + * @method displayMap + * @param {Microsoft.Maps.Map} map instance + * @param {Microsoft.Maps.Location} location instance + */ + displayMap: function (map, location) { + var options = map.getOptions(); + options.center = location; + map.setView(options); + }, + /** * Adds a marker to a Map instance. * * @method addMarker - * @param {jQuery} map ``Microsoft.Maps.Map`` instance - * @param {jQuery} location ``Microsoft.Maps.Location`` instance - * @param {jQuery} data the data objects from a Map instance + * @param {Microsoft.Maps.Map} map instance + * @param {Microsoft.Maps.Location} location instance + * @param {Object} data the data objects from a Map instance */ - addMarker: function addMarker(map, location, data) { + + addMarker: function (map, location, data) { var pushpin = new Microsoft.Maps.Pushpin(location, null); if (data.show_infowindow) { @@ -120,10 +116,11 @@ djangocms.Maps = { title: data.title, description: windowContent }); + infobox.setMap(map); Microsoft.Maps.Events.addHandler(pushpin, 'click', function () { - infobox.setOptions({ visible: true }); + infobox.setOptions({visible: true}); }); } diff --git a/djangocms_maps/templates/djangocms_maps/maps.html b/djangocms_maps/templates/djangocms_maps/maps.html index 2d7a783..bd92b49 100644 --- a/djangocms_maps/templates/djangocms_maps/maps.html +++ b/djangocms_maps/templates/djangocms_maps/maps.html @@ -1,6 +1,8 @@ {% load i18n %}{% get_current_language as LANGUAGE_CODE %}
- {% include "djangocms_maps/maps_title.html" %} + {% if object.title %} +

{{ object.title }}

+ {% endif %}
{{ object.title }}{% endif %} From 808f8c22f36fbb400e1480dc1ae91b830eabc7b5 Mon Sep 17 00:00:00 2001 From: Herve PUSSET Date: Fri, 7 Jun 2019 14:16:42 +0200 Subject: [PATCH 3/3] Bump to version 0.12.0 --- CHANGELOG.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 132ed95..a064fa8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ CHANGELOG ========= +0.12.0 (2019-06-07) +------------------- +- Fix Bing Maps zoom +- Remove map_title template +- Use Bing Maps API to convert latitude and longitude + 0.11.0 (2019-05-08) -------------------