javascript - Displaying PostGIS Data with Leafletjs -


i'm learning gis postgis , wanted try funny downloaded shape files osm, imported in postgres postgis extension , want represent data postgis visually. have pulled data query

select st_asgeojson(geom) "dar-es-salaam_tanzania.land_coast; 

i got bunch of geojson , wanted show them user. unfortunately not show it. use yii2 write codes pulls data. here controller code:

public function actionindex() {     $cmd = yii::$app->db->createcommand('select st_asgeojson(geom) "dar-es-salaam_tanzania.land_coast";');     $gjsons = [];     foreach($cmd->queryall() $row)     {         $gjsons[] = json_decode($row['st_asgeojson']);     }     return $this->render('index', ['geojson'=>json_encode($gjsons)]); } 

and in view

<?php /* @var $this yii\web\view */ $this->title = 'map application';  $this->registerjs("     var map = l.map('map').setview([6.8000, 39.2833], 13);     l.tilelayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {         maxzoom: 18,         attribution: 'map data &copy; <a href=\http://openstreetmap.org\">openstreetmap</a> contributors, ' +             '<a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">cc-by-sa</a>, ' +             'imagery © <a href=\"http://mapbox.com\">mapbox</a>',         id: 'examples.map-20v6611k'     }).addto(map);     var geojsonlist = $geojson;     l.geojson(geojsonlist).addto(map);   ");  ?>  <div id="map">  </div> 

is there missing? i'm new leaflet library , following tutorials on site

update

here html output (stripped geojson fit so) here full source note set height of map , can see grey box (+) , (-) signs on no map shown.

<!doctype html> <html lang="en-us"> <head>     <title>map application</title>     <link href="/hosannasystems/maps-app/web/assets/7edc4543/css/bootstrap.css" rel="stylesheet">     <link href="/hosannasystems/maps-app/web/css/site.css" rel="stylesheet">     <link href="/hosannasystems/maps-app/web/css/map.css" rel="stylesheet">     <link href="/hosannasystems/maps-app/web/leafletjs/leaflet.css" rel="stylesheet"></head> <body>      <div class="wrap">         <div id="map">         </div>      </div>  </script><script src="/hosannasystems/maps-app/web/assets/c29e8e0a/jquery.js"></script> <script src="/hosannasystems/maps-app/web/assets/f3e1524/yii.js"></script> <script src="/hosannasystems/maps-app/web/leafletjs/leaflet.js"></script> <script src="/hosannasystems/maps-app/web/assets/7edc4543/js/bootstrap.js"></script> <script type="text/javascript">     jquery(document).ready(function () {          var map = l.map('map').setview([6.8000, 39.2833], 13);         l.tilelayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {             maxzoom: 18,             attribution: 'map data &copy; <a href=\http://openstreetmap.org">openstreetmap</a> contributors, ' +                 '<a href="http://creativecommons.org/licenses/by-sa/2.0/">cc-by-sa</a>, ' +                 'imagery © <a href="http://mapbox.com">mapbox</a>',             id: 'examples.map-20v6611k'         }).addto(map);         var geojsonlist = [{"type":"multipolygon","coordinates":[[[[39.094989013528,-7.2022471828125],[38.638288027056,-7.2022471828125],[38.638288027056,-6.638130390625],[39.094989013528,-6.638130390625],[39.094989013528,-7.2022471828125]]]]}];         l.geojson(geojsonlist).addto(map);        }); </script> </body> </html> 

you didn't set height container. set in css file:

#map {     height: 400px; } 

and set zoom. that:

l.tilelayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {zoom: 10, ... 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -