Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:44:25+00:00 2026-06-07T09:44:25+00:00

I am trying to write a module`to load a Stamen tile map under Require.js,

  • 0

I am trying to write a module`to load a Stamen tile map under Require.js, but I’m unsure how to best use it with Require.

If you haven’t seen Stamen maps before, their site is at Stamen Maps.

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 am loading the maps API following modules:

map.js

define(['google!maps/3/sensor=false'], function() { 
  return google.maps;
});

Which has the dependency of google.js

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 issue is that the Stamen maps layers appear to edit the Google Maps instance directly. You can see the Stamen maps implementation here:
http://maps.stamen.com/js/tile.stamen.js?v1.1.1

google.maps.StamenMapType = function(name) {
  //Implementation
}

It seems to rely on the global google.maps object, which is where I believe the issue is coming from.

I’m unsure how to best rewrite the Stamen plugin to be require.js friendly, or if I need to, and I am really keen on using it. Unless I take Google Maps and Stamen out of Require.js and load them normally (like I do with Modernizr) but I’d much prefer to try and do it the Require.js way. If there is such a thing.

Any advice or tips would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:44:27+00:00Added an answer on June 7, 2026 at 9:44 am

    I’m responsible for tile.stamen.js. Sorry for the headache.

    The problem here is that our script needs access to the Google Maps namespace (google.maps) so that it can create the StamenMapType class and have it inherit methods from Google’s ImageMapType. If you absolutely need to use RequireJS (which I wouldn’t suggest, exactly because it makes simple stuff like this awkward), you’ll need to rewrite the whole Google-specific portion of tile.stamen.js (lines 155-177) to look something like this:

    exports.makeStamenMapType = function(name, gmaps) {
        if (!gmaps) gmaps = google.maps;
        var provider = getProvider(name);
        return new gmaps.ImageMapType({
            "getTileUrl": function(coord, zoom) {
                var index = (zoom + coord.x + coord.y) % SUBDOMAINS.length;
                return [
                    provider.url
                        .replace("{S}", SUBDOMAINS[index])
                        .replace("{Z}", zoom)
                        .replace("{X}", coord.x)
                        .replace("{Y}", coord.y)
                ];
            },
            "tileSize": new gmaps.Size(256, 256),
            "name":     name,
            "minZoom":  provider.minZoom,
            "maxZoom":  provider.maxZoom
        });
    };
    

    Then you’d use:

    var toner = makeStamenMapType("toner", gmaps);
    

    where gmaps is your required Google Maps API object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some unit tests for my NetBeans module, but i'm unable
I am trying to write a module in ruby and whenever i use a
I am trying to write a reporting module for my application, the application itself
I am trying to write a generic module to extend the World class. I
I'm trying to write a spellchecker module. It loads a text, creates a dictionary
I am trying to write a custom magento module and i've got it all
I am trying to write a MSBuild logger module which logs information when receiving
currently I am trying to write to an 20x4 LCD Dot-Matrix Module using Perle's
I am trying to write extension methods in VB.NET Imports System.Runtime.CompilerServices Module ExtensionMethods <Extension()>
Getting extremely confused with an adminhtml module i'm trying to write! Effectively I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.