]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/osm_plugin_error_TypeError:_mapProjection_is_null.mdwn
Merge remote-tracking branch 'spalax/calendar-autocreate'
[ikiwiki.git] / doc / bugs / osm_plugin_error_TypeError:_mapProjection_is_null.mdwn
1 [[!template  id=gitbranch branch=cbaines/osm-layers-patch author="[[cbaines]]"]]
2
3 Using the osm plugin with a simple \[[!osm]] directive does not seem to work, a "TypeError: mapProjection is null" is given. I believe this is because the client side Javascript uses the options.layers, which is always Null. 
4
5 [[!tag patch]]
6 I have produced a patch for this issue, but beware, while it appears to fix the problem for me, I have little understanding of perl and the existing code base.
7
8 > It looks sound, but I have yet to test it. --[[anarcat]]
9
10 >> I reviewed a version of this (possibly rebased or modified or something)
11 >> that was in the [[todo/osm_plugin_GeoJSON_popup_patch]] branch,
12 >> over on the todo page for that branch. Feel free to move my
13 >> review comments for it here if you want to split the discussion. --[[smcv]]
14 >> [[!tag reviewed]]
15
16 Here's [[smcv]]'s review from [[todo/osm_plugin_GeoJSON_popup_patch]], annotated with my comments. --[[anarcat]]
17
18 > It would be good if the commit added documentation for the new feature,
19 > probably in `doc/ikiwiki/directive/osm.mdwn`.
20 >
21 >     + my @layers = [ 'OSM' ];
22 >
23 > You mean `$layers`. `[]` is a scalar value (a reference to an array);
24 > `@something` is an array.
25
26 >> Or `@layers = ( 'OSM' );`. --[[anarcat]]
27
28 >>> Yeah, and then `layers => [@layers]` or `layers => \@layers`
29 >>> to turn it into a reference when building `%options`. --s
30
31 >     +         @layers = [ split(/,/, $params{layers}) ];
32 >
33 > Is comma-separated the best fit here? Would whitespace, or whitespace and/or
34 > commas, work better?
35
36 >> Why don't we simply keep it an array as it already is? I fail to see the reason behind that change.
37 >>
38 >>> This seems to be at least partially a feature request for \[[!osm]]:
39 >>> "allow individual \[[!osm]] maps to override `$config{osm_layers}`.
40 >>> Items in `%config` can be a reference to an array, so that's fine.
41 >>> However, parameters to a [[ikiwiki/directive]] cannot be an array,
42 >>> so for the directive, we need a syntax for taking a scalar parameter
43 >>> and splitting it into an array - comma-separated, whitespace-separated,
44 >>> whatever. --s
45 >>
46 >> This is the config I use right now on http://reseaulibre.ca/:
47 >> 
48 >> ~~~~
49 >> osm_layers:
50 >> - http://a.tile.stamen.com/toner/${z}/${x}/${y}.png
51 >> - OSM
52 >> - GoogleHybrid
53 >> ~~~~
54 >> 
55 >> It works fine. At the very least, we should *default* to the configuration set in the the .setup file, so this chunk of the patch should go:
56 >> 
57 >> ~~~~
58 >> -        $options{'layers'} = $config{osm_layers};
59 >> ~~~~
60 >> 
61 >> Maybe the best would be to use `$config{osm_layers};` as a default? --[[anarcat]]
62
63 > It's difficult to compare without knowing what the values would look like.
64 > What would be valid values? The documentation for `$config{osm_layers}`
65 > says "in a syntax acceptable for OpenLayers.Layer.OSM.url parameter" so
66 > perhaps:
67 >
68 >     # expected by current branch
69 >     \[[!osm layers="OSM,WTF,OMG"]]
70 >     \[[!osm layers="http://example.com/${z}/${x}/${y}.png,http://example.org/tiles/${z}/${x}/${y}.png"]]
71 >     # current branch would misbehave with this syntax but it could be
72 >     made to work
73 >     \[[!osm layers="OSM, WTF, OMG"]]
74 >     \[[!osm layers="""http://example.com/${z}/${x}/${y}.png,
75 >       http://example.org/tiles/${z}/${x}/${y}.png"""]]
76 >     # I would personally suggest whitespace as separator (split(' ', ...))
77 >     \[[!osm layers="OSM WTF OMG"]]
78 >     \[[!osm layers="""http://example.com/${z}/${x}/${y}.png
79 >       http://example.org/tiles/${z}/${x}/${y}.png"""]]
80 >
81 > If you specify more than one layer, is it like "get tiles from OpenCycleMap
82 > server A or B or C as a round-robin", or "draw OpenCycleMap and then overlay
83 > county boundaries and then overlay locations of good pubs", or what?
84
85 >> Multiple layers support means that the user is shown the first layer by default, but can also choose to flip to another layer. See again http://reseaulibre.ca/ for an example. --[[anarcat]]
86
87 >     +         layers => @layers,
88 >
89 > If @layers didn't have exactly one item, this would mess up argument-parsing;
90 > but it has exactly one item (a reference to an array), so it works.
91 > Again, if you replace @layers with $layers throughout, that would be better.
92 >
93 >     -        $options{'layers'} = $config{osm_layers};
94 >
95 > Shouldn't the default if no `$params{layers}` are given be this, rather
96 > than a hard-coded `['OSM']`?
97
98 >> Agreed. --[[anarcat]]
99
100 > `getsetup()` says `osm_layers` is `safe => 0`, which approximately means
101 > "don't put this in the web UI, changing it could lead to a security flaw
102 > or an unusable website". Is that wrong? If it is indeed unsafe, then
103 > I would expect changing the same thing via \[[!osm]] parameters to be
104 > unsafe too.
105
106 >> I put that at `safe=>0` as a security precaution, because I didn't
107 >> exactly know what that setting did.
108 >> 
109 >> It is unclear to me whether this could lead to a security flaw. The
110 >> osm_layers parameter, in particular, simply decides which tiles get
111 >> loaded in OpenLayers, but it is unclear to me if this is safe to change
112 >> or not. --[[anarcat]]
113
114 > I notice that `example => { 'OSM', 'GoogleSatellite' }` is wrong:
115 > it should (probably) be `example => [ 'OSM', 'GoogleSatellite' ]`
116 > (a list of two example values, not a map with key 'OSM' corresponding
117 > to value 'GoogleSatellite'. That might be why you're having trouble
118 > with this.
119
120 >> That is an accurate statement.
121 >>
122 >> This is old code, so my memory may be cold, but i think that the "layers" parameters used to be a hash, not an array, until two years ago (commit 636e04a). The javascript code certainly expects an array right now. --[[anarcat]]
123
124 >>> OK, then I think this might be a mixture of a bug and a feature request:
125 >>>
126 >>> * bug: the configuration suggested by the example (or the default when
127 >>>   unconfigured, or something) produces "TypeError: mapProjection is null"
128 >>>
129 >>> * feature request: per-\[[!osm]] configuration to complement the
130 >>>   per-wiki configuration
131 >>>
132 >>> --s
133 >>>
134 >>>> That is correct. --[[anarcat]]