Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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_Leaflet - Fatal编程技术网

Javascript 页面上的传单加载打开所有标记的弹出窗口

Javascript 页面上的传单加载打开所有标记的弹出窗口,javascript,leaflet,Javascript,Leaflet,我正在使用0.7.7版的传单.js和1.3.0版的传单实时实现实时标记。工作正常。但在地图加载时,我需要打开所有标记的弹出窗口。 我使用了.openPopup()和openOn(),但不适用于我 我的小提琴是: var-map=L.map('map').setView([48.517,18.255],5); L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png'{ 属性:“©;贡献者” }).addTo(地图); var shipLa

我正在使用0.7.7版的传单.js和1.3.0版的传单实时实现实时标记。工作正常。但在地图加载时,我需要打开所有标记的弹出窗口。 我使用了.openPopup()和openOn(),但不适用于我

我的小提琴是:

var-map=L.map('map').setView([48.517,18.255],5);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png'{
属性:“©;贡献者”
}).addTo(地图);
var shipLayer=L.layerGroup();
var=L.icon({
伊克努尔:'https://upload.wikimedia.org/wikipedia/commons/thumb/9/97/Emoji_u1f6a2.svg/30px-Emoji_u1f6a2.svg.png',
iconSize:[30,30]
});
var realtime=L.realtime(
/*
我提供了一个模拟GeoJSON服务的函数,
而不是URL
{
url:'jsonServlet/ships.json',
交叉起源:对,
键入:“json”
}*/
函数(成功、错误){
var ship=mockShip();
成功(船);
}, {
间隔:5*1000,
getFeatureId:函数(featureData){
返回featureData.properties.mmsi;
},
pointToLayer:功能(特性、latlng){
marker=L.marker(latlng,{icon:ships});
marker.bindpoop('mmsi:'+feature.properties.mmsi+
“
课程:”+feature.properties.hdg+ “
速度:”+feature.properties.sog); marker.addTo(发货人); 返回标记; } }).addTo(地图); //addOverlayer(geojson,“Ships”); realtime.on('update',function()){ fitBounds(realtime.getBounds(),{maxZoom:5}); }); 函数mockShip(){ 返回{ “类型”:“FeatureCollection”, “crs”:{ “类型”:“名称”, “财产”:{ “名称”:“urn:ogc:def:crs:ogc:1.3:CRS84” } }, “特点”:[ { “几何学”:{ “坐标”:[ 48.517+Math.sin((新日期).getTime())*2, 18.255 ], “类型”:“点” }, “类型”:“功能”, “财产”:{ “几何/坐标/经度”:“48.517708”, “几何/类型”:“点”, “mmsi”:“512131345”, “几何/坐标/纬度”:“18.255447”, “hdg”:“108”, “cog”:“108”, “sog”:“30.0”, “类型”:“特征” } }, { “几何学”:{ “坐标”:[ 48.415, 18.151+Math.sin((新日期).getTime())*2 ], “类型”:“点” }, “类型”:“功能”, “财产”:{ “几何/坐标/经度”:“48.417708”, “几何/类型”:“点”, “mmsi”:“612131346”, “几何/坐标/纬度”:“18.155447”, “hdg”:“108”, “cog”:“108”, “sog”:“30.0”, “类型”:“特征” } } ] }; }
我将引用以下内容:

使用Map#openPopup打开弹出窗口,同时确保一次只打开一个弹出窗口(推荐使用),或者使用Map#addLayer打开任意数量的弹出窗口

我会引述:

使用Map#openPopup打开弹出窗口,同时确保一次只打开一个弹出窗口(推荐使用),或者使用Map#addLayer打开任意数量的弹出窗口

 var map = L.map('map').setView([48.517,18.255], 5);

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

    var shipLayer = L.layerGroup();
    var ships = L.icon({
        iconUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/97/Emoji_u1f6a2.svg/30px-Emoji_u1f6a2.svg.png',
        iconSize: [30, 30]
    });

    var realtime = L.realtime(
        /*
        I'm providing a function to simulate a GeoJSON service,
        instead of an URL

        {
        url: 'jsonServlet/ships.json',
        crossOrigin: true,
        type: 'json' 
        }*/
      function(success, error){
        var ship = mockShip();
        success(ship);
      }, {
        interval: 5 * 1000,
        getFeatureId: function(featureData){
          return featureData.properties.mmsi;
        },
        pointToLayer: function (feature, latlng) {
          marker = L.marker(latlng, {icon: ships});
          marker.bindPopup('mmsi: ' + feature.properties.mmsi +
                           '<br/> course:' + feature.properties.hdg+
                           '<br/> speed:' + feature.properties.sog);
          marker.addTo(shipLayer);
          return marker;
        }

    }).addTo(map);
    //controlLayers.addOverlay(geojson, 'Ships');

    realtime.on('update', function() {
        map.fitBounds(realtime.getBounds(), {maxZoom: 5});
    });

    function mockShip() {
      return {
        "type": "FeatureCollection",
        "crs": {
          "type": "name",
          "properties": {
            "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
          }
        },
        "features": [
          {
            "geometry": {
              "coordinates": [
                48.517+Math.sin((new Date).getTime())*2,
                18.255
              ],
              "type": "Point"
            },
            "type": "Feature",
            "properties": {
              "geometry/coordinates/longitude": "48.517708",
              "geometry/type": "Point",
              "mmsi": "512131345",
              "geometry/coordinates/latitude": "18.255447",
              "hdg": "108",
              "cog": "108",
              "sog": "30.0",
              "type": "Feature"
            }
          },
          {
            "geometry": {
              "coordinates": [
                48.415,
                18.151+Math.sin((new Date).getTime())*2
              ],
              "type": "Point"
            },
            "type": "Feature",
            "properties": {
              "geometry/coordinates/longitude": "48.417708",
              "geometry/type": "Point",
              "mmsi": "612131346",
              "geometry/coordinates/latitude": "18.155447",
              "hdg": "108",
              "cog": "108",
              "sog": "30.0",
              "type": "Feature"
            }
          }
        ]
      };
    }