zoukankan      html  css  js  c++  java
  • leaflet 利用ajax 将前端地图上的数据post到后台

    生成Google地图,在地图上单击后,将该点的经纬度反馈给后台。

    前端HTML代码:

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <meta charset="UTF-8">
     5      <link rel="stylesheet" href="/static/thirdpart/leaflet/leaflet.css" />
     6     <link rel="stylesheet" href="/static/thirdpart/leaflet/normalize.min.css" />
     7     <link rel="stylesheet" href="/static/thirdpart/leaflet/leaflet-filelayer-style.css" />
     8 
     9     <script src="/static/thirdpart/leaflet/leaflet.js" ></script>
    10     <script src="/static/thirdpart/leaflet/KML.js"></script>
    11     <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>12 </head>
    13 
    14 <body>
    15     <header>
    16      <h1>RTV File Selection System</h1>
    17     </header>
    18     <main>
    19         <div id="map" style=" 100%; height: 900px; display: block;"></div>
    20     </main>
    21 
    22     <script>
    23         var map = L.map('map').setView([42.5011596177, -83.5361632705], 13);
    24         
    25         //Google Satellite map
    26         L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', {
    27             attribution: 'google',
    28             minZoom:2,
    29         }).addTo(map);
    30         
    31 
    32         map.on('click', onMapClick);
    33         function onMapClick(e) {
    34             var latlng_point = [e.latlng.lat, e.latlng.lng];
    35             alert(latlng_point);
    36             
    37             jQuery(function($){
    38                  $.ajax({
    39                     type:"POST",
    40                     data: {point:''+latlng_point},
    41                     url: "/videomap/", 
    42                     cache: false,
    43                     dataType: "json",
    44                 });
    45              })
    46         }
    47 
    48     </script>
    49 
    50 </body>
    51 </html>

    后台代码:

     1 from django.shortcuts import render
     2 
     3 def index(request):
     4    
     5     if request.method == 'POST':
     6         if request.POST.get('point', '') != '':
     7             point = request.POST.get('point', '')
     8             print "################",point
     9         
    10     return render(request, 'test.html', data)
  • 相关阅读:
    第3周 实践项目2 建设”顺序表“算法库(可参考为模板)
    第3周实践项目3 求集合并集
    【luogu 2529】【SHOI 2001】击鼓传花
    【BZOJ 3270】博物馆
    【BZOJ 2337】XOR和路径
    浅谈期望dp
    【codeforces 24D】Broken Robot
    【POJ 1463】Strategic game
    【POJ 3585】Accumulation Degree
    【luogu 3146/3147】248/262144
  • 原文地址:https://www.cnblogs.com/mianbaoshu/p/7563116.html
Copyright © 2011-2022 走看看