Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var map;
- var iconFeatures = [];
- var lineString;
- var lineArray = [];
- var extent;
- var baseLayers = [
- new ol.layer.Tile({
- source: new ol.source.TileWMS({
- url: 'http://localhost/geoserver/India/wms',
- params:
- {
- 'LAYERS': 'India:roads', //,dist_bnd,dist_hq,dist_road,roads
- 'TILED': true,
- crossOrigin: 'anonymous',
- 'isBaselayer': true
- },
- serverType: 'geoserver'
- })
- })
- ];
- var vectorPointSource = new ol.source.Vector({
- //create empty vector
- });
- var vectorLineSource = new ol.source.Vector({
- });
- var iconStyle = new ol.style.Style({
- image: new ol.style.Icon(/** @type {olx.style.IconOptions} */
- ({
- anchor: [0.5, 46],
- anchorXUnits: 'fraction',
- anchorYUnits: 'pixels',
- opacity: 0.75,
- src: 'images/marker.png'
- }))
- });
- var lineStyle = new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: '#000000',
- width: 2
- })
- });
- //add the feature vector to the layer vector, and apply a style to whole layer
- var pointLayer = new ol.layer.Vector({
- source: vectorPointSource,
- style: iconStyle
- });
- var lineLayer = new ol.layer.Vector({
- source: vectorLineSource,
- style: [lineStyle]
- });
- var view = new ol.View({
- center: [10497145, 2369099],
- zoom: 4
- });
- map = new ol.Map({
- controls: ol.control.defaults().extend([
- new ol.control.FullScreen(),
- new ol.control.ScaleLine()
- ]),
- layers: baseLayers,
- target: document.getElementById('map'),
- view: view
- });
- // lineLayer.getSource().updateParams({"time": Date.now()});
- map.addLayer(pointLayer);
- map.addLayer(lineLayer);
- // lineLayer.getSource().updateParams({"time": Date.now()});
- function showMap() {
- $.ajax({
- url: 'GetTerminalData',
- type: 'post',
- dataType: 'json',
- success: function(json) {
- alert('inside success');
- $.each(json, function(idx, obj) {
- var final_lat = +(obj.latitude);
- var final_lon = +(obj.longitude);
- lineArray.push({x: final_lon, y: final_lat});
- // alert('lineArray[0].x' + lineArray[0].x);
- // alert("Final_lon : " + final_lon + " Final_lat: " + final_lat);
- var iconFeature = new ol.Feature({
- geometry: new
- ol.geom.Point(ol.proj.transform([final_lon, final_lat], 'EPSG:4326', 'EPSG:3857'))
- });
- lineArray[idx] = ol.proj.transform([lineArray[idx].x, lineArray[idx].y], 'EPSG:4326', 'EPSG:3857');
- var featureLine = new ol.Feature({
- geometry: new ol.geom.LineString(lineArray),
- time: Date.now()
- });
- // pointLayer.getSource().updateParams({"time": Date.now()});
- // lineLayer.clear();
- /* var fe = vectorPointSource.getFeatures();
- alert('fe count ' + fe.length);
- for(i=0;i<fe.length;i++){
- vectorPointSource.removeFeatures(fe[i]);
- }*/
- // alert('fe count ' + fe.length);
- // vectorPointSource.removeFeatures();
- vectorPointSource.addFeature(iconFeature);
- vectorLineSource.addFeature(featureLine);
- // lineLayer.refresh({force:true});
- // lineLayer.getSource().updateParams({"time": Date.now()});
- });
- extent = pointLayer.getSource().getExtent();
- map.getView().fit(extent, map.getSize());
- }, complete: function() {
- setTimeout(showMap, 10000);
- }
- });
- }
- try {
- ArrayList<LocationBean> list = new ArrayList<LocationBean>();
- Connection con = null;
- System.out.println("Inside servlet");
- Statement s = null;
- ResultSet rs = null;
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/VesselTracking", "user3", "shivam");
- s = con.createStatement();
- rs = s.executeQuery("Select terminalId,`timestamp`,ST_Y(Current_Location) as Latitude,ST_X(Current_Location) as Longitude from VesselTracking.Terminal where TerminalId<1006;"); //ST_Y(Current_Location) as Latitude,ST_X(Current_Location) as Longitude
- while (rs.next()) {
- LocationBean lb = new LocationBean(rs.getInt(1), rs.getTimestamp(2), rs.getFloat(3),rs.getFloat(4));
- list.add(lb);
- }
- rs.close();
- s.close();
- con.close();
- Gson gson = new Gson();
- String json = gson.toJson(list);
- System.out.println(json);
- response.setContentType("application/json");
- response.getWriter().write(json);
- } catch (Exception e) {
- e.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement