use coordinates to open a routermap - Javascript Leaflet

Javascript examples for Leaflet:Map

Description

use coordinates to open a routermap

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <link rel="stylesheet" type="text/css" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"> 
      <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> 
      <style id="compiled-css" type="text/css">

#map {//from   w w  w.j a  v  a2 s .c  o  m
   height: 500px;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var map = L.map("map").setView([
  45.150788440748805,
  8.664894998073578
], 12);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var geoJsonData = {
  "type": "Feature",
  "properties": {
    "marker-color": "#0000ff",
    "marker-size": "medium",
    "marker-symbol": "water",
    "name": "Fontana Valle",
    "address": "Via della Valle 19 - VALLE LOMELLINA",
    "description": '<div style="width: 240px; text-align:justify;">Fontanella con acqua potabile, si trova difronte alla Piazza Corte Granda. </div><p text-align="center";><a href="http://www.mappeattive.com/wp-content/uploads/2015/11/fontanavallelomellina.jpg"><img data-id="2021"  src="http://www.mappeattive.com/wp-content/uploads/2015/11/fontanavallelomellina.jpg" alt="Fontanella Acqua Potabile" width="240" height="140" class="alignnone size-medium wp-image-2021" /></a></p>'
  },
  "geometry": {
    "type": "Point",
    "coordinates": [
      8.664894998073578,
      45.150788440748805
    ]
  }
};
var markers = [];
L.geoJson(geoJsonData, {
   pointToLayer: function (feature, latLng) {
     var props = feature.properties,
          lat = latLng.lat,
        lng = latLng.lng;
     var marker = L.marker(latLng).bindPopup(
       "<strong>" + props.name + "</strong><br />" +
      props.address + "<br />" +
      (props.description ? props.description : "") +
      "GPS: " + feature.geometry.coordinates + "<br /><br />" +
      "<a href='http://map.project-osrm.org/?z=18&center=" + lat + "%2C" + lng +
      "&loc=" + lat + "%2C" + lng +
      "&loc=" + lat + "%2C" + lng +
      "&hl=en&ly=&alt=&df=&srv=' target='_blank'>Get directions from this point</a>");
    markers.push(marker);
    return marker;
  }
}).addTo(map);
markers[0].openPopup();
    }

      </script> 
   </head> 
   <body> 
      <div id="map"></div>  
   </body>
</html>

Related Tutorials