2017-02-01 2 views
0

"bencoding.map" https://github.com/benbahrenburg/benCoding.Map/blob/master/documentation/index.mdを使用していたAppceleratorアプリをアップデートしています。bencoding.mapでKMLに代わるAppcelerator

"bencoding.map"は非推奨になっていますので、ネイティブのチタニウムマップ機能を使用するように更新しました。

しかし、 "bencoding.map"の "addKML"がTitaniumマップAPIで使用できないという問題がありました。

私はKMLの機能を置き換えるために何が使えるのか誰にでも分かりますか?以下のコードは次のとおりです。

function onkmlCompleted(){ 
     Ti.API.info("onkmlCompleted"); 
     Ti.API.info("onkmlCompleted"+JSON.stringify(mapLoadingWindow)); 
     mapLoadingWindow.close({animated:false}); 
     mapView.removeEventListener('kmlCompleted',onkmlCompleted); 
    }; 

    mapView.addEventListener('kmlCompleted',onkmlCompleted); 

    mapView.addKML({ 
     path:"some_file.kml", //Path to our kml file 
     tag : 55, //Integer value used as the tag for all polygons and annotations. If you want use remove you need to set this to a known value. 
     flyTo:false, //Will set your zoom to show all of your points added (false by default)   
     //Contains all of the details used to process overlays from your KML file 
     overlayInfo:{ 
      title:'my kml batch key', //This identifies all of the overlay elements in your kml file. This is also used for delete or query operations. 
      alpha:0.5, //Alpha value of your overlays 
      lineWidth:1.2, //Line Width of your overlays 
      strokeColor:'#000', //Stroke Color of your overlays 
      color:'yellow', //Sets the color of all your overlays (if left off, a random color will be selected) 
      useRandomColor:true, //If true, a random color will be selected, this overrides the color provided if true    
     } 
    }); 

答えて

1

1つのオプションは、あなたのデータとして、そしてなどcreatePolygon、createPolyline、としてマップモジュールのメソッドを介してネイティブTitanium Mapにデータを追加し、JSONにKMLデータを変換することです必要です。

これは、togeojson Node.jsモジュールを使用して行っています。 Titanium 6以降、プロジェクト内からノードモジュールに直接アクセスできるようになりました。あなたは合金のプロジェクトを使用していると仮定すると:

cd MyProject/app/assets 
npm install togeojson 

これはまた、我々は同様に使用することができますxmldom、を含むいくつかの他の依存モジュールをインストールします。

sample KML LineString dataをとり、MyProjects/app/assetsに入れると、togeojsonモジュールを使用して変換できます。これは私たちの半分をそこに得るでしょう。チタニウムマップモジュールはGeoJSONを話しませんが、GeoJSONは単なるJSONなので、それを繰り返し処理して必要なデータを取得し、それを関連するMapモジュールメソッドに渡すことができます。

以下は、KML LineStringデータをマップのcreatePolylineメソッドに送信することによってすべてを行う例です。このアロイindex.jsのコントローラに、マップ上に「マップ」というIDのマップビューがあるとします。

//the titanium map module 
var Map = require('ti.map'); 
//the node module we installed 
var togeojson = require('togeojson'); 
//a dependency of togeojson which we will also use 
var DOMParser = require('xmldom').DOMParser; 

//with out data file in apps/assets 
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "linestring.kml"); 
var kml = file.read().text; 

//the module requires the xml data in XML DOM, so we parse it first 
var xml = (new DOMParser()).parseFromString(kml, 'text/xml'); 

//convert the kml to GeoJSON 
var converted = togeojson.kml(xml); 

//Here, we iterate through the GeoJSON file and pull out the coordinates to use to 
//create our Map polygons, polylines, etc. Your implementation will vary depending 
//on the data you are reading 
converted.features.forEach(function(feature){ 
    if(feature.geometry.type === 'LineString') 
    $.map.addPolyline(Map.createPolyline({ 
     points: feature.geometry.coordinates, 
     strokeColor: '#ff0000', 
     strokeWidth: '2' 
    })); 
}); 

$.map.setRegion({ 
    latitude: 37.824664, 
    latitudeDelta: 0.002, 
    longitude: -122.364383, 
    longitudeDelta: 0.002 
});