1

In the code below the point links are embeded in GeoJSON object places_geojson. How could we make the link to be opened in a new tab?

I believe that this functionality need to be added in the layerGroup layer href section.

Here is the code:

// Define spatial data in GeoJSON format
    var places_geojson={"type":"FeatureCollection","features":
[
    {"type":"Feature","geometry":{"type":"Point","coordinates":[-4.145212,51.569558]},"properties":{"id":1,"condition":"Location 1, Coordinates: -4.145212,51.569558","Link":"http://localhost/condition_0001.jpg "}},
{"type":"Feature","geometry":{"type":"Point","coordinates":[-4.14523,51.569542]},"properties":{"id":2,"condition":"Location 2, Coordinates: -4.14523,51.569542","Link":"http://localhost/new1.html"}}
]}

    // Define map
var map = L.map('mapid', {
    center: [51.565, -4.153],
    minZoom: 1,
    zoom: 14,
    layers: googleSLayer
});
// Map Control 
L.control.layers(baseLayers).addTo(map); 

// Adding GeoJSON layer with the data to the map and creating marker with popup for each feature
var layerGroup = L.geoJSON(places_geojson, {
        onEachFeature: function (feature, layer) {
            layer.bindPopup("<a href='" + feature.properties.Link + "'>" + feature.properties.condition + "</a>")
  }
})
.addTo(map);
  • If you read carefully the answer to your past question gis.stackexchange.com/questions/347113/…, you'll find answer to your question there. – TomazicM Feb 12 at 17:01
  • I have tried "target="_blank" on several places. However, did not find the solution. It is not in the link within the GeoJson. – Iliyan Iliev Feb 12 at 18:16
  • 1
    layer.bindPopup("<a href='" + feature.properties.Link + "' target='_blank'>" + feature.properties.condition + "</a>") – MattM Feb 12 at 19:16
  • Thanks Matt. I knew that it must be simple :) – Iliyan Iliev Feb 12 at 19:36