I'm trying to write a module to load the Stamen tile map in the Require.js section, but I'm not sure how to best use it with Require.
If you have not seen Stamen cards, their site is on Open Cards .
This is the code for the map view, view.js
define([ 'jquery', 'underscore', 'backbone', 'maps', 'text!templates/map/view.html' ], function($, _, Backbone, maps, mapTemplate){ var mapView = Backbone.View.extend({ el: $(".map"), displayMap: function() { this.options = { center: new maps.LatLng(-37.8, 144.9), zoom: 11, mapTypeId: google.maps.MapTypeId.ROADMAP, scrollwheel: false }; this.render(); }, render: function(){ var compiledTemplate = _.template(mapTemplate); var $el = $(this.el); $el.html(compiledTemplate); this.map = new maps.Map($el.find('.map').get(0), this.options); } }); return new mapView; });
I load the map API of the following modules:
map.js
define(['google!maps/3/sensor=false'], function() { return google.maps; });
Who has a google.js dependency
define(['http://www.google.com/jsapi?key=THE_API_KEY&callback=define'], { load: function( name, req, load, config ) { if (config.isBuild) { onLoad(null); } else { var request = name.split('/'); google.load(request[0], request[1], { callback: load, language: 'en', other_params: ((typeof request[2] === 'string')?request[2]:'') }); } } });
The problem is that the Stamen map layers directly display an instance of Google Maps. Here you can see the implementation of the excavation cards: http://maps.stamen.com/js/tile.stamen.js?v1.1.1
google.maps.StamenMapType = function(name) {
It seems to be relying on the google.maps global object, from where I believe the problem is coming from.
I'm not sure how best to rewrite the Stamen plugin to be require.js friendly, or if I need it, and I really really like to use it. If I donโt take Google Maps and pop out of Require.js and load them normally (for example, I do it with Modernizr), but I would prefer to try and do it using the Require.js method. If there is such a thing.
Any advice or advice would be highly appreciated.