Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图按多个区域(多边形)过滤?_Javascript_Wordpress_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图按多个区域(多边形)过滤?

Javascript 谷歌地图按多个区域(多边形)过滤?,javascript,wordpress,google-maps,google-maps-api-3,Javascript,Wordpress,Google Maps,Google Maps Api 3,我正在使用一个地图,其中我感兴趣的是选择多个区域,当选择这些区域时,只有显示这些区域的管脚。基本上,站点当前已设置标记,因此当您单击某个区域时,相应的标记将显示在过滤器下。添加过滤器后,将比较每个标记,如果该标记不在某个区域中,则删除标记。当前,当选择下拉项并将该项与每个标记的多边形区域进行比较时,地图正在运行。但是,当您为每个标记添加另一个循环时,筛选将不再起作用。下面是我的代码,网站链接位于 使用它来管理标记群集,这将有助于优化地图视图,答案应该有助于集成 此外,代码段中的代码通常可以很好地

我正在使用一个地图,其中我感兴趣的是选择多个区域,当选择这些区域时,只有显示这些区域的管脚。基本上,站点当前已设置标记,因此当您单击某个区域时,相应的标记将显示在过滤器下。添加过滤器后,将比较每个标记,如果该标记不在某个区域中,则删除标记。当前,当选择下拉项并将该项与每个标记的多边形区域进行比较时,地图正在运行。但是,当您为每个标记添加另一个循环时,筛选将不再起作用。下面是我的代码,网站链接位于

使用它来管理标记群集,这将有助于优化地图视图,答案应该有助于集成

此外,代码段中的代码通常可以很好地进行过滤。你可以试试看。可能就是这样

//从php文档markers.php输出中获取所有标记 模拟json对象 $'map-canvas'.gmap.bind'init',functionevt,map{ $.getJSON'http://example.php', functiondata{$.each data.markers,functioni,marker{ $'map-canvas'.gmap'addMarker',{'tags':marker.tags,'position':new google.maps.LatLngmarker.latitude,marker.longitude,'bounds':true}。单击函数{ //声明单击标记时要在信息窗口中显示的内容 $'map-canvas'.gmap'openInfoWindow',{'content':+ marker.title++marker.address++ marker.phone++marker.tags},这个; }; //过滤器映射 $'map-canvas'.gmap'find','markers',{'property':'tags', 'value':['baths'、'beddrooms'、'minprice'、'maxprice']、'operator':'和'},functionmarker,isFound{ 如果找到{ marker.setVisibletrue; }否则{ marker.setVisiblefalse; } }; }; };
}; // 结束映射功能如何筛选数据?您使用的是自定义代码还是地理编码API?我一直在使用地理编码API和Geoxmlv3。我已经设法让我的地图将每个pin与每个位置进行比较,但是位置越多,pin越多,发生的计算越多,页面加载所需的时间也越长。有没有一种方法可以让所有的比较首先放在JSON文件中?为了加快这一进程?思想?这更像是AngularJS解决方案吗?
    var DistrictVal = jQuery('#District').val(); 
    var baths = jQuery('#baths').val();
    var bedrooms = jQuery('#bedrooms').val(); 
    //var amount = jQuery('listings_per_page')

    var minprice = jQuery('#minPriceB').val();
    var maxprice = jQuery('#maxPriceB').val();

    jQuery('#loading').show(); //show the loading icon on start before a selection is made 
/*     ===================================================================================================================*/ 

    var stopIt = [];
    var bad; 

    var DistrictLen = jQuery('#District option').length; // determine how many items there are 
    for(var i = 0; i <= DistrictLen; i++) //loop through each item in the drop down 
    {
        var optionText = jQuery('#District option').eq(i).text(); //get the text and put in variable 
    }

    //loop through each filter tag added
    // if the filter tag matches drop down selection
    // make sure not to add the new tag

    var districtTags = jQuery('#districtTags #districtTag')
    var tagLength = districtTags.length; 

    for (var z = 0; z <= tagLength; z++)
    {
        if (districtTags.eq(z).text() == DistrictVal)
        {
            stopIt.push(1); //there is a match 
        }
        else{
            stopIt.push(0);  // there is not a match 
        }
    }
    var bad = jQuery.inArray(1, stopIt); 
    if (bad == -1)
    {
        jQuery('#districtTags').append('<div id="tag"><div id="districtTag">'+DistrictVal+'</div><span id="remove-tag"> X</span></div>');
        tags.push(DistrictVal); //get all of the tags and send them to mapChange() which is in jGMap.js 
        //console.log(tags);
    }
    jQuery('#remove-tag').live('click',function()
    {
    jQuery(this).parent().empty();
    tags = [];

    }); 
/* ===================================================================================================================*/        

//New Ajax request indepentant from the below Ajax request which 
// is only used to retrieve listings by location

    infoWindow = new google.maps.InfoWindow({size: new google.maps.Size(150, 100)});
    var mapOptions = {
        center: new google.maps.LatLng(39.977735,-86.141566),
        zoom: 11,
        mapTypeControl: true,
        mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
        navigationControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map-canvas-listing"), mapOptions);
    geoXml = new geoXML3.parser({map: map, singleInfoWindow: true, infowindow: infoWindow});
    geoXml.parse('/wp-content/themes/swishercorbett/js/SC Map.kml');
    /* ================================================================================ */  

    //Adds inforation to the database with the address and the latitude and longitude
    jQuery.ajax({
            async: 'false',
            url: 'http://swishercorbett.com.test.marketmagnitude.com/wp-content/plugins/john-    real-estate/mapinformation.php', //not a real page 
            type: 'GET',
            dataType: 'json',
            data: {jbaths: baths, jbedrooms: bedrooms, jminprice: minprice, jmaxprice: maxprice},
            //data: {jaddr: addr, jlat: lat, jlon: lon}, //uncomment after use! 
            success: function(e)
            { // get each address 
                jQuery(e).each(function(index) 
                {
                    // e[0] is first item repeated over itself 
                        var text = e[index][0]; //get the address of each listing 
                        //console.log(text);
                        var cords = e[index][1].split(','); //get the latitude and longitude and spit
                        var lat = parseFloat(cords[0]); //latitude with decimal points
                        var lon = parseFloat(cords[1]); // longitude with decimal points 

                        infowindow = new google.maps.InfoWindow();
                        marker = new google.maps.Marker( //add a new marker for each item in JSON array 
                        {
                            position: new google.maps.LatLng(lat, lon), // create a new position
                            map: map // add the position to the map 
                        });

                    /* ============================================================================ */  
                      for(var i = 0; i<geoXml.docs[0].gpolygons.length; i++ )
                      {
                        // if any of the tags match show those districts, remove the rest
                        for( var z = 0; z<= tags.length; z++)
                        {
                             if( geoXml.docs[0].placemarks[i].name == tags[z] ) //DistricVal 
                             {
                                if (geoXml.docs[0].gpolygons[i].Contains(marker.getPosition()) ) 
                                 { //if the marker is in the first quadriant then keep it, else remove the marker from the map
                                    marker.setMap(map);
                                    setTimeout(function(){ jQuery('#loading').hide();   }, 500); 
                                 }
                                  else
                                  {
                                    marker.setVisible(false);
                                    //console.log('does not contain');
                                  }
                             }
                             else
                             {
                                //alert('there is not a kml region with that name')
                             }
                         }
                      }
                    /* ============================================================================ */   
                        //console.log(google.maps.geometry.poly.containsLocation(cords, Midtown)); 
                        google.maps.event.addListener(marker, 'click', (function(marker, index) 
                        {
                            return function() 
                            {
                                infowindow.close(map,marker);
                                infowindow.setContent(e[index][0]);
                                infowindow.open(map, marker);
                            }
                        })(marker, index));
                });
            }
        }).done(function(){
            jQuery('#loading').hide();
        });