• 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)
  • 相关阅读:
    对GDI+绘制圆弧接口的理解
    陈灯可重用代码管理器(插件版最新版本:3.2;桌面版最新版本:2.3)
    Apache OpenJPA 2.1.0 发布
    B3log Solo 0.2.5.1 发布了!
    Apache OpenJPA 2.1.0 发布
    jsoup 1.5.1 发布,超棒的HTML解析器
    程序员阿士顿的故事
    Web 是开源最大的成功
    Web 是开源最大的成功
    Python执行系统命令的方法 os.system(),os.popen(),commands renwofei423的个人空间 开源中国社区
  • 原文地址:https://www.cnblogs.com/mianbaoshu/p/7563116.html
Copyright © 2020-2023  润新知