2016-11-08 19 views
0

Leaflet JS - changing esri shape into marker on certain zoom level 」私は私がleaflet JSライブラリとしていた問題を解決することができたとポリゴン形状にマーカーのアイコンを変更しますをズームしたときに表示されます。リーフレットJS + Leaflet.Deflate - 私の以前の記事でカスタムアイコンに、デフォルトのマーカーアイコンを変更する

私は 'Leaflet.Deflate'プラグインを使用するように 'Ivan Sanchez'からアドバイスを受けています。これは魅力的なものですので、さまざまな図形があるズームレベルの後にマーカーに変換されます。 カスタムマーカーアイコンにデフォルトのリーフレットマーカーアイコン、私の質問は今あるので:usinながら

カスタムマーカーアイコンデフォルトのマーカーアイコンを変更することが可能ですg 'Leaflet.ShapeFile'と 'Leaflet.Deflate'プラグインとこ​​れを行うための最良の方法は何ですか?

私はJSFiddleを作りたかったのですが、私はJSFiddleを使って形状ファイルを添付することができませんでした。私はこれまでのコードを投稿します。助けてくれてありがとうございました。

<!doctype html> 
<html lang="en"> 

<head> 
    <meta charset='utf-8' /> 
    <title>v4</title> 
    <link rel="stylesheet" type="text/css" href="lib/leaflet/leaflet.css" /> 
    <!--[if lte IE 8]> <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" /> <![endif]--> 
<link rel="stylesheet" type="text/css" href="lib/leaflet/L.Control.Sidebar.css" /> 
<style> 
    html { height: 100% } 
    body { height: 100%; margin: 0; padding: 0; } 
    #map { height: 100% } 
</style> 
</head> 

<body> 
    <div id="map"></div> 

    <script src="lib/jquery/jquery-3.1.1.min.js"></script> 
    <script src="lib/leaflet/leaflet.js"></script> 
    <script src="lib/leaflet/catiline.js"></script> 
    <script src="lib/leaflet/leaflet.shpfile.js"></script> 
    <script src="lib/leaflet/shp.js"></script> 
    <script src="lib/leaflet/L.Control.Sidebar.js"></script> 
    <script src="lib/leaflet/L.Deflate.js"></script> 

    <script> 
     // init map 
     var m = L.map('map').setView([52.472833, 1.749609], 15); 

     // clicking on the map will hide the sidebar plugin. 
     m.on('click', function() { 
      sidebar.hide(); 
     }); 

     // init Deflate plugin 
     L.Deflate({ minSize: 10 }).addTo(m); 

     // Init side bar control 
     var sidebar = L.control.sidebar('sidebar', { closeButton: true, position: 'right' }); 
     m.addControl(sidebar); 

     // Init esri shape file via leaflet.shapefile, shp.js plugin 
     var businessProperties = new L.Shapefile('data/businessshapes.zip', { style: propertyStyle, onEachFeature: propertyOnEachFeature }).addTo(m); 

     // create on-click Feature 
     function propertyOnEachFeature(feature, layer) { 
      layer.on({ 
       mouseover: highlightFeature, 
       mouseout: resetHighlight, 
       click: function populate() { 
        sidebar.toggle(); 
        document.getElementById('pinfoHeader').innerHTML = "<h2>" + feature.properties.Building + " - Detailed Information</h2><br />"; 
        document.getElementById('pTitle').innerHTML = "Name: " + feature.properties.Building 
        document.getElementById('pDetails').innerHTML = "SHAPE_Leng: " + feature.properties.SHAPE_Leng + "<br/ >SHAPE_Area: " + feature.properties.SHAPE_Area 
       }, highlightFeature, zoomToFeature 
      }); 
     } 

     // style the properties style 
     function propertyStyle(feature) { 
      return { 
       fillColor: getPropertyColor(feature.properties.BusType), 
       weight: 2, 
       opacity: 1, 
       color: 'white', 
       dashArray: 3, 
       fillOpacity: 0.7 
      } 
     } 

     // set color per property according to the data table of the Esri Shape file. 
     function getPropertyColor(propStatus) { 
      if (propStatus == 'TypeA') { 
       return 'red'; 
      } else if (propStatus == 'TypeB') { 
       return 'green'; 
      } else { 
       return 'yellow'; 
      } 
     } 

     // set the highlighted color for polygon 
     function highlightFeature(e) { 
      var layer = e.target; 
      layer.setStyle({ 
       weight: 2, 
       color: 'black', 
       fillColor: 'white', 
       fillOpacity: 0.2 
      }); 

      if (!L.Browser.ie && !L.Browser.opera) { 
       layer.bringToFront(); 
      } 
     } 

     // reset the highlighted color for polygon after mouse leave polygon 
     function resetHighlight(e) { 
      businessProperties.resetStyle(e.target); 
     } 


     //Extend the Default marker class to overwrite the leaflet.deflate marker icon??? 
     var TestIcon = L.Icon.Default.extend({ 
      options: { 
       iconUrl: 'assets/images/markers/business.png' 
      } 
     }); 
     var testIcon = new TestIcon(); 

     businessProperties.addTo(m); 

     // Init base maps for switch 
     var grayscale = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { id: 'MapID', attribution: 'Map maintained by <a href="http://www.demo.com">Demo LTD</a>, &mdash; Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>,' }).addTo(m); 
     var streets = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { id: 'MapID', attribution: 'Map maintained by <a href="http://www.demo.com">Demo LTD</a>, &mdash; Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>,' }); 

     var baseMaps = { 
      "Streets": streets, 
      "Grayscale": grayscale 
     }; 

     // Init overlay map switch 
     var overlayMaps = { 
      "Bussines Properties": businessProperties 
     }; 

     // Add switches to map control 
     L.control.layers(baseMaps, overlayMaps).addTo(m); 
    </script> 
</body> 
</html> 

答えて

2

それはLeaflet.Deflate "プラグインを使用しながら、カスタムマーカーアイコンに、デフォルトのマーカーアイコンを変更することは可能ですか?

答えはいいえです。

Leaflet.Deflateの現在のコードは、デフォルトのマーカーとデフォルトのマーカーを使用して、あなたはそれのまわりであなたの方法をハック可能性がhttps://github.com/oliverroick/Leaflet.Deflate/blob/991f51ca82e7bb14a17c8d769b4c378c4ebaf700/src/L.Deflate.js#L42

を参照してください、私はむしろLeaflet.Deflateレポで機能要求を提出する推薦します。ライン/ポリゴンフィーチャにマーカーオプションとして使用されるいくつかの追加のプロパティを持たせるために、Leaflet.Deflateレポを変更することが可能でなければなりません。

関連する問題