带有GeoJSON奇怪表示的MarkerCluster

时间:2017-09-14 13:46:06

标签: javascript leaflet openstreetmap markerclusterer

这是我的剧本,对不起,如果它有点乱,我已经尝试了很多......

<script>
     var geojsonObject = #{jsonDataModel.jsonData};

     var markerIcon = L.icon({
         iconUrl: '#{request.contextPath}/images/pin48.png',
         iconAnchor:   [17,43] // point of the icon which will correspond to marker's location
         });

      <!--Initialisieren der Karte mit Angabe der Koordinate und der Zoomstufe:-->
      var mapLat = #{jsonDataModel.centerLat};
      var mapLon = #{jsonDataModel.centerLon};
      var zoom = #{jsonDataModel.zoom};
        var map = L.map('map').setView([mapLat, mapLon], zoom);

        <!--Laden eines Layers mit Angabe der URL auf den OpenStreetMap-Kartendienst sowie einem Kartenlabel:-->
        L.tileLayer(#{geodataserverurlreader.geodataserverUrl}, {
            attribution: '&amp;copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap-Mitwirkende</a>. ',
            maxZoom: 18,
        }).addTo(map);

        L.tileLayer('http://a.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png',{
            attribution: 'Daten <a href="http://www.openstreetmap.org/copyright">© OpenStreetMap-Mitwirkende</a>, Grafik: <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA 2.0</a> <a href="http://www.openrailwaymap.org/">OpenRailwayMap</a>',
            maxZoom: 18,
            minZoom: 10,
        }).addTo(map);

        L.tileLayer('http://{s}.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png',{
            attribution: 'Daten <a href="http://www.openstreetmap.org/copyright">© OpenStreetMap-Mitwirkende</a>, Grafik: <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA 2.0</a> <a href="http://www.openrailwaymap.org/">OpenRailwayMap</a>',
            maxZoom: 18,
        }).addTo(map);

        var markers = L.markerClusterGroup();

        var oms = new OverlappingMarkerSpiderfier(map);

        var geoJsonLayer = L.geoJSON(geojsonObject, {
            onEachFeature: onEachFeature,
            pointToLayer : function(feature, latlng){
               var marker = L.marker(latlng);
//             oms.addMarker(marker);
               return marker;
            }
            });

        markers.addLayer(geoJsonLayer);

        map.addLayer(markers);

  </script>

所以现在我想知道我错过了什么:

  1. 我已将tileLayer添加到地图中。
  2. 我初始化了markerCluster
  3. 我(希望)将geoData正确添加到图层(geoJsonLayer
  4. 我将这些图层添加到markerCluster
  5. 我将markerCluster添加到地图中。
  6. 此外,我确保我的宣传单脚本之前标记集群。

    <script src="#{request.contextPath}/lib/leaflet/leaflet-src.js" />
    <script src="#{request.contextPath}/lib/leaflet/leaflet.markercluster-src.js" />
    
    <script src="#{request.contextPath}/js/oms.js" />
    <script src="#{request.contextPath}/js/oneachfeature.js" />
    

    我的结果如下: weird lines and stuff

    (这些行添加了第3个L.tileLayer

    任何人都知道我做错了什么?

    地理数据

    {  
       "totalFeatures":2,
       "features":[  
          {  
             "geometry":{  
                "coordinates":[  
                   10.111521,
                   54.3688972
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>: 928012610566 / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 03.11.2011 09:20:00"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   9.9738655,
                   53.4957533
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>: 928012610368 / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 03.10.2011 09:00:17"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   11.4343346,
                   50.5976445
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>:  / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 01.06.2011 09:07:30"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   11.3753961,
                   50.6505401
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>:  / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 05.08.2010 10:00:12"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   9.9325934,
                   53.5313402
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>: 928012610376 / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 06.08.2012 14:56:23"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   9.6329706,
                   53.7676329
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>:  / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 05.08.2010 14:51:40"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   9.6329706,
                   53.7676329
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>:  / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 05.08.2010 14:51:40"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   8.2252779,
                   53.1435944
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>: 928012650174 / <br><b>Auslösungsart<\/b>: ?? STOERCODE ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 06.06.2017 15:16:11"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   8.7582774,
                   51.7287785
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>: 928012650166 / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 06.06.2017 15:44:46"
             }
          },
          {  
             "geometry":{  
                "coordinates":[  
                   11.4343346,
                   50.5976445
                ],
                "type":"Point"
             },
             "type":"Feature",
             "properties":{  
                "popupContent":"<b>Fz/Tz<\/b>:  / <br><b>Auslösungsart<\/b>: ?? ZEIT ??<br><b>Code<\/b>: <br><b>Text<\/b>: <br><b>Ereigniszeit<\/b>: 01.06.2011 09:07:30"
             }
          }
        .
        .
        .
    
       ],
       "type":"FeatureCollection"
    }
    

    VALID JSON(RFC 4627)

    即使使用geojson.io测试我的geojson数据也能为我提供有效的标记。 (无法链接,因为我的代表太低了。)

    预期结果

    这是想要的result

0 个答案:

没有答案