Skip to content
This repository has been archived by the owner on Jan 22, 2018. It is now read-only.

require convert2geosjon

Hsu Ting edited this page Nov 26, 2015 · 24 revisions

This is just for creating a simple map. Therefore, if you want to create a complex map, you can see mapbox api.

Example code

Map

  • Require convert2geojson.config.js:
var convert2geojson = require('convert2geojson');
var config = require('./convert2geojson.config.js');

(function() {
  convert2geojson.Map(config);
})();
  • Using an object:
var convert2geojson = require('convert2geojson');

(function() {
  convert2geojson.Map({
    output: {
      filename: '[name].geojson',
      path: './output/'
    },
    simple: {
      id: "map",
      center: {
        lat: 23.619, 
        lon: 120.795,
        zoom: 7
      },
      include: [
        {'data': {}}
      ]
    }
  });
})();

Init

  let map = convert2geojson.Init("map", {
    lat: 23.619, 
    lon: 120.795,
    zoom: 7
  }); 
  • The first argument is id for map.
  • The second argument is for setting map, and it is the same with simple.center in convert2geojson.config.js.

Add

Using this function to add geojson on the map:

  convert2geojson.Add(map, "./example/data/[name].geojson", [
    {'data': {}}
  ]);

If your data is not at local, you need to set second argument to be undefined, and add data in third argument`s object.

  var output = {"type":"Feature","geometry":{"type":"Point","coordinates":[125.6,10.1]},"properties":{"name":"Dinagat Islands"}};
  convert2geojson.Add(map, undefined, [
    {'data': {data: output}}
  ]);
  • You need to save data from Init to a variable, and give this variable to add in the first argument.
  • The second argument is the path of your file, and this form is {your path}/[name].{your file extension}. You do not change [name]. Because program will change [name] to filename.
  • The third is an array, and it is the same with simple.include in convert2geojson.config.js.
  • You can see here to know what you can add in the third argument.

Input

Using this function to get goejson:

  var output = convert2geojson.Input(data, "temp." + type, symbol);
  • The second argument is filename, and type is this file`s type. If you need to give many files, you need to change file name.
  • symbol is identical with symbol in convert2geojson.config.js.

Adding a function to modify the data before this program converts data to geojson:

function handleFunction(d) {
  d[0].data[0].name = "try_1";
  return d;
};
var output = convert2geojson.Input(data, "temp." + type, symbol, handleFunction);

Set

  $(".simple-map-set").click(function() { convert2geojson.Set(map); }); 
  • This is set map to user`s GPS positioning.

Reset

  $(".simple-map-reset").click(function() {
    convert2geojson.Reset(map, {
      lat: 23.619, 
      lon: 120.795,
      zoom: 7
    }); 
  });
  • You need to save data from Init to a variable, and give this variable to add in the first argument.
  • Reset map at the place where you set.
Clone this wiki locally