0

我知道这可能是一个重复的问题。请不要将此作为重复问题。在过去的两天里,我对此感到震惊。请帮我。

我已经用谷歌搜索过了。但我无法找到这个问题的解决方案。

我正在尝试做的 na..

我在笔记本电脑上配置了 IIS-10。PHP,MySQL,PostgreSQL 也是我已经配置了与地理服务器相同的系统。

我在这里尝试访问使用地理服务器中的形状文件创建的地图。效果很好。IM 使用 Leaflet.js 实现地图功能

然后我的问题是当我试图在 ONCLICK 上添加一个事件时,我试图在 ajax 中调用一个 WMS 调用。我在这里遇到了问题。请查看错误的屏幕截图在此处输入图像描述

我的代码是。

<?php
    header('Access-Control-Allow-Origin: http://localhost');  //I have also tried the * wildcard and get the same response
    header("Access-Control-Allow-Credentials: true");
    header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
    header('Access-Control-Max-Age: 1000');
    header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
//print_r($_GET);
$DistrictName="ALL";    // to show all kerala map with loc
$DistrictId=-1;         // to show all kerala map
if(isset($_GET) &&!empty($_GET)){
    if(isset($_GET['DistrictName'])&&!empty($_GET['DistrictName'])&&$_GET['DistrictName']!=""){
        $DistrictName=$_GET['DistrictName'];
    }else{
        $DistrictName="BMAP";   // to show all kerala map 
    }

    if(isset($_GET['DistrictId'])&&!empty($_GET['DistrictId'])&&$_GET['DistrictId']!=""){
        $DistrictId=$_GET['DistrictId'];
    }else{
        $DistrictId=0;          // to show all kerala map
    }
}
?>
<html>
<head> 
 <link rel="stylesheet" href="./css/leaflet/leaflet.css"/>
 <script src="./js/leaflet/leaflet.js"></script>
 <script src="js/jquery-1.10.2.min.js"></script>
  <script src="js/gis/CRS.Simple.js"></script>
 <script type="text/javascript"> 
 $(document).ready(function(){
    getDistrictBoundary('<?php echo $DistrictName; ?>');
}); 
 </script>
 <style>
    /*#mapid { height: 180px; }*/
 </style>

 </head>
 <body>
 <table width="100%" border="1">
    <tr>
        <td width="50%">
            <div id="mapid"  style="height: 600px;width: 100%; "></div>
        </td>

    </tr>
 </table>


 </body>
 <script> 
    var districtLayer="",Kerala_Layer_Group="";
    var map = L.map('mapid');
    function getDistrictBoundary(TxtDistrict){
      //alert(TxtDistrict);
      switch(TxtDistrict){ 
        case 'ALL':
                map.removeLayer(Kerala_Layer_Group);
                map.removeLayer(districtLayer);
                map.setView([10.54265308,76.13877106], 7); 
                districtLayer=L.tileLayer.wms("http://localhost:8081/geoserver/TAMS/wms/",{ // url
                layers: 'TAMS:Kerala_Layer_Group',// workspacce:layername
                format: 'image/png',
                transparent: true,      
                opacity: 0.7,
                zoom:10     
                }).addTo(map); 
            break; 
    } 

    map.on('click', function(e) {
        var url = getFeatureInfoUrl1( map, e.latlng, { 'info_format': 'application/jsonp', 'propertyName': 'NAME,AREA_CODE,DESCRIPTIO' } );
    getGson(url);
    });
    getGson=function(url){
       $.ajax({ 
            url: url,  
            crossDomain: true,
            dataType: 'application/jsonp',
            success: function() { alert("Success"); },
            error: function() { alert('Failed!'); }
        });
    };

    var geojsonLayerWells;
    function loadGeoJson(data) {

        $('#data').html("jshjhdjhdsj");
        /*geojsonLayerWells.addData(data);
        map.addLayer(geojsonLayerWells);
        map.addLayer(geojsonLayerWells);*/
    };



    function getFeatureInfoUrl1(map, latlng, params) { 
        var bounds = map.getBounds();
        var sw = bounds.getSouthWest();
        var ne = bounds.getNorthEast();
        var size = map.getSize();
        var point = map.latLngToContainerPoint(latlng, map.getZoom()); 
        return 'http://localhost:8081/geoserver/wms?' + 
        'request=GetFeatureInfo' +
        '&service=wms'+
        '&version=1.1.1'+
        '&layers=TAMS:district_boundary'+
        '&styles='+
        '&srs=EPSG:4326'+
        '&format=application/jsonp'+
        '&bbox='+ map.getBounds().toBBoxString()+
        '&width='+size.x +
        '&height='+size.y +
        '&query_layers=TAMS:district_boundary'+
        '&info_format=text/html'+
        '&feature_count=50'+
        '&x='+ point.x +
        '&y='+ point.y ; 

        } 
</script>
 </html>
4

0 回答 0