This repository has been archived by the owner on Jan 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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.
- Not using config.js -> Demo
- Using function Map -> Demo
- Getting data from a link -> Demo
- Getting data from a local file -> Demo
- 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': {}}
]
}
});
})();
- If you do not know how to set
convert2geojson.config.js
, seeing create a simple map.
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
inconvert2geojson.config.js
.
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]
tofilename
. - The third is an array, and it is the same with
simple.include
inconvert2geojson.config.js
. - You can see here to know what you can add in the third argument.
Using this function to get goejson:
var output = convert2geojson.Input(data, "temp." + type, symbol);
- The second argument is
filename
, andtype
is this file`s type. If you need to give many files, you need to change file name. -
symbol
is identical withsymbol
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);
$(".simple-map-set").click(function() { convert2geojson.Set(map); });
- This is set map to user`s GPS positioning.
$(".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.