-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
158 lines (120 loc) · 3.92 KB
/
app.js
File metadata and controls
158 lines (120 loc) · 3.92 KB
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
var L = require('leaflet');
var popup = L.popup();
L.Icon.Default.imagePath = 'node_modules/leaflet/dist/images';
var myStyle = {
"color": "#ff7800",
"opacity": 0.4,
"weight": 0
};
var map = L.map('map');
map.setView([32.5385291729546, -117.186767353706], 1);
var attribution = '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
var tiles = 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png';
var layer = L.tileLayer(tiles, {
maxZoom: 18,
attribution: attribution
});
layer.addTo(map);
// Layer last highighed
var highlight;
// Function to handle a click on a polygon
function onclick(e){
if (highlight){
map.removeLayer(highlight);
}
var x = e.latlng.lng;
var y = e.latlng.lat;
var layerData = leafletPip.pointInLayer([x,y], pickLayer);
if (!layerData[0]) {
console.log('nothing picked');
}else {
var i;
var len = layerData.length;
var fname=[];
var maxPS=[];
for (i = 0; i < len; i++) {
fname[i] = layerData[i].feature.properties.Name;
maxPS[i] = layerData[i].feature.properties.MaxPS;
}
highlight = new L.geoJson(geoSat, {
filter: function(feature, layer) {
var i;
var len = fname.length;
for (i = 0; i < len; i++) {
return feature.properties.Name == fname[i];
}
},
style: {color: 'skyblue', fillColor: 'skyblue'}}).addTo(map);
var popup = '';
for (i = 0; i < len; i++) {
popup += 'Map: ' + fname[i] + '<hr>' + ' MaxPS: ' + maxPS[i] + '<hr>';
}
var myPopup = L.popup({
maxHeight: 300,
keepInView: true
}).setContent(popup);
myPopup.setLatLng(e.latlng);
myPopup.addTo(map);
myPopup.openOn(map);
//map.openPopup(popup, e.latlng);
map.on('popupclose', function() {
map.removeLayer(highlight)
highlight = null;
});
}
};
// We need go create a json layer for the map but we don't
// add it to the map since we are drawing the layer via the tiles,
// but we still need the layer to find the map if it gets selected
var pickLayer = L.geoJson(geoSat);
// Interact with geojson data represented by the tile layer
map.on('click', onclick);
var tileOptions = {
maxZoom: 20, // max zoom to preserve detail on
tolerance: 5, // simplification tolerance (higher means simpler)
extent: 4096, // tile extent (both width and height)
buffer: 64, // tile buffer on each side
debug: 0, // logging level (0 to disable, 1 or 2)
indexMaxZoom: 1, // max zoom in the initial tile index
indexMaxPoints: 10000000, // max number of points per tile in the index
};
var tileIndex = geojsonvt(geoSat, tileOptions);
var tileLayer = new L.TileLayer.Canvas();
tileLayer.drawTile = function (canvas, tileLoc, zoom) {
var ctx = canvas.getContext('2d');
var tileSize = this.options.tileSize;
ctx.globalCompositeOperation = 'source-over';
var tile = tileIndex.getTile(zoom, tileLoc.x, tileLoc.y);
if (!tile) {
console.log('tile empty');
return;
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
var features = tile.features;
var pad = 0;
ctx.strokeStyle = 'orange';
for (var i = 0; i < features.length; i++) {
var feature = features[i],
type = feature.type;
ctx.fillStyle = feature.tags.color ? feature.tags.color : 'rgba(255, 120,0,0.4)';
ctx.beginPath();
for (var j = 0; j < feature.geometry.length; j++) {
var geom = feature.geometry[j];
if (type === 1) {
ctx.arc(geom[0] * ratio + pad, geom[1] * ratio + pad, 2, 0, 2 * Math.PI, false);
continue;
}
for (var k = 0; k < geom.length; k++) {
var p = geom[k];
var extent = 4096;
var x = p[0] / extent * 256;
var y = p[1] / extent * 256;
if (k) ctx.lineTo(x + pad, y + pad);
else ctx.moveTo(x + pad, y + pad);
}
}
if (type === 3 || type === 1) ctx.fill('evenodd');
ctx.stroke();
}
};
tileLayer.addTo(map);