2

I'm trying to use Python's Flask and Javascript to build a web map. So far I've managed to get Flask to perform an SQL query a ZIP, return some coordinates, and for the map to load that location.

Now I'm trying to control the 'visible:' part of the Javascript.

(function (w) {
var map = new ol.Map({
layers: [
         new ol.layer.Tile({
         title: 'Water color',
         visible: true,
         }),
         new ol.layer.Tile({
         title: 'OSM',
         visible: false,
         }),
        ],

        target: 'map',
        view: new ol.View({
        center: ol.proj.transform(w.latLon),
        })
    });
}(window));

Can that be done? The coordinates are passes in via w.latLon. Replacing visible: true, with visible: w.OSM and setting OSM to the string true doesn't seem to do it.

3
  • 2
    Would using 1 and 0 as Boolean substitutes work instead? Commented Jun 16, 2015 at 21:50
  • Nice idea, but doesn't work for me. Set as 0, 1, '0' or '1' it always behaves as true. Interesting (to a complete novice like me) how 1 and 0, when I hardcode them in, behave as true and false. Commented Jun 16, 2015 at 22:19
  • Maybe adding in an intermediate function to parse the Flask output to JavaScript and vice versa would work. Commented Jun 16, 2015 at 22:25

2 Answers 2

2

I had 2 problems. 1) I was failing to declare the variable in my template

2) I had to use this tojson device to stop it just passing a string, which is true

So, in my html template

OSM = {{ OSM|tojson }}

and in the javascript

visible : w.OSM,
Sign up to request clarification or add additional context in comments.

Comments

0

I am a bit late but if anyone's still wondering:

visible: JSON.parse('{{ w.OSM|tojson }}');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.