Skip to content

Instantly share code, notes, and snippets.

@marguslt
Last active December 25, 2019 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marguslt/3bc9b264bf4abd31e87e872f4550c4c2 to your computer and use it in GitHub Desktop.
Save marguslt/3bc9b264bf4abd31e87e872f4550c4c2 to your computer and use it in GitHub Desktop.
Random Chrome snippets

Random js snippets for Chrome dev tools

/*
Movescount GeoJSON points.
Adds point features from geojson (i.e. Overpass query results ) to Movescount (or any other Mapbox) map.
*/
mapboxgl.MapElement.addLayer({
'id': 'geojson_circles_' + mapboxgl.MapElement.getStyle().layers.length,
'type': 'circle',
'source': {
'type': 'geojson',
'data': JSON.parse(prompt("paste GeoJSON"))
},
'paint': {
'circle-radius': 6,
'circle-color': '#e3700b',
'circle-opacity': 0.8
}
})
/*
Add tms layer from Estonian land Board (https://www.maaamet.ee/) to Mapbox (i.e movesount.com)
works only with EPSG:3857 - https://tiles.maaamet.ee/tm/tms/1.0.0/
*/
// from MapAnt bookmarklet - https://www.mapant.fi/about.php
var layers = mapboxgl.MapElement.getStyle().layers;
var firstSymbolId;
for (var i = 0; i < layers.length; i++) {
if (layers[i].type === "symbol") {
firstSymbolId = layers[i].id;
break;
}
};
mapboxgl.MapElement.addLayer({
"id": "maaamet",
"source": {
"type": "raster",
"tiles": ["https://tiles.maaamet.ee/tm/tms/1.0.0/foto@GMC/{z}/{x}/{y}.png&ASUTUS=MAAAMET&KESKKOND=LIVE&IS=TMSNAIDE"],
// "tiles": ["https://tiles.maaamet.ee/tm/tms/1.0.0/kaart@GMC/{z}/{x}/{y}.png&ASUTUS=MAAAMET&KESKKOND=LIVE&IS=TMSNAIDE"],
"tileSize": 256,
"scheme": "tms"
},
"type": "raster",
"visibility": "visible"
}, firstSymbolId);
/*
Getting point features from OSM and importing those into Movescount as POIs
Export a list of point features from OSM as a GeoJSON
( https://overpass-turbo.eu/ , https://overpass-turbo.eu/s/Pdj -> Export -> Copy as GeoJSON),
open watch page at Movescount - http://www.movescount.com/gear -> select watch - run the snippet (ctrl+enter)
and run SavePoisFromGeoJSON() from console
overpassGs : GeoJSON obj with point features
prefix : POI prefix string e.g. "WtrPnt". will be appended with numbers
poiType : POi type ID, 0 .. 47
useInDevice : true / false
const gs = <paste copied GeoJSON>;
SavePoisFromGeoJSON(gs,"WtrPnt",12,true);
WP Types:
0 Building
1 Home
2 Car
3 Parking
4 Camp
5 Camping
6 Food
7 Restaurant
8 Cafe
9 Lodging
10 Hostel
11 Hotel
12 Water
13 River
14 Lake
15 Coast
16 Mountain
17 Hill
18 Valley
19 Cliff
20 Forest
21 Crossroads
22 Sight
23 Begin
24 End
25 Geocache
26 Waypoint
27 Road
28 Trail
29 Rock
30 Meadow
31 Cave
32 Emergency
33 Information
34 Peak
35 Waterfall
36 Fishing spot
37 Bedding
38 Prints
39 Rub
40 Scrape
41 Stand
42 Trail cam
43 Big Game
44 Small Game
45 Bird
46 Shot
47 Fish
samplee GeoJSON from https://overpass-turbo.eu/
( https://overpass-turbo.eu/s/Pdj ):
const sample_gs = {
"type": "FeatureCollection",
"generator": "overpass-ide",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.",
"timestamp": "2019-12-24T09:09:02Z",
"features": [
{
"type": "Feature",
"properties": {
"@id": "node/2203051915",
"amenity": "drinking_water"
},
"geometry": {
"type": "Point",
"coordinates": [
9.2782768,
45.8241257
]
},
"id": "node/2203051915"
},
{
"type": "Feature",
"properties": {
"@id": "node/5492171205",
"amenity": "drinking_water"
},
"geometry": {
"type": "Point",
"coordinates": [
9.2804018,
45.8133826
]
},
"id": "node/5492171205"
},
{
"type": "Feature",
"properties": {
"@id": "node/5506655013",
"amenity": "drinking_water"
},
"geometry": {
"type": "Point",
"coordinates": [
9.2831267,
45.8133687
]
},
"id": "node/5506655013"
},
{
"type": "Feature",
"properties": {
"@id": "node/5590009130",
"amenity": "drinking_water"
},
"geometry": {
"type": "Point",
"coordinates": [
9.2844115,
45.8200733
]
},
"id": "node/5590009130"
}
]
};
*/
function SavePoisFromGeoJSON(overpassGs,prefix,poiType,useInDevice){
let deviceID = window.location.pathname.split('/')[2].split('-')[0].slice(4);
let pois = [];
for (let i = 0; i < overpassGs.features.length; i++ ){
let poi = {
userDeviceId : deviceID,
wp : {}
};
poi.wp["Id"] = 0;
poi.wp["Latitude"] = overpassGs.features[i].geometry.coordinates[1];
poi.wp["Longitude"] = overpassGs.features[i].geometry.coordinates[0];
poi.wp["Altitude"] = 0;
poi.wp["Type"] = poiType;
poi.wp["Name"] = prefix + String(i).padStart(2,"0");
poi.wp["CreationLocalTime"] = overpassGs.timestamp;
poi.wp["UseInDevice"] = useInDevice;
pois.push(poi);
}
console.log("pois: ", pois);
pois.forEach(itm => {
fetch("http://www.movescount.com/services/SaveSummitWaypoint", {
"credentials" :"include",
"headers" :{"content-type":"application/json"},
"body" :JSON.stringify(itm),
"method" :"POST",
"mode" :"cors"});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment