Skip to main content
improved step 3 to clarify the input is html, not plugin
Source Link
toms
  • 7.1k
  • 1
  • 26
  • 31

here is a rough, general approach, with a few code examples (using jQuery/javascript):

  1. Set up a couple of color styles for the markers (using circle markers here)

    var blueMarker = {
      radius: 8,
      fillColor: "#0000ff"
    };
    
    var redMarker = {
      radius: 8,
      fillColor: "#ff0000"
    }
    
  2. Add the geojson features as L.circleMarkers, keeping track of each as a layer for color change. (Assuming here your feature properties have a "name" attribute; change as needed)

    var layerlist = {};  
    L.geoJson(data, {
      pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, blueMarker);
      },
      onEachFeature: function(feature, layer) {  
        layerlist[feature.properties.name]=layer;  
      }
    }).addTo(map);  
    
  3. Get the feature name from the input text box (not a plugin here, just regular html form input)

    // on change or submit
    var name = $(input).val();
    
  4. Remove the layer by name

    map.removeLayer(layerlist[name]);
    
  5. Add the layer by name, and restyle

    layerlist[name].addTo(map).setStyle(redMarker);
    

here is a rough, general approach, with a few code examples (using jQuery/javascript):

  1. Set up a couple of color styles for the markers (using circle markers here)

    var blueMarker = {
      radius: 8,
      fillColor: "#0000ff"
    };
    
    var redMarker = {
      radius: 8,
      fillColor: "#ff0000"
    }
    
  2. Add the geojson features as L.circleMarkers, keeping track of each as a layer for color change. (Assuming here your feature properties have a "name" attribute; change as needed)

    var layerlist = {};  
    L.geoJson(data, {
      pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, blueMarker);
      },
      onEachFeature: function(feature, layer) {  
        layerlist[feature.properties.name]=layer;  
      }
    }).addTo(map);  
    
  3. Get the feature name from the input text box

    var name = $(input).val();
    
  4. Remove the layer by name

    map.removeLayer(layerlist[name]);
    
  5. Add the layer by name, and restyle

    layerlist[name].addTo(map).setStyle(redMarker);
    

here is a rough, general approach, with a few code examples (using jQuery/javascript):

  1. Set up a couple of color styles for the markers (using circle markers here)

    var blueMarker = {
      radius: 8,
      fillColor: "#0000ff"
    };
    
    var redMarker = {
      radius: 8,
      fillColor: "#ff0000"
    }
    
  2. Add the geojson features as L.circleMarkers, keeping track of each as a layer for color change. (Assuming here your feature properties have a "name" attribute; change as needed)

    var layerlist = {};  
    L.geoJson(data, {
      pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, blueMarker);
      },
      onEachFeature: function(feature, layer) {  
        layerlist[feature.properties.name]=layer;  
      }
    }).addTo(map);  
    
  3. Get the feature name from the input text box (not a plugin here, just regular html form input)

    // on change or submit
    var name = $(input).val();
    
  4. Remove the layer by name

    map.removeLayer(layerlist[name]);
    
  5. Add the layer by name, and restyle

    layerlist[name].addTo(map).setStyle(redMarker);
    
Source Link
toms
  • 7.1k
  • 1
  • 26
  • 31

here is a rough, general approach, with a few code examples (using jQuery/javascript):

  1. Set up a couple of color styles for the markers (using circle markers here)

    var blueMarker = {
      radius: 8,
      fillColor: "#0000ff"
    };
    
    var redMarker = {
      radius: 8,
      fillColor: "#ff0000"
    }
    
  2. Add the geojson features as L.circleMarkers, keeping track of each as a layer for color change. (Assuming here your feature properties have a "name" attribute; change as needed)

    var layerlist = {};  
    L.geoJson(data, {
      pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, blueMarker);
      },
      onEachFeature: function(feature, layer) {  
        layerlist[feature.properties.name]=layer;  
      }
    }).addTo(map);  
    
  3. Get the feature name from the input text box

    var name = $(input).val();
    
  4. Remove the layer by name

    map.removeLayer(layerlist[name]);
    
  5. Add the layer by name, and restyle

    layerlist[name].addTo(map).setStyle(redMarker);