我正在更新一个曾经使用"bencoding.map“https://github.com/benbahrenburg/benCoding.Map/blob/master/documentation/index.md的应用程序。
现在"bencoding.map“被弃用了,所以我更新为使用原生的钛地图特性。
然而,我现在遇到了一个问题,来自"bencoding.map“的"addKML”在Titanium map 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
}
});发布于 2017-02-06 05:33:15
一种选择是将kml数据转换为JSON,然后根据数据需要,通过映射模块的方法(如createPolygon、createPolyline等)将数据添加到本机Titanium Map。
我已经使用togeojson Node.js模块做到了这一点。从Titital6开始,我们现在可以直接从我们的项目中访问Node模块。假设您使用的是一个合金项目:
cd MyProject/app/assets
npm install togeojson这还将安装一些其他依赖模块,包括我们也可以使用的xmldom。
获取一些sample KML LineString data并将其放在MyProjects/app/assets中,然后我们可以使用togeojson模块对其进行转换。这会让我们走到一半。Titanium模块不会说GeoJSON,但是因为GeoJSON只是JSON,所以我们可以遍历它并获取所需的数据,然后将其提供给相关的Map模块方法。
下面是通过向地图的createPolyline方法发送KML数据来完成所有这些操作的示例。假设这个合金index.js控制器有一个带有' map‘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
});https://stackoverflow.com/questions/41974128
复制相似问题