Advertisement
DekkerBass

Draggable Map TomTom Script JSTL

May 23rd, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1.             <script>
  2.                     // Define your product name and version
  3.                     tomtom.setProductInfo('MapsWebSDKExamplesSelfhosted',
  4.                             '4.47.2-SNAPSHOT');
  5.                     var map, marker;
  6.                     // Setting TomTom keys
  7.                     tomtom.key('D5IYmsgLaSB7BkLe9jgyhDA923FgG0mS');
  8.                     tomtom.searchKey('D5IYmsgLaSB7BkLe9jgyhDA923FgG0mS');
  9.  
  10.                     //Creating the map
  11.                     map = tomtom
  12.                             .map('map', {
  13.                                 source : 'vector',
  14.                                 basePath : '/sdk'
  15.                             })
  16.                             .setView(
  17.                                     [
  18.                                             "${requestScope.results.get(0).getPosition().getLat()}",
  19.                                             "${requestScope.results.get(0).getPosition().getLon()}" ],
  20.                                     14);
  21.  
  22.                     // Adding marker to the map
  23.                     marker = tomtom.L
  24.                             .marker(
  25.                                     [
  26.                                             "${requestScope.results.get(0).getPosition().getLat()}",
  27.                                             "${requestScope.results.get(0).getPosition().getLon()}" ],
  28.                                     {
  29.                                         draggable : true
  30.                                     }).bindPopup('Amsterdam').addTo(map);
  31.  
  32.                     // Show popup each time the marker is moved
  33.                     marker
  34.                             .on(
  35.                                     'dragend',
  36.                                     function(e) {
  37.                                         tomtom
  38.                                                 .reverseGeocode(
  39.                                                         {
  40.                                                             position : e.target
  41.                                                                     .getLatLng()
  42.                                                         })
  43.                                                 .go(
  44.                                                         function(response) {
  45.                                                             if (response
  46.                                                                     && response.address
  47.                                                                     && response.address.freeformAddress) {
  48.                                                                 marker
  49.                                                                         .setPopupContent(response.address.freeformAddress);
  50.                                                             } else {
  51.                                                                 marker
  52.                                                                         .setPopupContent('No results found');
  53.                                                             }
  54.                                                             marker.openPopup();
  55.                                                         });
  56.                                     });
  57.                 </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement