Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Map file not found #11

Closed
egofree71 opened this issue Jul 19, 2015 · 3 comments
Closed

Map file not found #11

egofree71 opened this issue Jul 19, 2015 · 3 comments

Comments

@egofree71
Copy link

Hello,

I try to use the plugin with the Ionic framework. When i run it in the android emulator with genymotion, i've always the same error message in the console : 'Map file not found'. Here is the code in the controller :

$ionicPlatform.ready(function() {

  var mapfile = "/sdcard/Download/albania.map";

  // initialize the map on the "map" div with a given center and zoom
  var map = L.map('map', {
      center: [41.328341,19.818761],
      zoom: 9
  });

  mapsforge.cache.initialize(mapfile,
      function() {
          console.log("map file loaded");
          L.offlineTileLayer({
              maxZoom: 18,
              attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
          }).addTo(map);

      },
      function(error) {
          console.log("error loading map file: " + mapfile);
          console.dir("error:" + error);
      });

}

I've uploaded the 'map into the download folder by dragging the file into the emulator, and i can see the file in the file manager of the emulator. I tested many different paths (for instance /storage/emulated/0/Download/albania.map, /sdcard/Download/albania.map, etc.), but the plugin never finds the map file . Also by default, the map is stored within my project in the www/data folder. So i tried also '/android_asset/www/data' or 'file:///android_asset/www/data' folders, but it's not working.
Do you have any idea how to specify the folder ?

@afsuarez
Copy link
Owner

Hello.
I've been checking it out and I could load the map (I put an alert in both callback functions to see if it was working).

Emulator

I placed the file under /storage/sdcard, as you can see below:

DDMS

If you place it under 'Download' for example, try /storage/sdcard/Download/albania.map or /mnt/sdcard/Download/albania.map.

The way it is done in the code is like this:

SetMapFileMethod

So the path you pass is the path it is going to look for.

WWW folder

Abour placing it under the www folder....I don't know, I mean, I'm not sure how cordova packages that folder so trying to guess its path it is going to be difficult. If you want to include the map in your application from the begining I would place it under the www and then through javascript load it from that folder and save it to the android filesystem with the File API plugin (since I guess you will be able to get the file with a simple path like js/albania.map or data/albania.map like you would do to get CSS or JS files).

@egofree71
Copy link
Author

Thanks for your help.

@egofree71 egofree71 reopened this Jul 23, 2015
@egofree71
Copy link
Author

I've worked again on this problem, and i've finally found a solution. I write my results here, as it could be useful for others. First, it's doesn't seem possible for security reason to access directly files stored in the project folder :
"Chrome requires --allow-file-access-from-files run argument to support API via file:/// protocol."

https://github.com/apache/cordova-plugin-file

A solution is to download and store the map in the /Download folder of the sdCard (/mnt/sdcard/Download/albania.map)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants