Advertisement
monomoti

FOSS4G 2017 TOKAI LEAFLET HANDS ON

Nov 18th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // twomaps.html
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5.     <meta charset="utf-8">
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.     <title>Leaflet Hands On</title>
  8.     <link rel="stylesheet" href="./leaflet/leaflet.css"/>    
  9.     <link rel="stylesheet" href="./css/mystyle.css">
  10.     <script src="./leaflet/leaflet.js"></script>
  11. </head>
  12. <body>
  13.     <div id="map1" class="twomaps"></div>
  14.     <div id="map2" class="twomaps"></div>
  15.     <script src="./js/twomaps.js"></script>
  16. </body>
  17. </html>
  18.  
  19.  
  20. // mystyle.css
  21. .twomaps{
  22.     width:49vw;
  23.     height:100vh;
  24.     float:left;
  25.     border-right:2px solid #000;
  26. }
  27.  
  28. //twomaps.js
  29. var options = {
  30.  center : [35.1611,136.8842],
  31.  zoom : 16
  32. }
  33.  
  34. var map1 = L.map('map1',options);
  35. var osm_j_baselayer = L.tileLayer('http://tile.openstreetmap.jp/{z}/{x}/{y}.png',{
  36.     attribution:'map data &copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  37. }).addTo(map1);
  38.  
  39. var map2 = L.map('map2',options);
  40. var gis_baselayer = L.tileLayer('https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', {
  41.     attribution:
  42. "<a href=\"http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html\" target=\"_blank\">国土地理院</a>"
  43. }).addTo(map2);
  44.  
  45. var moveOtherMap = function(target, center, zoom){
  46.     offHandler(target);
  47.     target.setView(center, zoom);
  48. };
  49.  
  50. var offHandler = function(target){
  51.     target.off("move");
  52. };
  53.  
  54. var onHandler = function(this_map){
  55.     var other_map;
  56.     if (this_map == map1){
  57.         other_map = map2;
  58.     }else{
  59.         other_map = map1;
  60.     }
  61.  
  62.     this_map.on("move", function(e){
  63.         moveOtherMap(other_map, this.getCenter(), this.getZoom());
  64.     }, this_map);
  65.  
  66. };
  67.  
  68. L.DomEvent.on(map1.getContainer(), "mouseover touchstart", function(e){
  69.     onHandler(this);
  70. }, map1);
  71.  
  72. L.DomEvent.on(map2.getContainer(), "mouseover touchstart", function(e){
  73.     onHandler(this);
  74. }, map2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement