0

I am trying to visualize points on a map through NodeJs. Here is my index.js file:

var express = require('express');
var fs = require('fs');
var getdata = require('./database.js');

var app = express();

app.get('/', function (req, res, next) {
    res.writeHead(200,{'Content-Type':'text/html'});
    var myReadStream = fs.createReadStream(__dirname + '/index.html','utf8')
    myReadStream.pipe(res);
    //var value = getdata.deneme();
    //console.log("Value: "+value);
});
app.listen(4000, function () {
    console.log('Server is running.. on Port 4000');
});

I can call the map through HTML file. Index.html file is here:

<html><body>
    <div id="mapdiv"></div>
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
    <script>
      map = new OpenLayers.Map("mapdiv");
      map.addLayer(new OpenLayers.Layer.OSM());


      var lonLat = new OpenLayers.LonLat(32 ,39 )
            .transform(
              new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
              map.getProjectionObject() // to Spherical Mercator Projection
            );

      var zoom=16;

      var markers = new OpenLayers.Layer.Markers( "Markers" );
      map.addLayer(markers);

      markers.addMarker(new OpenLayers.Marker(lonLat));

      map.setCenter (lonLat, zoom);
    </script>
  </body></html>

The last step is connecting to database. I created a database.js file:

const{Pool,Client} = require('pg');

var connectionString = "postgressql://ID:[email protected]:5432/dduigib0uc8ebt?ssl=true";

const pool = new Pool({
    connectionString: connectionString,
  });


module.exports = {
    deneme: function() {
        pool.query('SELECT st_astext(loc) from GetAllData()', (err, res) => {
            console.log(err, res)
            return res
            pool.end()
        });
    }
};

I can connect to database and get the locations of points. But I don't know how to send these points to my HTML file to visualize the points on map. In HTML page includes sample point for visualize. I just want to enter my points to there. How can I do that ?

1 Answer 1

1

Your back end should contain the database connection and the endpoints. You need to call those endpoints from your front end. The front end part should contain the HTML page and requests. you can use Xml Http Request to handle the requests.

Sign up to request clarification or add additional context in comments.

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.