ng-map只能打开远程KML文件,但不能打开本地文件? [英] ng-map only opens remote KML file but not local file?

查看:286
本文介绍了ng-map只能打开远程KML文件,但不能打开本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ionic和 p>

我正在像这样加载一个本地KML文件(与远程KML文件的语法相同):

 < div style =height:100%> 
< kml-layer url =./ kml / cta.kml>< / kml-layer>
< / ng-map>
< / div>

但KML行不会显示为远程KML文件。地图已加载,但没有在KML中指定的行。



那么, ng-map 需要远程KML来加载KML规范?这是 ng-map 或Ionic目录上的错误吗?

我没有收到任何错误错误或任何可能导致错误的地方,除了本地KML文件似乎无法被读取,该规范将不会显示在地图上,不像远程KML文件。

解决方案

它不是既不是 ng-map 库也不是 Ionic ng-map 库使用 KML图层 ,这反过来不支持从本地主机或文件系统加载KML文件。



基本上你有两个选择:
$ b $ 1)将KML文件放在一个公共服务器上,谷歌服务器可以访问它, KML解析和渲染由Google服务器完成



<2>利用第三方库,如 geoxml3库,它允许您加载KML文件并解析它托管在本地主机上,如下所示:



p>

 < div ng-app =mapAppng-controller =mapController> 
< / div>

Js

  angular.module('mapApp',['ngMap'])
.controller('mapController',function($ scope,NgMap){

NgMap.getMap() .then(function(map){
$ scope.map = map;
var myParser = new geoXML3.parser({map:map});
myParser.parse('cta.kml ');
});
});

演示


I'm using Ionic and ng-map. I have to display different KMLs (one at a time and on user request). The KML loads on the map but only for remote KMLs. So this one works:

<div style="height: 100%">
  <ng-map center="41.876,-87.624" zoom="15" map-type-id="HYBRID" style="display:block; width: 100%; height:100%;">
    <kml-layer url="http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml"></kml-layer>
  </ng-map>
</div>

My local KMLs are in a kml folder inside www directory in my Ionic app.

And I'm loading a local KML file like this (same syntax as the remote KML file):

<div style="height: 100%">
  <ng-map center="41.876,-87.624" zoom="15" map-type-id="HYBRID" style="display:block; width: 100%; height:100%;">
    <kml-layer url="./kml/cta.kml"></kml-layer>
  </ng-map>
</div>

But the KML lines don't show up like the remote KML file. The map is loaded but just without the lines specified in the KML.

So, does ng-map require a remote KML to load the KML specs? Is this a bug on ng-map or Ionic directories?

I don't get any errors or anything indicating that there's anything wrong except that the local KML file can't seem to be read that the specs won't show up on the map unlike the remote KML file.

解决方案

It is not a bug neither of ng-map library nor a Ionic. ng-map library utilizes KML Layers which in turn does not support the loading of KML file from localhost or a file system.

Basically you have two options here:

1) place the KML file on a public server where google server can access it, since parsing of KML and rendering is done by Google servers

2) utilize third party library such as geoxml3 library which allows you to load KML file and parse it hosted on localhost as shown below:

Html

<div ng-app="mapApp" ng-controller="mapController">
    <ng-map center="41.876,-87.624" zoom="15" map-type-id="HYBRID" style="display:block; width: 100%; height:100%;"/>
</div>

Js

angular.module('mapApp', ['ngMap'])
    .controller('mapController', function($scope, NgMap) {

        NgMap.getMap().then(function(map) {
            $scope.map = map;
            var myParser = new geoXML3.parser({ map: map });
            myParser.parse('cta.kml');
        });
    });

Demo

这篇关于ng-map只能打开远程KML文件,但不能打开本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆