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

map: доработки #2

Open
6 of 12 tasks
sipayRT opened this issue Mar 16, 2015 · 5 comments
Open
6 of 12 tasks

map: доработки #2

sipayRT opened this issue Mar 16, 2015 · 5 comments

Comments

@sipayRT
Copy link
Contributor

sipayRT commented Mar 16, 2015

Я наконец снова добрался до кода

Что сделал:

  • Разобрался с инфраструктурой (не очень красиво, но работает)
  • Переименовал блок ymaps -> map-helper
  • Добавил стандартное значение zoom
  • (ymaps) Добавил возможность указывать тип карты
  • (ymaps) Теперь геообъекты поддерживают все свои опции из апи в bemjson'e
  • Разбил примеры, по вендорному признаку

Что нужно сделать

  • Покрыть код тестами
  • Написать документацию
  • Доделать подключение google maps
  • bh шаблон

С чем испытываю проблемы

  • Загрузка API Google Maps,
    Отправляю правильный урл в loader_type_js
    получаю в ответ ошибку
     Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened. 
  • Еще мне не очень нравится как сделан map.bemhtml, есть идеи как сделать красивее
@h4
Copy link

h4 commented Jun 26, 2015

Я сейчас столкнулся с загрузкой GoogleMaps и сделал пока что так:

modules.define('i-googlemaps', ['loader_type_js', 'i-googlemaps__config', 'identify'],
    function(provide, loader, config, identify) {
        var win = this.global,
            apiLoadCallback = 'googleMapsLoadCallback__' + identify(),
            loaderUrl = config.url + apiLoadCallback;

        /* global google.maps */
        function doProvide() {
            /**
             * @exports
             * @type Function
             */
            provide(google.maps);
        }

        win[apiLoadCallback] = function() {
            doProvide();
        };

        typeof google !== 'undefined' && typeof google.maps !== 'undefined' ?
            doProvide() :
            loader(loaderUrl);
    });

@redhedg
Copy link

redhedg commented Sep 9, 2015

Привет, подключил по Вашему методу блок i-googlemaps, но почему-то вылетает ошибка в консоли: Uncaught TypeError: window.initializegoogleMapsLoadCallback__uniq1 is not a function
Вот файл i-googlemaps__config:

modules.define('i-googlemaps__config', function(provide) {
provide(/** @exports */{
    /**
     * URL for loading GoogleMapsApi if it does not exist
     */
    url : '//maps.googleapis.com/maps/api/js?v=3&sensor=false&callback=initialize'
});
});

Весь код блока подключения здесь: https://github.com/redhedg/i-googlemaps

Что я делаю не так? Помогите пожалуйста разобраться.

@h4
Copy link

h4 commented Sep 9, 2015

Апи Google Maps возвращате код как jsonp (ну или типа того), поэтому значением параметра callback должно быть имя нашей функции. Поэтому, собственно, мы собираем loaderUrl конкатенацией.

Попробуйте изменить i-googlemaps__config на такой:

modules.define('i-googlemaps__config', function(provide) {
    provide(/** @exports */ {
        /**
         * URL for loading GoogleMaps API if it does not exist
         */
        url: '//maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false&callback='
    });
});

@redhedg
Copy link

redhedg commented Sep 9, 2015

Спасибо большое, все заработало!

@h4
Copy link

h4 commented Sep 9, 2015

Отлично! Хотя сейчас мне кажется, что лучше сделать так для большей очевидности:

i-googlemaps__config.js

modules.define('i-googlemaps__config', function(provide) {
    provide(/** @exports */ {
        /**
         * URL for loading GoogleMaps API if it does not exist
         */
        url: function(callbackName) {
            return '//maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false&callback=' + callbackName;
        }
    });
});

i-googlemaps.js

modules.define('i-googlemaps', ['loader_type_js', 'i-googlemaps__config', 'identify'],
    function(provide, loader, config, identify) {
        var win = this.global,
            apiLoadCallback = 'googleMapsLoadCallback__' + identify(),
            loaderUrl = config.url(apiLoadCallback);

        /* global google.maps */
        function doProvide() {
            /**
             * @exports
             * @type Function
             */
            provide(google.maps);
        }

        win[apiLoadCallback] = function() {
            doProvide();
        };

        typeof google !== 'undefined' && typeof google.maps !== 'undefined' ?
            doProvide() :
            loader(loaderUrl);
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants