0

I'm trying to make a map where a user can select a constituency and then see a series of markers, from a much larger list, that are only within that constituency.

I have the code below, and if you Select Tamworth you can see it draws the boundary, but all the markers appear without being filtered.

How can I get it to only show markers that fit within the displayed boundary?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Constituency picker</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.9/mapbox.css' rel='stylesheet' />
    <script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
    <script src="leaflet.ajax.min.js"></script>
    <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="leaflet-pip.js"></script>

    <noscript>
        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/skeleton.css">
    </noscript>
    <script>
    function loadCSS(href, before, media, callback) {
        "use strict";
        var ss = window.document.createElement("link");
        var ref = before || window.document.getElementsByTagName("script")[0];
        var sheets = window.document.styleSheets;
        ss.rel = "stylesheet";
        ss.href = href;
        ss.media = "only x";
        if (callback) {
            ss.onload = callback;
        }
        ref.parentNode.insertBefore(ss, ref);
        ss.onloadcssdefined = function(cb) {
            var defined;
            for (var i = 0; i < sheets.length; i++) {
                if (sheets[i].href && sheets[i].href.indexOf(href) > -1) {
                    defined = true;
                }
            }
            if (defined) {
                cb();
            } else {
                setTimeout(function() {
                    ss.onloadcssdefined(cb);
                });
            }
        };
        ss.onloadcssdefined(function() {
            ss.media = media || "all";
        });
        return ss;
    }
    </script>
    <style>
    #map {
        position: absolute;
        height:100%;
        width:100%;
    }
    </style>
</head>

<body>
    <div class="twelve columns">
        <div id="map"></div>
    </div>
    </div>
    <script>
    loadCSS("css/normalize.css");
    loadCSS("css/skeleton.css");
    loadCSS("http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css");
    </script>
    <script>
    var boundaries
    var myArr;
    var ConstituentcyList;
    var map;
    var boundarylines;
    var businessMarkers;
    businessMarkers = [
    [-1.68373,52.6278,"Business"],
    [-1.647423,52.62637,"Business"],
    [-1.688607,52.63592,"Business"],
    [-1.690209,52.63305,"Business"],
    [-1.690209,52.63305,"Business"],
    [-1.692224,52.63435,"Business"],
    [-1.691354,52.63622,"Business"],
    [-1.691354,52.63622,"Business"],
    [-1.692439,52.63324,"Business"],
    [-1.694671,52.63522,"Business"],
    [-1.695007,52.63367,"Business"],
    [-1.69636,52.63242,"Business"],
    [-1.692322,52.63934,"Business"],
    [-1.698248,52.62869,"Business"],
    [-1.713936,52.64285,"Business"],
    [-1.614024,52.61874,"Business"],
    [-1.694085,52.69163,"Business"],
    [-1.542248,52.57591,"Business"],
    [-1.792715,52.56823,"Business"],
    [-1.771228,52.54889,"Business"],
    [-1.699962,52.52921,"Business"],
    [-1.823508,52.58709,"Business"],
    [-1.827828,52.58827,"Business"],
    [-1.801244,52.56155,"Business"],
    [-1.829928,52.58727,"Business"],
    [-1.827326,52.5845,"Business"],
    [-1.823686,52.67873,"Business"],
    [-1.823249,52.68432,"Business"],
    [-1.826631,52.68213,"Business"],
    [-1.823249,52.68432,"Business"],
    [-1.826347,52.68292,"Business"],
    [-1.826726,52.68421,"Business"],
    [-1.826726,52.68421,"Business"],
    [-1.821571,52.56604,"Business"],
    [-1.82157,52.56623,"Business"],
    [-1.822219,52.56635,"Business"],
    [-1.820246,52.56536,"Business"],
    [-1.821398,52.56503,"Business"],
    [-1.819852,52.56419,"Business"],
    [-1.821471,52.56507,"Business"],
    [-1.819852,52.56419,"Business"],
    [-1.832108,52.68498,"Business"],
    [-1.82146,52.56425,"Business"],
    [-1.820962,52.55964,"Business"],
    [-1.820962,52.55964,"Business"],
    [-1.820962,52.55964,"Business"],
    [-1.845819,52.58957,"Business"],
    [-1.832024,52.5681,"Business"],
    [-1.79845,52.54026,"Business"],
    [-1.856222,52.59986,"Business"],
    [-1.82453,52.55667,"Business"],
    [-1.736013,52.51603,"Business"],
    [-1.736013,52.51603,"Business"],
    [-1.826685,52.55626,"Business"],
    [-1.822505,52.54293,"Business"],
    [-1.832557,52.5483,"Business"],
    [-1.837955,52.54833,"Business"],
    [-1.703748,52.49906,"Business"],
    [-1.839825,52.54922,"Business"],
    [-1.705365,52.49948,"Business"],
    [-1.704318,52.49752,"Business"],
    [-1.84267,52.54956,"Business"],
    [-1.760265,52.50109,"Business"],
    [-1.855025,52.54661,"Business"],
    [-1.748947,52.49382,"Business"],
    [-1.779638,52.50113,"Business"],
    [-1.841855,52.52194,"Business"],
    [-1.841855,52.52194,"Business"],
    [-1.841855,52.52194,"Business"],
    [-1.841855,52.52194,"Business"],
    [-1.881905,52.55424,"Business"],
    [-1.881905,52.55424,"Business"],
    [-1.841855,52.52194,"Business"],
    [-1.856568,52.53032,"Business"],
    [-1.825171,52.51029,"Business"],
    [-1.856568,52.53032,"Business"],
    [-1.915721,52.60463,"Business"],
    [-1.915721,52.60463,"Business"],
    [-1.917864,52.60373,"Business"],
    [-1.738868,52.4794,"Business"],
    [-1.917526,52.60282,"Business"],
    [-1.882414,52.54052,"Business"],
    [-1.556373,52.77294,"Business"],
    [-1.556373,52.77294,"Business"],
    [-1.469334,52.52156,"Business"],
    [-1.468222,52.52333,"Business"],
    [-1.552848,52.77254,"Business"],
    [-1.554668,52.77291,"Business"],
    [-1.671965,52.79006,"Business"],
    [-1.468868,52.52114,"Business"],
    [-1.422118,52.69131,"Business"],
    [-1.814778,52.49377,"Business"],
    [-1.465969,52.52197,"Business"],
    [-1.463757,52.52203,"Business"],
    [-1.399667,52.62357,"Business"],
    [-1.400054,52.62446,"Business"],
    [-1.465238,52.51899,"Business"],
    [-1.820084,52.49292,"Business"],
    [-1.815364,52.49106,"Business"],
    [-1.820084,52.49292,"Business"],
    [-1.472875,52.74627,"Business"],
    [-1.472875,52.74627,"Business"],
    [-1.472875,52.74627,"Business"],
    [-1.472875,52.74627,"Business"],
    [-1.472875,52.74627,"Business"],
    [-1.472875,52.74627,"Business"],
    [-1.73436,52.46757,"Business"],
    [-1.472875,52.74627,"Business"],
    [-1.831867,52.49332,"Business"],
    [-1.684897,52.46103,"Business"],
    [-1.469264,52.746,"Business"],
    [-1.808347,52.48217,"Business"],
    [-1.46933,52.74668,"Business"],
    [-1.46933,52.74668,"Business"],
    [-1.471716,52.7478,"Business"],
    [-1.467693,52.74725,"Business"],
    [-1.466718,52.74704,"Business"],
    [-1.466718,52.74704,"Business"],
    [-1.466718,52.74704,"Business"],
    [-1.466718,52.74704,"Business"],
    [-1.727395,52.45824,"Business"],
    [-1.630191,52.80013,"Business"],
    [-1.630191,52.80013,"Business"],
    [-1.629176,52.80097,"Business"],
    [-1.630191,52.80013,"Business"],
    [-1.445768,52.51895,"Business"],
    [-1.628223,52.80133,"Business"],
    [-1.628081,52.80238,"Business"],
    [-1.396852,52.68642,"Business"],
    [-1.696375,52.45295,"Business"],
    [-1.696375,52.45295,"Business"],
    [-1.696375,52.45295,"Business"],
    [-1.894747,52.5199,"Business"],
    [-1.894747,52.5199,"Business"],
    [-1.696375,52.45295,"Business"],
    [-1.88417,52.51184,"Business"],
    [-1.88417,52.51184,"Business"],
    [-1.627851,52.80318,"Business"],
    [-1.627571,52.80301,"Business"],
    [-1.890414,52.51368,"Business"],
    [-1.847147,52.48782,"Business"],
    [-1.857592,52.49148,"Business"],
    [-1.849693,52.48827,"Business"],
    [-1.855961,52.49047,"Business"],
    [-1.854238,52.49024,"Business"],
    [-1.854519,52.48999,"Business"],
    [-1.869404,52.49718,"Business"],
    [-1.857592,52.49148,"Business"],
    [-1.625803,52.8068,"Business"],
    [-1.932011,52.54631,"Business"],
    [-1.625803,52.8068,"Business"],
    [-1.632158,52.80973,"Business"],
    [-1.806908,52.46762,"Business"],
    [-1.900023,52.51374,"Business"],
    [-1.900773,52.51422,"Business"],
    [-1.900023,52.51374,"Business"],
    [-1.934741,52.54493,"Business"],
    [-1.535764,52.46453,"Business"],
    [-1.966813,52.62923,"Business"],
    [-1.366692,52.64804,"Business"],
    [-1.921515,52.52704,"Business"],
    [-1.901158,52.50711,"Business"],
    [-1.928083,52.53161,"Business"],
    [-1.928775,52.5317,"Business"],
    [-1.962281,52.5728,"Business"],
    [-1.852132,52.47692,"Business"],
    [-1.814484,52.46212,"Business"],
    [-1.972085,52.58796,"Business"],
    [-1.89909,52.50252,"Business"],
    [-1.814484,52.46212,"Business"],
    [-1.471964,52.47925,"Business"],
    [-1.471964,52.47925,"Business"],
    [-1.780492,52.45098,"Business"],
    [-1.902082,52.50212,"Business"],
    [-1.97625,52.58405,"Business"],
    [-1.97625,52.58405,"Business"],
    [-1.976086,52.58714,"Business"],
    [-1.976086,52.58714,"Business"],
    [-1.976086,52.58714,"Business"],
    [-1.976086,52.58714,"Business"],
    [-1.823421,52.46166,"Business"],
    [-1.973714,52.57986,"Business"],
    [-1.879807,52.48521,"Business"],
    [-1.975273,52.58783,"Business"],
    [-1.976086,52.58714,"Business"],
    [-1.466478,52.47865,"Business"],
    [-1.979703,52.5868,"Business"],
    [-1.977357,52.58441,"Business"],
    [-1.467944,52.47799,"Business"],
    [-1.977666,52.58501,"Business"],
    [-1.979969,52.58523,"Business"],
    [-1.978745,52.58238,"Business"],
    [-1.982446,52.5929,"Business"],
    [-1.979984,52.58572,"Business"],
    [-1.84828,52.46667,"Business"],
    [-1.464038,52.47829,"Business"],
    [-1.916182,52.50222,"Business"],
    [-1.981683,52.58052,"Business"],
    [-1.853812,52.46785,"Business"],
    [-1.981372,52.58286,"Business"],
    [-1.860414,52.47042,"Business"],
    [-1.856679,52.46886,"Business"],
    [-1.854295,52.46845,"Business"],
    [-1.862207,52.47116,"Business"],
    [-1.917578,52.50412,"Business"],
    [-1.980105,52.57934,"Business"],
    [-1.856679,52.46886,"Business"],
    [-1.843759,52.46292,"Business"],
    [-1.843759,52.46292,"Business"],
    [-1.897352,52.48971,"Business"],
    [-1.854295,52.46845,"Business"],
    [-1.982214,52.58163,"Business"],
    [-1.983481,52.58891,"Business"],
    [-1.983484,52.58105,"Business"],
    [-1.376981,52.53875,"Business"],
    [-1.376981,52.53875,"Business"],
    [-1.376981,52.53875,"Business"],
    [-1.98282,52.58101,"Business"],
    [-1.98282,52.58101,"Business"],
    [-1.895077,52.48626,"Business"],
    [-1.98282,52.58101,"Business"],
    [-1.895077,52.48626,"Business"],
    [-1.895077,52.48626,"Business"],
    [-1.98282,52.58101,"Business"],
    [-1.376981,52.53875,"Business"],
    [-1.927616,52.51052,"Business"],
    [-1.376981,52.53875,"Business"],
    [-1.918673,52.5016,"Business"],
    [-1.984944,52.58381,"Business"],
    [-1.376981,52.53875,"Business"],
    [-1.89149,52.48376,"Business"],
    [-1.89149,52.48376,"Business"],
    [-1.933446,52.51414,"Business"],
    [-1.894053,52.48347,"Business"],
    [-1.890877,52.48161,"Business"],
    [-1.891419,52.48283,"Business"],
    [-1.891593,52.48359,"Business"],
    [-1.894524,52.48379,"Business"],
    [-1.817224,52.45105,"Business"],
    [-1.919325,52.49971,"Business"],
    [-1.891419,52.48283,"Business"],
    [-1.914659,52.4973,"Business"],
    [-1.890877,52.48161,"Business"],
    [-1.893875,52.48411,"Business"],
    [-1.89177,52.48355,"Business"],
    [-1.919325,52.49971,"Business"],
    [-1.891419,52.48283,"Business"],
    [-1.891419,52.48283,"Business"],
    [-1.892009,52.48233,"Business"],
    [-1.891197,52.48327,"Business"],
    [-1.891197,52.48327,"Business"],
    [-1.890877,52.48161,"Business"],
    [-1.890877,52.48161,"Business"],
    [-1.890877,52.48161,"Business"],
    [-1.891197,52.48327,"Business"],
    [-1.371616,52.53955,"Business"],
    [-1.914514,52.49615,"Business"],
    [-1.893614,52.48238,"Business"],
    [-1.881088,52.47432,"Business"],
    [-1.894984,52.48222,"Business"],
    [-1.89448,52.48341,"Business"],
    [-1.910267,52.49121,"Business"],
    [-1.896984,52.48333,"Business"],
    [-1.371616,52.53955,"Business"],
    [-1.878266,52.47285,"Business"],
    [-1.371616,52.53955,"Business"],
    [-1.89448,52.48341,"Business"],
    [-1.371616,52.53955,"Business"],
    [-1.923712,52.50142,"Business"],
    [-1.89448,52.48341,"Business"],
    [-1.371616,52.53955,"Business"],
    [-1.899422,52.48616,"Business"],
    [-1.896188,52.48351,"Business"],
    [-1.892289,52.4822,"Business"],
    [-1.923375,52.50062,"Business"],
    [-1.894984,52.48222,"Business"],
    [-1.894984,52.48222,"Business"],
    [-1.892289,52.4822,"Business"],
    [-1.892289,52.4822,"Business"],
    [-1.895262,52.48295,"Business"],
    [-1.892289,52.4822,"Business"],
    [-1.371616,52.53955,"Business"],
    [-1.918649,52.4986,"Business"],
    [-1.894984,52.48222,"Business"],
    [-1.893614,52.48238,"Business"],
    [-1.892289,52.4822,"Business"],
    [-1.89448,52.48341,"Business"],
    [-1.371027,52.54051,"Business"],
    [-1.895262,52.48295,"Business"],
    [-1.910256,52.48944,"Business"],
    [-1.910033,52.49022,"Business"],
    [-1.910033,52.49022,"Business"],
    [-1.900034,52.48283,"Business"],
    [-1.898312,52.48219,"Business"],
    [-1.370797,52.53701,"Business"],
    [-1.902283,52.48455,"Business"],
    [-1.905266,52.48776,"Business"],
    [-1.905266,52.48776,"Business"],
    [-1.92791,52.50209,"Business"],
    [-1.898562,52.48252,"Business"],
    [-1.903313,52.48522,"Business"],
    [-1.930689,52.50583,"Business"],
    [-1.911711,52.49065,"Business"],
    [-1.894648,52.48089,"Business"],
    [-1.937459,52.51143,"Business"],
    [-1.894648,52.48089,"Business"],
    [-1.367208,52.54257,"Business"],
    [-1.371874,52.72169,"Business"],
    [-1.37267,52.72403,"Business"],
    [-1.371874,52.72169,"Business"],
    [-1.37013,52.53934,"Business"],
    [-1.902283,52.48455,"Business"],
    [-1.896045,52.48183,"Business"],
    [-1.371874,52.72169,"Business"],
    [-1.910256,52.48944,"Business"],
    [-1.902283,52.48455,"Business"],
    [-1.897959,52.48212,"Business"],
    [-1.899665,52.48304,"Business"],
    [-1.911711,52.49065,"Business"],
    [-1.898562,52.48252,"Business"],
    [-1.896045,52.48183,"Business"],
    [-1.892723,52.47946,"Business"],
    [-1.931368,52.50444,"Business"],
    [-1.895163,52.48129,"Business"],
    [-1.89637,52.48145,"Business"],
    [-1.898562,52.48252,"Business"],
    [-1.899298,52.48257,"Business"],
    [-1.900034,52.48283,"Business"],
    [-1.896045,52.48183,"Business"],
    [-1.881253,52.47334,"Business"],
    [-1.903313,52.48522,"Business"],
    [-1.901318,52.4817,"Business"],
    [-1.900568,52.48125,"Business"],
    [-1.899876,52.48105,"Business"],
    [-1.896255,52.48009,"Business"],
    [-1.931665,52.50323,"Business"],
    [-1.902362,52.48236,"Business"],
    [-1.931665,52.50323,"Business"],
    [-1.92872,52.50188,"Business"],
    [-1.837746,52.45279,"Business"],
    [-1.898655,52.48035,"Business"],
    [-1.900758,52.48153,"Business"],
    [-1.905403,52.48552,"Business"],
    [-1.900568,52.48125,"Business"],
    [-1.900568,52.48125,"Business"],
    [-1.931946,52.50256,"Business"],
    [-1.901318,52.4817,"Business"],
    [-1.900568,52.48125,"Business"],
    [-1.900568,52.48125,"Business"],
    [-1.902362,52.48236,"Business"],
    [-1.899258,52.4809,"Business"],
    [-1.89955,52.48194,"Business"],
    [-1.901318,52.4817,"Business"],
    [-1.895726,52.47987,"Business"],
    [-1.896255,52.48009,"Business"],
    [-1.898934,52.48058,"Business"],
    [-1.899448,52.48156,"Business"],
    [-1.904979,52.48423,"Business"],
    [-1.900758,52.48153,"Business"],
    [-1.901567,52.48191,"Business"],
    [-1.898934,52.48058,"Business"],
    [-1.895726,52.47987,"Business"],
    [-1.900417,52.48262,"Business"],
    [-1.36321,52.54373,"Business"],
    [-1.902079,52.48391,"Business"],
    [-1.901318,52.4817,"Business"],
    [-1.898934,52.48058,"Business"],
    [-1.898934,52.48058,"Business"],
    [-1.888594,52.47601,"Business"],
    [-1.9027,  52.48255, "Business"],
    [-1.904979,52.48423,"Business"],
    [-1.931946,52.50256,"Business"],
    [-1.903359,52.48413,"Business"],
    [-1.896255,52.48009,"Business"],
    [-1.897375,52.4798,"Business"],
    [-1.896255,52.48009,"Business"],
    [-1.89955,52.48194,"Business"],
    [-1.89955,52.48194,"Business"],
    [-1.89955,52.48194,"Business"],
    [-1.89955,52.48194,"Business"],
    [-1.898655,52.48035,"Business"],
    [-1.898655,52.48035,"Business"],
    [-1.89955,52.48194,"Business"],
    [-1.930694,52.50264,"Business"],
    [-1.89895,52.48026,"Business"],
    [-1.896801,52.47969,"Business"],
    [-1.909111,52.48718,"Business"],
    [-1.898305,52.47874,"Business"],
    [-1.907764,52.48339,"Business"],
    [-1.934184,52.50331,"Business"],
    [-1.90551,52.4839,"Business"],
    [-1.900467,52.48029,"Business"],
    [-1.897657,52.47902,"Business"],
    [-1.900233,52.47934,"Business"],
    [-1.899776,52.47951,"Business"],
    [-1.899937,52.47996,"Business"],
    [-1.985585,52.69966,"Business"],
    [-1.899657,52.48013,"Business"],
    [-1.903306,52.48145,"Business"],
    [-1.900467,52.48029,"Business"],
    [-1.899436,52.48003,"Business"],
    [-1.899436,52.48003,"Business"],
    [-1.899436,52.48003,"Business"],
    [-1.901863,52.48144,"Business"],
    [-1.897671,52.47926,"Business"],
    [-1.907764,52.48339,"Business"],
    [-1.907764,52.48339,"Business"],
    [-1.901748,52.48019,"Business"],
    [-1.899937,52.47996,"Business"],
    [-1.898305,52.47874,"Business"],
    [-1.90682,52.48412,"Business"],
    [-1.899938,52.47976,"Business"],
    [-1.899381,52.47863,"Business"],
    [-1.36428,52.72259,"Business"],
    [-1.900442,52.47838,"Business"],
    [-1.901707,52.47857,"Business"],
    [-1.36428,52.72259,"Business"],
    [-1.902503,52.47838,"Business"],
    [-1.901118,52.47885,"Business"],
    [-1.901118,52.47885,"Business"],
    [-1.869875,52.4622,"Business"],
    [-1.824647,52.44563,"Business"],
    [-1.939694,52.504,"Business"],
    [-1.901707,52.47857,"Business"],
    [-1.912298,52.48468,"Business"],
    [-1.895165,52.47415,"Business"],
    [-1.901707,52.47857,"Business"],
    [-1.36428,52.72259,"Business"],
    [-1.937751,52.50254,"Business"],
    [-1.939826,52.50441,"Business"],
    [-1.910693,52.48437,"Business"],
    [-1.36428,52.72259,"Business"],
    [-1.821825,52.44494,"Business"],
    [-1.901707,52.47857,"Business"],
    [-1.939826,52.50441,"Business"],
    [-1.910693,52.48437,"Business"],
    [-1.901707,52.47857,"Business"],
    [-1.897075,52.47584,"Business"],
    [-1.911414,52.48453,"Business"],
    [-1.933873,52.75917,"Business"],
    [-1.932598,52.75953,"Business"],
    [-1.893769,52.47325,"Business"],
    [-1.896475,52.47446,"Business"],
    [-1.94342,52.50524,"Business"],
    [-1.934361,52.76006,"Business"],
    [-1.896475,52.47446,"Business"],
    [-1.869972,52.45915,"Business"],
    [-1.902026,52.47432,"Business"],
    [-1.88175,52.46364,"Business"],
    [-1.870929,52.45913,"Business"],
    [-1.906644,52.47673,"Business"],
    [-1.868975,52.45814,"Business"],
    [-1.902026,52.47432,"Business"],
    [-1.89392,52.47141,"Business"],
    [-1.869972,52.45915,"Business"],
    [-1.363732,52.72668,"Business"],
    [-1.897716,52.4725,"Business"],
    [-1.902026,52.47432,"Business"],
    [-1.901468,52.4738,"Business"],
    [-1.869972,52.45915,"Business"],
    [-1.902117,52.47308,"Business"],
    [-1.909604,52.47684,"Business"],
    [-1.909604,52.47684,"Business"],
    [-1.909604,52.47684,"Business"],
    [-1.865571,52.45457,"Business"],
    [-1.865571,52.45457,"Business"],
    [-1.897881,52.47119,"Business"],
    [-1.897881,52.47119,"Business"],
    [-1.91215,52.47764,"Business"],
    [-1.882331,52.46107,"Business"],
    [-1.907664,52.4748,"Business"],
    [-2.013366,52.6562,"Business"],
    [-1.864427,52.45325,"Business"],
    [-1.91215,52.47764,"Business"],
    [-1.913643,52.47475,"Business"],
    [-1.861642,52.44966,"Business"],
    [-2.007954,52.57504,"Business"],
    [-1.934548,52.48638,"Business"],
    [-1.859206,52.44746,"Business"],
    [-1.863115,52.44911,"Business"],
    [-1.865112,52.45051,"Business"],
    [-1.876581,52.4538,"Business"],
    [-1.876329,52.4547,"Business"],
    [-1.911632,52.47163,"Business"],
    [-1.857955,52.44742,"Business"],
    [-1.865112,52.45051,"Business"],
    [-1.997632,52.70893,"Business"],
    [-1.851072,52.44217,"Business"],
    [-1.858784,52.4459,"Business"],
    [-2.008864,52.6968,"Business"],
    [-2.009057,52.69791,"Business"],
    [-1.756367,52.41726,"Business"],
    [-1.84674,52.43949,"Business"],
    [-1.847521,52.43913,"Business"],
    [-1.911916,52.46926,"Business"],
    [-1.858027,52.44358,"Business"],
    [-1.316514,52.5754,"Business"],
    [-1.921391,52.47268,"Business"],
    [-1.918702,52.46999,"Business"],
    [-1.918702,52.46999,"Business"],

]


    var map = L.map('map').setView([52.47497, -1.90695],15);
    var mapView = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
            maxZoom: 18,

            })
    mapView.addTo(map)
    var xmlhttp = new XMLHttpRequest();
    var url = "http://mapit.mysociety.org/areas/WMC.json";
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            myArr = JSON.parse(xmlhttp.responseText);
            myFunction(myArr);
        }
    }
    xmlhttp.open("GET", url, true);
    xmlhttp.send();


    var legend = L.control({
        position: 'topright'
    });

    legend.onAdd = function(map) {
        var div = L.DomUtil.create('div', 'info legend');
        div.innerHTML = '<select id="sel"><option value="null">Please Select</option></select>';
        div.firstChild.onmousedown = div.firstChild.ondblclick;
        return div;
    };
    legend.addTo(map);

    function myFunction(arr) {
        $.each(arr, function(i, option) {
            if (option.name == 'The Wrekin' || option.name == 'Tamworth' || option.name == 'Clacton') {
                $('#sel').append($('<option/>').attr("value", option.id).text(option.name));
            }
        });
    }

    $("#sel").change(function(){
        if (boundaries != undefined){
            map.removeLayer(boundaries);
        }
        constituencyID = $(this).val();
        constituencyName = $(this).find('option:selected').text();
        $.ajax({
            url: 'http://mapit.mysociety.org/area/' + constituencyID +'.geojson',
            dataType: 'json',
            async: false,
            success: function(data) {
               boundaries = L.geoJson(data).addTo(map);

           }
            })

            // });
            map.fitBounds(boundaries.getBounds());
                for (var i=0; i<businessMarkers.length; i++) {

            var lon = businessMarkers[i][0];
            var lat = businessMarkers[i][1];
            var popupText = businessMarkers[i][2];
            var markerLocation = new L.LatLng(lat, lon);
            var marker = new L.Marker(markerLocation);
            console.log(markerLocation)
            if (leafletPip.pointInLayer(markerLocation, boundaries, false))
            {    
                map.addLayer(marker);
            marker.bindPopup("<h2>" + popupText + "</h2><p>" + constituencyName +"</p>");
            }
    }



    });










    </script>
</body>

</html>
  • Welcome to GIS SE! As a new user be sure to take the Tour. To help make clear what it is that you are asking I recommend that you use the edit button beneath your question to include a single question mark somewhere within its body. – PolyGeo Jun 18 '15 at 23:05
0

According to the documentation, leaflet-pip returns:

An array of polygons in which the given point resides, an empty array if there are none.

whereas you are looking for the opposite: to test if the given point resides in the selected polygon

In principle, you should be able to do this with turf-inside. Rough example:

var point = turf.point([lon, lat]);
if (turf.inside(point,boundaries) {    
    map.addLayer(marker);
    marker.bindPopup("<h2>" + popupText + "</h2><p>" + constituencyName +"</p>");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.