javascript - LeafletJS :Search box outside the map? - Stack Overflow

Currently I have this leaflet.js map<div id="myMap" style="width: 100%; height:300px;

Currently I have this leaflet.js map

<div id="myMap" style="width: 100%; height:300px;"></div>

<script>
// This setup the leafmap object by linking the map() method to the map id (in <div> html element)
var map = L.map('myMap', {
center: [14.599512, 120.984222],
zoom: 13,
// minZoom: 1.5,
//  maxZoom: 1.5
});

// Start adding controls as follow... L.controlName().addTo(map);

// Control 1: This add the OpenStreetMap background tile
L.tileLayer('http://{s}.tile.osm/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="">OpenStreetMap</a> contributors'
}).addTo(map);


// Control 2: This add a scale to the map
L.control.scale().addTo(map);

// Control 3: This add a Search bar
var searchControl = new L.esri.Controls.Geosearch().addTo(map);


var results = new L.LayerGroup().addTo(map);

searchControl.on('results', function(data){
    results.clearLayers();
    for (var i = data.results.length - 1; i >= 0; i--) {
    results.addLayer(L.marker(data.results[i].latlng));
    }
});

this is the current output of this code.

This is working fine as of now. But What I'm trying to do is to make a search box outside the leaflet map. When the user type some places on the search box outside the map, the map will automatically find the value of searchbox.

This is my current mdb html code I don't have idea how to do that.

  <!--Grid row-->
   <div class="row">
     <div class="col-md-12">
        <div class="md-form mb-0">
            <input type="text" id="proj_loc" name="proj_loc" class="form-control">
            <label for="proj_loc" class="">Location</label>
         </div>
       </div>
   </div>
   <!--Grid row-->

Currently I have this leaflet.js map

<div id="myMap" style="width: 100%; height:300px;"></div>

<script>
// This setup the leafmap object by linking the map() method to the map id (in <div> html element)
var map = L.map('myMap', {
center: [14.599512, 120.984222],
zoom: 13,
// minZoom: 1.5,
//  maxZoom: 1.5
});

// Start adding controls as follow... L.controlName().addTo(map);

// Control 1: This add the OpenStreetMap background tile
L.tileLayer('http://{s}.tile.osm/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm/copyright">OpenStreetMap</a> contributors'
}).addTo(map);


// Control 2: This add a scale to the map
L.control.scale().addTo(map);

// Control 3: This add a Search bar
var searchControl = new L.esri.Controls.Geosearch().addTo(map);


var results = new L.LayerGroup().addTo(map);

searchControl.on('results', function(data){
    results.clearLayers();
    for (var i = data.results.length - 1; i >= 0; i--) {
    results.addLayer(L.marker(data.results[i].latlng));
    }
});

this is the current output of this code.

This is working fine as of now. But What I'm trying to do is to make a search box outside the leaflet map. When the user type some places on the search box outside the map, the map will automatically find the value of searchbox.

This is my current mdb html code I don't have idea how to do that.

  <!--Grid row-->
   <div class="row">
     <div class="col-md-12">
        <div class="md-form mb-0">
            <input type="text" id="proj_loc" name="proj_loc" class="form-control">
            <label for="proj_loc" class="">Location</label>
         </div>
       </div>
   </div>
   <!--Grid row-->

Share Improve this question asked Oct 11, 2019 at 7:12 King RGKing RG 5102 gold badges13 silver badges28 bronze badges 1
  • This thread gives me an answer stackoverflow./questions/15919227/… – King RG Commented Oct 11, 2019 at 9:18
Add a ment  | 

1 Answer 1

Reset to default 5

Please check Leaflet Control Search Plugin for adding search control.

map.addControl( new L.Control.Search({
    container: 'findbox',
    layer: markersLayer,
    initial: false,
    collapsed: false
}) );

For example please check this You will get full code here

Hope this will help you.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745301350a4621454.html

相关推荐

  • javascript - LeafletJS :Search box outside the map? - Stack Overflow

    Currently I have this leaflet.js map<div id="myMap" style="width: 100%; height:300px;

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信