[OpenLayers-Users] OpenLayers error - template.replace is not a function

Leigh Holcombe lholcombe at triple-bypass.net
Fri Feb 25 05:52:20 EST 2011


On Feb 25, 2011, at 12:32 AM, <christopher.schmidt at nokia.com> wrote:

> 
> On Feb 25, 2011, at 11:25 AM, ext Leigh Holcombe wrote:
> 
>> Hello,
>> I'm a new user of OpenLayers, with not much JavaScript or Ajax programming experience.  I thought I was starting to get the hang of the API, but then I came across an error.  This error shows up in the Firefox error console, and an empty map-sized container is shown:
>> 
>> template.replace is not a function
>> http://www.openlayers.org/api/OpenLayers.js
>> Line: 102
>> 
>> Can anyone shed some light on what might be causing this?  My humble code, relying heavily on various samples and tutorials, is below:
> 
> The OSM layer is a subclass of XYZ, and therefore has a constructor that 
> takes three options:
> 
> Parameters
> name	{String}
> url	{String}
> options	{Object} Hashtable of extra options to tag onto the layer
> 
> You have passed an object to the second option (url), and when it
> tries to call the template replacement on that non-string, you get
> an error. 
> 
> Since the OSM layer is already a sphericalMercator layer, you can
> simply remove the second argument to your OSM layer, and this should
> solve this problem.
> 
> -- Chris
> 
>> function init() {
>> 
>> Proj4js.defs["EPSG:26904"]="+proj=utm +zone=4 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";
>> var x = 626910.977254;
>> var y = 2358256.879039;
>> var mercator = new Proj4js.Proj("EPSG:90013");
>> var utm4n = new Proj4js.Proj("EPSG:26904");
>> var map = new OpenLayers.Map('testmap', {projection: mercator});
>> var osm = new OpenLayers.Layer.OSM('osmlayer', {sphericalMercator: true});
>> var point = new Proj4js.Point(x,y);
>> map.addLayer(osm);
>> map.addControl(new OpenLayers.Control.PanZoomBar());
>> map.setCenter(Proj4js.transform(utm4n, mercator, point));
>> map.zoomTo(15);
>> }
>> 
>> Regards,
>> Leigh Holcombe


Thanks, Chris.  I modified the line in question, it now reads:

var osm = new OpenLayers.Layer.OSM('osmlayer');

Good news is that this cleared the template.replace error.  Unfortunately, I am still getting an empty map.





More information about the Users mailing list