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

No value provided for variable {s} #1871

Closed
delister opened this issue Jul 16, 2013 · 12 comments
Closed

No value provided for variable {s} #1871

delister opened this issue Jul 16, 2013 · 12 comments
Assignees
Labels
Milestone

Comments

@delister
Copy link

When submit form not validate this error: No value provided for variable {s} leaflet-src.js:142

code:
template: function (str, data) {
return str.replace(/{ *([\w_]+) *}/g, function (str, key) {
var value = data[key];
if (value === undefined) {
142 line: throw new Error('No value provided for variable ' + str);
Uncaught Error: No value provided for variable {s}
} else if (typeof value === 'function') {
value = value(data);
}
return value;
});
},

@mourner
Copy link
Member

mourner commented Jul 16, 2013

What form, submitted where? Closed as incomprehensible. Please try reading bug reporting guidelines before submitting.

@mourner mourner closed this as completed Jul 16, 2013
@delister
Copy link
Author

There is a page with a form. In this form the output card. I deduce map:
map = L.map('ffield-map').setView([ll.lat, ll.lon], zoom);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: 'OpenStreetMap.',
maxZoom: 18,
}).addTo(map);
this code is executed twice. The first time a user comes to this page. The second time the user is not correctly filled out the form and clicked on the submit. The page reloads and displays an error message and the same form. The error occurs here:
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: 'OpenStreetMap.',
maxZoom: 18,
}).addTo(map);

@mourner
Copy link
Member

mourner commented Jul 16, 2013

I don't understand what's going on. Could you please set up a JSFiddle test case that reproduces the problem?

@ekaitzht
Copy link

I have the same problem when try use map.setView or map.panTo. :(

@mourner
Copy link
Member

mourner commented Jul 25, 2013

@ekaitzht please read how to submit a proper bug report here: https://github.com/Leaflet/Leaflet/blob/master/CONTRIBUTING.md#reporting-bugs

@TheIrishman
Copy link

Not sure if anyone else has had this issue when upgrading, but I hit it.

It appears that there is no longer any default zoom factor, so if you try calling setView without setting any zoom factor, then bang! it falls. The error message is a complete red herring.

Anyhow, if you just set any zoom factor then this should fix that issue.

There might, of course, be other causes of this, but anyone upgrading from a version with a working default zoom factor may well hit this one, and it is anything but obvious as to what is going wrong.

So if this helps someone, then great.

Cheers

@mourner
Copy link
Member

mourner commented Jan 2, 2014

@TheIrishman not sure I understand, could you set up a minimal JSFiddle that reproduces the issue?

@TheIrishman
Copy link

Hi mourner,

It is not that easy to produce a test case, and I don't use JSfiddle, but, when onLocationFound is triggered if there has been no call made to setZoom then when a call is made to setView leaflet.js will fail with the given error.

When walking through the code, I found that _adjustTilePoint failed because the zoom factor was not set.

Within this function this line: size = crs.getSize(this._map.getZoom()) returned NaN, as there was no default zoomfactor set.

By calling setZoom before calling setView the problem disappeared.

In the old version of leaflet.js (from about 2 years ago) this value was defaulted to, I think, 15 (e.g. the whole world).

Either way, no exception was raised when calling setView before setting the zoomfactor in the old version of leaflet.js.

My old code that threw the exception looked like this:

function onLocationFound(e)
{
map.setView(new L.LatLng(my.lat, my.lng))
...

And the new working code looks like this:

function onLocationFound(e)
{
if(firstSet)
{
curZm=15
map.setZoom(curZm)
firstSet=false
}
map.setView(new L.LatLng(my.lat, my.lng))
...

If you would like more details then let me know.

Hope that helps to clarify the situation.

Cheers

Liam Carton

PS. I am using leaflet.js to implement the mapping functions inside TribalContact (an encrypted web chat application). And I am deeply appreciative of the work you guys do. I do hope my post is not seen as some kind of criticism. I just want to help others who perhaps get stuck with issues like this. You guys have done a fantastic job with leaflet, and all credit to you for your efforts. Keep up the great work.
If you would like to give my app a try I would be deeply honoured.

@delister delister changed the title No value provided for variable {s} No value provided for variable {s} Apr 1, 2014
@jcheek
Copy link

jcheek commented May 14, 2014

Here's a code snippet that reproduces this bug:

var map = L.map('leafmap',
    {
      maxBounds: [
          [38.5336, -90.3222],
          [38.7278, -90.1780]
        ],
      zoom: 11
    }
  ).setView([38.64, -90.24]);

The docs state that zoom is optional, but it's not... if you don't set a zoom in setView(), you get the Error: No value provided for variable {s} bug.

Here's what you have to do:

var map = L.map('leafmap',
    {
      maxBounds: [
          [38.5336, -90.3222],
          [38.7278, -90.1780]
        ],
      zoom: 11
    }
  ).setView([38.64, -90.24], 11);

Note the addition of the '11' as a parameter to setView() in the working code.

@campeterson
Copy link

I had the same issue: Error: No value provided for variable {s}

It didn't set the zoom in setView()

Solved it by @jcheek method mentioned above.

@mourner mourner reopened this Jun 2, 2014
@mourner mourner added this to the 1.0-beta milestone Jun 2, 2014
@AndriiHeonia
Copy link
Contributor

Fixed: https://github.com/Leaflet/Leaflet/pull/2844/files
@mourner, can you review this fix? @Gaidamak, can you test it with different (zoom, maxZoom, minZoom, etc.) options?

mourner added a commit that referenced this issue Aug 11, 2014
issue #1871 fixed, set this._zoom on map init whenever options.zoom is provided
@mourner mourner modified the milestones: 1.0-beta1, 1.0-beta Oct 31, 2014
@jfirebaugh jfirebaugh self-assigned this Nov 5, 2014
jfirebaugh added a commit that referenced this issue Nov 5, 2014
@jfirebaugh
Copy link
Member

This is not reproducible on current master.

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

No branches or pull requests

8 participants