-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmap-test.js
269 lines (246 loc) · 8.86 KB
/
gmap-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
var gm = require('googlemaps'),
esri2geo = require('esri2geo'),
util = require('util'),
http = require('http'),
phantom = require('phantom'),
fs = require('fs'),
request = require('request'),
simplify = require('simplify-geojson'),
gju = require('geojson-utils');
gm.config({'encode-polylines': true});
function getLayer(url, next){
// console.log(arguments);
// console.log('getting', url);
http.get(url, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
var json = JSON.parse(body)
if(next)
next(json)
});
}).on('error', function(e) {
console.log("Got error: ", e);
});
}
// function handleEsriJSON(next, esrijson){
// // console.log(json, arguments)
// var geoJSON,
// cb = next;
// esri2geo(esrijson,cb);
// }
function handleTerminals(next, layers, err, json){
// console.log(arguments, Object.keys(arguments).length);
// console.log(layers);
var createImages = [];
if(json.features)
var simplified = simplify(json, 0.0001);
simplified.features.forEach(function(feature){
var terminal = feature.properties.TermnialName,
Terminal_ID = feature.properties.Terminal_ID,
geom = feature.geometry;
// console.log(terminal)
// if(terminal==='TraPac Terminal'){
var center = gju.centroid(geom).coordinates.reverse();
// var center = gju.rectangleCentroid(geom);
console.log(center);
var coords = [];
geom.coordinates.forEach(function(coord){
coord.forEach(function(a){
a.reverse();
coords.push(a.join(','));
})
});
var paths = [
{
'color': 'red',
// 'fillcolor': 'yellow',
'weight': '4',
'points':coords
}
]
for(var name in layers){
var layer = layers[name]
if(layer.Terminal_ID === Terminal_ID){
// console.log(layer.name, 'matched', Object.keys(layer));
paths.push(layer.path);
}
}
// console.log(coords.length, paths.length);
createImages.push(
function(){
getBuildings(
gju.boundingBoxAroundPolyCoords(geom.coordinates).join(','),
function(buildings){
// console.log('buildings', buildings)
layers.buildings = buildings;
paths.push(buildings.paths)
paths.reverse();
createImage(
// .bind(
// this,
// 'Oakland, CA', 15, '600x400', false, false, 'satellite'));//, markers, styles, paths
gm.staticMap( center, 16, '2400x1600', 2/*scale*/, false, false, 'satellite', false/*markers*/, false/*styles*/, paths),
'c:/temp/'+terminal.replace('/', ' - ').replace('\\', ' - ')+'.jpg',
function(){
if(createImages.length>0)
createImages.shift()();
else
console.log('done');
}
)
}
)
}
);
// }
})
if(next)
next(createImages)
}
function cyclethrough(){
for(var arg in arguments){
if(arguments[arg] instanceof Array)
arguments[arg].shift()()
}
}
function download(uri, filename, callback){
request.head(uri, function(err, res, body){
// console.log('content-type:', res.headers['content-type']);
// console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', function(){console.log(arguments, 'complete'); if(callback)callback()});
});
};
function createImage(url, filename, next){
console.log('image url:', url, 'output', filename);//, markers, styles, paths))
download(url, filename, next);
// phantom.create(function(ph){
// ph.createPage(function(page) {
// page.set("paperSize", { format: "A4", orientation: 'landscape', margin: '1cm' });
// page.open(url, function(status) {
// page.render("c:/temp/dwr-lep.pdf", function(){
// console.log("page rendered");
// ph.exit();
// })
// })
// })
// })
}
function processBerths(next, err, json){
var berths = {};
var simplified = simplify(json, 0.0001);
simplified.features.forEach(function(feature){
var Terminal_ID = feature.properties.Terminal_ID,
name = feature.properties.Berth
geom = feature.geometry;
// console.log(Terminal_ID, name);
// if(terminal==='TraPac Terminal'){
// var center = gju.rectangleCentroid(geom);
var coords = [];
geom.coordinates.forEach(function(coord){
coord.forEach(function(a){
a.reverse();
coords.push(a.join(','));
})
});
var path = {
'color': 'blue',
'weight': '2',
'points':coords
};
// console.log(coords);
berths[name] = {
name: name,
Terminal_ID : Terminal_ID,
path : path
}
})
return next(berths);
}
function processBuldingss(next, err, json){
var buildings = {}, markers = [];
// console.log(arguments);
// console.log(next,layers,err, json);
var simplified = simplify(json, 0.001);
simplified.features.forEach(function(feature){
var geom = feature.geometry;
var coords = [];
geom.coordinates.forEach(function(coord){
coord.forEach(function(a){
a.reverse();
coords.push(a.join(','));
})
});
var paths = {
'color': '0x151515ff',
'weight': '1',
'fillcolor' : '0x545454ff',
'points':coords
};
buildings.paths = paths;
markers.push(
{ 'location': gju.centroid(geom) }
)
// { 'location': '1333 Broadway Oakland, CA',
// 'color': 'red',
// 'label': 'A',
// 'shadow': 'true',
// 'icon' : 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600'
// }
// ]
})
buildings.markers = markers;
return next(buildings);
}
function getGates(){
'http://jls-gispweb1.portoakland.internal/arcgis/rest/services/Essentials/Base_fences/MapServer/1'
}
function getBuildings(bounds, next){
// console.log(next, arguments);
var url = 'http://jls-gispweb1.portoakland.internal/arcgis/rest/services/Essentials/Base_structures/MapServer/1/query?where=1%3D1&text=&objectIds=&time=&geometry='+ bounds +'&geometryType='+ 'esriGeometryEnvelope' +'&inSR='+ 4326 +'&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=4326&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&f=pjson'
getLayer(url, function process(esriJson){
esri2geo(esriJson, processBuldingss.bind(this, next));
} )
}
function getBerths(layers){
var url = 'http://jls-gispweb1.portoakland.internal/arcgis/rest/services/Essentials/Base_boundaries/MapServer/3/query?where=1%3D1&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=4326&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&f=pjson'
getLayer(url, function process(esriJson){
esri2geo(esriJson, processBerths.bind(this, getTerminals));
} )
}
function getTerminals(layers){
var url = 'http://jls-gispweb1.portoakland.internal/arcgis/rest/services/Essentials/Base_boundaries/MapServer/1/query?where=1%3D1&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=4326&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&f=pjson'
getLayer(url, function process(esriJson){
esri2geo(esriJson, handleTerminals.bind(this, cyclethrough, layers))
} )
}
getBerths();
// createImage(gm.staticMap('Oakland, CA', 15, '600x400', false, false, 'satellite'), 'c:/temp/gmap.jpg')
// gm.reverseGeocode('41.850033,-87.6500523', function(err, data){
// util.puts(JSON.stringify(data));
// });
// gm.reverseGeocode(gm.checkAndConvertPoint([41.850033, -87.6500523]), function(err, data){
// util.puts(JSON.stringify(data));
// });
// markers = [
// { 'location': '246 4th St Davis, CA' },
// { 'location': '1333 Broadway Oakland, CA',
// 'color': 'red',
// 'label': 'A',
// 'shadow': 'true',
// 'icon' : 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600'
// }
// ]
// styles = [
// { 'feature': 'road', 'element': 'all', 'rules':
// { 'hue': '0x00ff00' }
// }
// ]
// paths = [
// { 'color': '0x0000ff', 'weight': '5', 'points':
// [ '41.139817,-77.454439', '41.138621,-77.451596' ]
// }
// ]
// util.puts(gm.staticMap('Oakland, CA', 15, '600x400', false, false, 'satellite'));//, markers, styles, paths));