> var marker = L.marker([<? echo $dati[1][5]; ?>, <? echo $dati[1][6];
>?>]).addTo(map);
> marker.bindPopup("<b><? echo $dati[1][2]; ?></b><br><? echo
>$dati[1][7]; ?>").openPopup();
> ...
> as suggested in Leaflet Quick Start Guide. If I want to show 50 points
> (stored in $dati matrix), what code can I
> use? I realized if the description to show in the popup is long, Leaflet
> don't creates the map, how can I solve
> this problem?
Whenever you output data that may contain characters with a special meaning,
i.e. quotation marks, HTML angle brackets and the like, you have to make sure
they are properly escaped for the language they will be embedded in. For HTML,
you have to use `htmlspecialchars(...)` for that purpose; in this case, your
data ends up in Javascript strings, so you have to use `json_encode(...)`.
The reason the map sometimes isn't created probably has nothing to do with the
length of the description, but with the lack of quoting. Most likely, your
texts contain a quotation mark, which results in JS code like this:
marker.bindPopup("<b>some text</b><br>some "other" other").openPopup();
This is, of course, syntactically invalid.
Apart from that, it should be straight-forward:
var marker;
<?php foreach($dati as $d) { ?>
marker = L.marker([<?php echo $d[5]; ?>, <?php echo $d[6]; ?>]).addTo(map);
marker.bindPopup("<b><?php echo $d[2]; ?></b><br><?php echo $d[7];
?>").openPopup();
<?php } ?>
_______________________________________________
dev mailing list
[email protected]
https://lists.openstreetmap.org/listinfo/dev