mirror of
https://github.com/crawlerop/lpads
synced 2026-08-13 05:52:32 +07:00
872 lines
44 KiB
HTML
872 lines
44 KiB
HTML
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
|
|
<title>MapAds demo</title>
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>
|
|
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet-easybutton@2/src/easy-button.css">
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/leaflet-easybutton@2/src/easy-button.js"></script>
|
|
<script src="./mapads.js"></script>
|
|
<style>
|
|
body {
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
html, body, #mapid {
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
textarea.righttext {
|
|
position:absolute;
|
|
right:1px;
|
|
bottom:15px;
|
|
resize:none;
|
|
}
|
|
button.rightbutton {
|
|
position:absolute;
|
|
right:1px;
|
|
bottom:15px;
|
|
resize:none;
|
|
}
|
|
|
|
/* The Modal (background) */
|
|
.modal {
|
|
display: none; /* Hidden by default */
|
|
position: fixed; /* Stay in place */
|
|
z-index: 1; /* Sit on top */
|
|
padding-top: 25px; /* Location of the box */
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%; /* Full width */
|
|
height: 100%; /* Full height */
|
|
overflow: auto; /* Enable scroll if needed */
|
|
background-color: rgb(0,0,0); /* Fallback color */
|
|
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
|
|
}
|
|
|
|
/* Modal Content */
|
|
.modal-content {
|
|
background-color: #fefefe;
|
|
margin: auto;
|
|
padding: 20px;
|
|
border: 1px solid #888;
|
|
width: 75%;
|
|
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
font-size: larger;
|
|
}
|
|
|
|
/* The Close Button */
|
|
.close {
|
|
color: #aaaaaa;
|
|
float: right;
|
|
font-size: 28px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.close:hover,
|
|
.close:focus {
|
|
color: #000;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
<noscript>Please enable the javascript for LPAds.js to work!</noscript>
|
|
<div id="shopping" class="modal">
|
|
<div class="modal-content">
|
|
<span class="close" id="close_button">×</span>
|
|
<div id="shopping_content"></div>
|
|
</div>
|
|
</div>
|
|
<div id="mapid"></div>
|
|
<script>
|
|
var searching = false;
|
|
var s_modal = document.getElementById("shopping")
|
|
var sc = document.getElementById("shopping_content")
|
|
var map_data = document.getElementById("mapid")
|
|
var xhr = new XMLHttpRequest()
|
|
var xhr2 = new XMLHttpRequest()
|
|
var start = [40.7127837, -74.00594130000002]
|
|
// if (wrapper) start = [-27.564444, 151.951944]
|
|
var addLayer = false;
|
|
var dist = 8000;
|
|
var dist_modifier = 1;
|
|
var cors = false;
|
|
var nominatim_zoom = 17;
|
|
var searchAPIURL = "https://api.mapbox.com/geocoding/v5/mapbox.places/(query).json?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw&limit=1";
|
|
var searchAPIURLNominatim = "https://nominatim.openstreetmap.org/reverse?lat=(lat)&lon=(long)&format=jsonv2&zoom="+nominatim_zoom;
|
|
var searchAPIURLBing = "https://dev.virtualearth.net/REST/v1/Locations/(query)?o=json&key=AngXT6Kt9tQtmoGORNVnfY-H_W8CSkM2mb13SrDwLZ43mNaKhD5zpupeQX9uxYjo";
|
|
var lpadURL = "https://www.google.com/maps/preview/lp?authuser=0&hl=(LN)&gl=(GL)&pb=!1m3!1s0!7e81!15i60107!2m9!1m3!1d(dist)!2d(long)!3d(lat)!2m0!3m2!1i32767!2i32767!4f14!5m2!3b0!5e11"
|
|
var overrides = null;
|
|
var lang = "en", country = "us"
|
|
var blacklist = [];
|
|
var placeBlacklist = [];
|
|
var adParseFunction = null;
|
|
var adStartFunction = null;
|
|
|
|
function selLPUrl(uri) {
|
|
let rand = Math.floor(Math.random() * 1000000000000);
|
|
let rand2 = Math.floor(Math.random() * 1000000000000);
|
|
return cors ? uri : "https://api.allorigins.win/raw?hash="+rand.toString()+"&url=" + encodeURIComponent(uri+"!1024m1!1024s"+rand2.toString())
|
|
}
|
|
|
|
function show_shopping_modal(hide) {
|
|
if (hide) {
|
|
sc.innerHTML = ""
|
|
s_modal.style.display = "none"
|
|
map_data.style.display = ""
|
|
mymap.invalidateSize()
|
|
} else {
|
|
s_modal.style.display = "block"
|
|
map_data.style.display = "none"
|
|
}
|
|
}
|
|
|
|
function do_shop_modal(id) {
|
|
show_shopping_modal()
|
|
setup_shopping_modal(adData[id])
|
|
}
|
|
|
|
document.getElementById("close_button").onclick = () => {
|
|
show_shopping_modal(true)
|
|
}
|
|
|
|
function setup_shopping_modal(ad_data) {
|
|
var mp_data = ad_data.adMarketPlace.items
|
|
var out = `<h2>${ad_data.adName}</h2><br><br>`;
|
|
for (var i=0;i<mp_data.length;i++) {
|
|
var m_dat = mp_data[i]
|
|
out += `<img src="${m_dat.item_icon}"> <p>${m_dat.item_name} - ${m_dat.item_price} - <a href="${m_dat.item_buy_link}">Click here to buy</a></p><br><br>`
|
|
}
|
|
var wta_str = ""
|
|
for (k in ad_data.adMarketPlace.why) {
|
|
wta_str += `<br>${k} = ${ad_data.adMarketPlace.why[k]}`
|
|
}
|
|
sc.innerHTML = `<center>${out}<br>Why: <br><b>${wta_str}</b></center><footer><h3 style="text-align: right">Powered by <a href="https://github.com/crawlerop/lpads">lpads</a></h3></footer>`;
|
|
}
|
|
|
|
try {
|
|
up = new URLSearchParams(window.location.search)
|
|
if (up.get('lat') != null && up.get('lng') != null) {
|
|
start = [parseFloat(up.get('lat')), parseFloat(up.get('lng'))]
|
|
}
|
|
if (up.get('dist') != null) {
|
|
dist = parseFloat(up.get('dist'))
|
|
}
|
|
if (up.get('cors') == 'true') {
|
|
cors = true
|
|
}
|
|
if (up.get('localads') == "true") {
|
|
addLayer = true
|
|
}
|
|
if (up.get('override') != null) {
|
|
try {
|
|
overrides = JSON.parse(decodeURIComponent(escape(window.atob(up.get('override').replace(" ","+"))))).overrides
|
|
} catch (e) {
|
|
overrides = JSON.parse(window.atob(up.get('override').replace(" ","+"))).overrides
|
|
}
|
|
}
|
|
if (up.get('osm_zoom') != null) {
|
|
nominatim_zoom = parseFloat(up.get('osm_zoom'));
|
|
searchAPIURLNominatim = "https://nominatim.openstreetmap.org/reverse?lat=(lat)&lon=(long)&format=jsonv2&zoom="+nominatim_zoom;
|
|
}
|
|
if (up.get('lang') != null) {
|
|
lang = up.get('lang')
|
|
}
|
|
if (up.get('locale') != null) {
|
|
country = up.get('locale')
|
|
}
|
|
if (up.get('hl') != null) {
|
|
lang = up.get('hl')
|
|
}
|
|
if (up.get('gl') != null) {
|
|
country = up.get('gl')
|
|
}
|
|
try {
|
|
if (up.get('event') != null) {
|
|
adParseFunction = eval("("+window.atob(up.get('event'))+")")
|
|
if (({}).toString.call(adParseFunction) != '[object Function]') {
|
|
adParseFunction = null
|
|
throw new Error("Event is not a function.")
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.warn("Error parsing the event script: " + e)
|
|
}
|
|
try {
|
|
if (up.get('init') != null) {
|
|
adStartFunction = eval("("+window.atob(up.get('init'))+")")
|
|
if (({}).toString.call(adStartFunction) != '[object Function]') {
|
|
adStartFunction = null
|
|
throw new Error("Init is not a function.")
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.warn("Error parsing the init script: " + e)
|
|
}
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
var going = false;
|
|
|
|
var mburl = "https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw&rt_session=" + Math.floor(Math.random() * 1000000000000)
|
|
|
|
var data = L.layerGroup()
|
|
|
|
mapboxattr = 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' + '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + 'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>'
|
|
|
|
gmapsattr = 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' + '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + 'Imagery © <a href="https://maps.google.com/">Google Maps</a>'
|
|
|
|
esriattr = 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' + '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + 'Imagery © <a href="https://www.esri.com/">ESRI</a>'
|
|
|
|
osmattr = 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors'
|
|
|
|
normal = L.tileLayer(mburl, {
|
|
maxZoom: 21,
|
|
attribution: mapboxattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 512,
|
|
zoomOffset: -1
|
|
})
|
|
|
|
mdefault = L.tileLayer(mburl, {
|
|
maxZoom: 21,
|
|
attribution: mapboxattr,
|
|
id: 'mapbox/streets-v11',
|
|
tileSize: 512,
|
|
zoomOffset: -1
|
|
})
|
|
|
|
mgray = L.tileLayer(mburl, {
|
|
maxZoom: 21,
|
|
attribution: mapboxattr,
|
|
id: 'mapbox/light-v9',
|
|
tileSize: 512,
|
|
zoomOffset: -1
|
|
})
|
|
|
|
mdark = L.tileLayer(mburl, {
|
|
maxZoom: 21,
|
|
attribution: mapboxattr,
|
|
id: 'mapbox/dark-v9',
|
|
tileSize: 512,
|
|
zoomOffset: -1
|
|
})
|
|
|
|
esrinormal = L.tileLayer('https://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
|
|
maxZoom: 21,
|
|
attribution: esriattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
esriterrain = L.tileLayer('https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', {
|
|
maxZoom: 21,
|
|
attribution: esriattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
maxZoom: 21,
|
|
attribution: osmattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
satellite = L.tileLayer(mburl, {
|
|
maxZoom: 21,
|
|
attribution: mapboxattr,
|
|
id: 'user12435235124125235824592457/ckanekpxi1o3y1ipkm8tl6v3i',
|
|
tileSize: 512,
|
|
zoomOffset: -1
|
|
})
|
|
|
|
satellitenotext = L.tileLayer(mburl, {
|
|
maxZoom: 21,
|
|
attribution: mapboxattr,
|
|
id: 'user12435235124125235824592457/ckb7ik2nf4rel1ip61enm2h23',
|
|
tileSize: 512,
|
|
zoomOffset: -1
|
|
})
|
|
|
|
gmapsnormal = L.tileLayer('https://www.google.com/maps/vt/pb=!1m4!1m3!1i{z}!2i{x}!3i{y}!2m1!1i0!3m2!2sen-US!5i1106!5m1!5f4.0!23i1358902', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapsvue = L.tileLayer('https://maps.googleapis.com/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i520236120!3m17!2sen-US!3sUS!5e18!12m4!1e68!2m2!1sset!2sRoadmap!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcy50OjF8cy5lOmwudC5mfHAuYzojZmY0NDQ0NDQscy50OjV8cC5jOiNmZmYyZjJmMixzLnQ6MnxwLnY6b2ZmLHMudDozfHAuczotMTAwfHAubDo0NSxzLnQ6NDl8cC52OnNpbXBsaWZpZWQscy50OjUwfHMuZTpsLml8cC52Om9mZixzLnQ6NHxwLnY6b2ZmLHMudDo2fHAuYzojZmYyNjJlNDV8cC52Om9uLHMudDo2fHMuZTpsfHAudjpvZmY!4e0!5m1!5f4.0', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapsfb = L.tileLayer('https://maps.googleapis.com/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i520236108!3m17!2sen-US!3sUS!5e18!12m4!1e68!2m2!1sset!2sRoadmap!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcy5lOmwuaXxwLnY6b2ZmLHMudDoxfHAudjpvbixzLnQ6NXxwLmM6I2ZmZThlOWU5LHMudDoyfHMuZTpnfHAuYzojZmZlOGU5ZTkscy50OjQwfHAuYzojZmZiYWQyOTQscy50OjQwfHMuZTpsfHAudjpvZmYscy50OjQ5fHMuZTpnLmZ8cC5jOiNmZmZmZmZmZixzLnQ6NDl8cy5lOmcuc3xwLnY6b2ZmLHMudDo1MHxzLmU6Zy5mfHAuYzojZmZmZmZmZmYscy50OjUwfHMuZTpnLnN8cC52Om9mZixzLnQ6NTF8cy5lOmcuZnxwLmM6I2ZmZmJmYmZiLHMudDo0fHAudjpvZmYscy50OjZ8cy5lOmd8cC5jOiNmZjQxYWVjOSxzLnQ6NnxzLmU6bC50LmZ8cC5jOiNmZjA2NTk3MSxzLnQ6NnxzLmU6bC50LnN8cC52OnNpbXBsaWZpZWQ!4e0!5m1!5f4.0', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapsgray = L.tileLayer('https://maps.googleapis.com/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i520233372!3m17!2sen-US!3sUS!5e18!12m4!1e68!2m2!1sset!2sRoadmap!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcy50OjZ8cy5lOmd8cC5jOiNmZmU5ZTllOXxwLmw6MTcscy50OjV8cy5lOmd8cC5jOiNmZmY1ZjVmNXxwLmw6MjAscy50OjQ5fHMuZTpnLmZ8cC5jOiNmZmZmZmZmZnxwLmw6MTcscy50OjQ5fHMuZTpnLnN8cC5jOiNmZmZmZmZmZnxwLmw6Mjl8cC53OjAuMixzLnQ6NTB8cy5lOmd8cC5jOiNmZmZmZmZmZnxwLmw6MTgscy50OjUxfHMuZTpnfHAuYzojZmZmZmZmZmZ8cC5sOjE2LHMudDoyfHMuZTpnfHAuYzojZmZmNWY1ZjV8cC5sOjIxLHMudDo0MHxzLmU6Z3xwLmM6I2ZmZGVkZWRlfHAubDoyMSxzLmU6bC50LnN8cC52Om9ufHAuYzojZmZmZmZmZmZ8cC5sOjE2LHMuZTpsLnQuZnxwLnM6MzZ8cC5jOiNmZjMzMzMzM3xwLmw6NDAscy5lOmwuaXxwLnY6b2ZmLHMudDo0fHMuZTpnfHAuYzojZmZmMmYyZjJ8cC5sOjE5LHMudDoxfHMuZTpnLmZ8cC5jOiNmZmZlZmVmZXxwLmw6MjAscy50OjF8cy5lOmcuc3xwLmM6I2ZmZmVmZWZlfHAubDoxN3xwLnc6MS4y!4e0!5m1!5f4.0', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapsbold = L.tileLayer('https://www.google.com/maps/vt?pb=!1m4!1m3!1i{z}!2i{x}!3i{y}!2m2!2sm!3i504221335!3m7!2sen-US!5i1105!12m4!1i68!2m2!1sset!2sTerrain!5m1!5f4.0!23i1358902', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapstopo = L.tileLayer('https://www.google.com/maps/vt/pb=!1m4!1m3!1i{z}!2i{x}!3i{y}!2m2!1e5!2sshading!2m2!1e6!2scontours!2m3!1e0!2sm!3i505220892!3m7!5e1105!12m1!1e67!12m1!1e63!12m1!1e3!4e0!5m2!5f1!6b1!5m1!5f4.0', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapsnotext = L.tileLayer('https://www.google.com/maps/vt/pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i559283400!3m17!2sen-US!3sUS!5e18!12m4!1e68!2m2!1sset!2sRoadmap!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcy5lOmx8cC52Om9mZg!4e0!5m1!5f4.0', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapsdark = L.tileLayer('https://www.google.com/maps/vt/pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i559283400!3m17!2sen-US!3sUS!5e18!12m4!1e68!2m2!1sset!2sRoadmap!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcy5lOmd8cC5jOiNmZjIxMjEyMSxzLmU6bC50LmZ8cC5jOiNmZjc1NzU3NSxzLmU6bC50LnN8cC5jOiNmZjIxMjEyMSxzLnQ6MXxzLmU6Z3xwLmM6I2ZmNzU3NTc1LHMudDoxN3xzLmU6bC50LmZ8cC5jOiNmZjllOWU5ZSxzLnQ6MTl8cy5lOmwudC5mfHAuYzojZmZiZGJkYmQscy50OjJ8cy5lOmwudC5mfHAuYzojZmZiZmJmYmYscy50OjQwfHMuZTpnfHAuYzojZmYxODE4MTgscy50OjQwfHMuZTpsLnQuc3xwLmM6I2ZmMWIxYjFiLHMudDozfHMuZTpnLmZ8cC5jOiNmZjJjMmMyYyxzLnQ6M3xzLmU6bC50LmZ8cC5jOiNmZjhhOGE4YSxzLnQ6NTB8cy5lOmd8cC5jOiNmZjM3MzczNyxzLnQ6NDl8cy5lOmd8cC5jOiNmZjNjM2MzYyxzLnQ6Nzg1fHMuZTpnfHAuYzojZmY0ZTRlNGUscy50OjUxfHMuZTpsLnQuZnxwLmM6I2ZmNjE2MTYxLHMudDo0fHMuZTpsLnQuZnxwLmM6I2ZmNzU3NTc1LHMudDo2fHMuZTpnfHAuYzojZmYwMDAwMDAscy50OjZ8cy5lOmwudC5mfHAuYzojZmYzZDNkM2Q!4e0!5m1!5f4.0', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapsdarknotext = L.tileLayer('https://www.google.com/maps/vt/pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i559283400!3m17!2sen-US!3sUS!5e18!12m4!1e68!2m2!1sset!2sRoadmap!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcy5lOmd8cC5jOiNmZjIxMjEyMSxzLmU6bHxwLnY6b2ZmLHMuZTpsLml8cC52Om9mZixzLmU6bC50LmZ8cC5jOiNmZjc1NzU3NSxzLmU6bC50LnN8cC5jOiNmZjIxMjEyMSxzLnQ6MXxzLmU6Z3xwLmM6I2ZmNzU3NTc1LHMudDoxN3xzLmU6bC50LmZ8cC5jOiNmZjllOWU5ZSxzLnQ6MjF8cC52Om9mZixzLnQ6MTl8cy5lOmwudC5mfHAuYzojZmZiZGJkYmQscy50OjJ8cy5lOmwudC5mfHAuYzojZmY3NTc1NzUscy50OjQwfHMuZTpnfHAuYzojZmYxODE4MTgscy50OjQwfHMuZTpsLnQuZnxwLmM6I2ZmNjE2MTYxLHMudDo0MHxzLmU6bC50LnN8cC5jOiNmZjFiMWIxYixzLnQ6M3xzLmU6Zy5mfHAuYzojZmYyYzJjMmMscy50OjN8cy5lOmwudC5mfHAuYzojZmY4YThhOGEscy50OjUwfHMuZTpnfHAuYzojZmYzNzM3Mzcscy50OjQ5fHMuZTpnfHAuYzojZmYzYzNjM2Mscy50Ojc4NXxzLmU6Z3xwLmM6I2ZmNGU0ZTRlLHMudDo1MXxzLmU6bC50LmZ8cC5jOiNmZjYxNjE2MSxzLnQ6NHxzLmU6bC50LmZ8cC5jOiNmZjc1NzU3NSxzLnQ6NnxzLmU6Z3xwLmM6I2ZmMDAwMDAwLHMudDo2fHMuZTpsLnQuZnxwLmM6I2ZmM2QzZDNk!4e0!5m1!5f4.0', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
esrisatellite = L.tileLayer('https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
|
|
maxZoom: 21,
|
|
attribution: esriattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
esrisatellitealt = L.tileLayer('https://clarity.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
|
|
maxZoom: 21,
|
|
attribution: esriattr,
|
|
id: 'user12435235124125235824592457/ckao1rqf85kh01imwyf5b0pvc',
|
|
tileSize: 256,
|
|
zoomOffset: 0
|
|
})
|
|
|
|
gmapssatellite = L.tileLayer('https://mt{s}.googleapis.com/vt?lyrs=y&hl=en-US&x={x}&y={y}&z={z}', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckanekpxi1o3y1ipkm8tl6v3i',
|
|
tileSize: 256,
|
|
zoomOffset: 0,
|
|
subdomains: ["0", "1", "2", "3"]
|
|
})
|
|
|
|
gmapssatellitenotext = L.tileLayer('https://mt{s}.googleapis.com/vt?lyrs=s&hl=en-US&x={x}&y={y}&z={z}', {
|
|
maxZoom: 21,
|
|
attribution: gmapsattr,
|
|
id: 'user12435235124125235824592457/ckanekpxi1o3y1ipkm8tl6v3i',
|
|
tileSize: 256,
|
|
zoomOffset: 0,
|
|
subdomains: ["0", "1", "2", "3"]
|
|
})
|
|
|
|
blank = L.tileLayer('https://nope', {
|
|
maxZoom: 21,
|
|
attribution: "",
|
|
tileSize: 256,
|
|
zoomOffset: 0,
|
|
})
|
|
|
|
var mymap = L.map('mapid', {
|
|
center: start,
|
|
zoom: 14,
|
|
layers: [blank]
|
|
})
|
|
|
|
if (addLayer == true) {
|
|
mymap.addLayer(data)
|
|
}
|
|
|
|
var layernames = {
|
|
"Mapbox Normal": normal,
|
|
"Mapbox Streets": mdefault,
|
|
"Mapbox Grayscale": mgray,
|
|
"Mapbox Dark": mdark,
|
|
"Google Maps Normal": gmapsnormal,
|
|
"Google Maps Terrain": gmapstopo,
|
|
"Google Maps Normal (Better)": gmapsfb,
|
|
"Google Maps Bold": gmapsbold,
|
|
"Google Maps Vue": gmapsvue,
|
|
"Google Maps Grayscale": gmapsgray,
|
|
"Google Maps Normal (No Label)": gmapsnotext,
|
|
"Google Maps Dark": gmapsdark,
|
|
"Google Maps Dark (No Label)": gmapsdarknotext,
|
|
"OSM": osm,
|
|
"ESRI Normal": esrinormal,
|
|
"ESRI Terrain": esriterrain,
|
|
"Mapbox Satellite": satellite,
|
|
"Mapbox Satellite (no label)": satellitenotext,
|
|
"Google Maps Satellite": gmapssatellite,
|
|
"Google Maps Satellite (no label)": gmapssatellitenotext,
|
|
"ESRI Satellite": esrisatellite,
|
|
"ESRI Satellite (alt)": esrisatellitealt,
|
|
"Empty Tile": blank,
|
|
}
|
|
|
|
|
|
layers = L.control.layers(layernames, {"Local Ads": data})
|
|
layers.addTo(mymap)
|
|
|
|
|
|
asyncPayload = []
|
|
|
|
function asyncRequest(loc, cb, err) {
|
|
asyncPayload.push({"asLocation":loc,"asCallback":cb,"asError":err})
|
|
}
|
|
|
|
onGeocode = false
|
|
|
|
function doAsync(reqid=0, onDone, preCon, t=0) {
|
|
if (preCon != null && preCon() == false) {
|
|
return
|
|
}
|
|
|
|
if (asyncPayload.length < 1) {
|
|
console.log("No payload found!")
|
|
if (onDone != null) {
|
|
onDone()
|
|
}
|
|
return
|
|
}
|
|
|
|
let xhr4 = new XMLHttpRequest()
|
|
xhr4.open("GET", asyncPayload[reqid].asLocation)
|
|
xhr4.onreadystatechange = function() {
|
|
if (this.readyState == 4) {
|
|
if (preCon != null && preCon() == true) {
|
|
asyncPayload[reqid].asCallback(this.responseText)
|
|
if (reqid < asyncPayload.length-1) {
|
|
setTimeout(function(){doAsync(reqid+1, onDone, preCon, t)}, t)
|
|
} else {
|
|
if (onDone != null) {
|
|
onDone()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
xhr4.onerror = function(e) {
|
|
if (e != null) {
|
|
asyncPayload[reqid].asError(e)
|
|
}
|
|
onSearch = false
|
|
}
|
|
xhr4.send()
|
|
}
|
|
|
|
function setupIcon(url, size) {
|
|
return L.icon({
|
|
iconUrl: url,
|
|
iconSize: [size[0],size[1]],
|
|
iconAnchor: [size[0]/2,size[1]],
|
|
popupAnchor: [0,-size[1]+0]
|
|
})
|
|
}
|
|
|
|
function setupMarker(ad, fa_id=0) {
|
|
m = L.marker(ad.adLocation.split(", "), {title: ad.adName})
|
|
|
|
if (ad.adPinImage != null) {
|
|
let iconIsOverride = false
|
|
if (ad.adPinImage.search("composite_map_square") != -1) {
|
|
newIcon = ad.adPinImage.replace("composite_map_square_logo", "composite_map_pinlet")
|
|
if (ad.adPinImage.search("_v") == -1) {
|
|
newIcon += "_v1"
|
|
}
|
|
} else {
|
|
iconIsOverride = true
|
|
newIcon = ad.adPinImage
|
|
}
|
|
m = L.marker(ad.adLocation.split(", "), {
|
|
title: ad.adName,
|
|
icon: iconIsOverride ? setupIcon(newIcon, [48,48]) : setupIcon(newIcon, [43,60])
|
|
})
|
|
|
|
}
|
|
|
|
ld = ad.adLocation.split(", ")
|
|
adTextData = "<h1>"+ad.adName+"</h1>"
|
|
if (ad.promoData == null) {
|
|
adTextData += "In: <b>(LocationName)</b><br>"
|
|
if (ad.adNotes) {
|
|
adTextData += "<br><b>Secret notes: </b>"+ad.adNotes+"<br><br>"
|
|
} else if (ad.adMarketPlace) {
|
|
adTextData += "<br><b><a href=\"javascript:void(do_shop_modal("+fa_id+"))\">View currently sold items</a></b><br>"
|
|
if (ad.adMarketPlace.storefront) {
|
|
adTextData += "<b><a href=\""+ad.adMarketPlace.storefront+"\">View store's storefront page</a></b><br>"
|
|
}
|
|
adTextData += "<br>"
|
|
}
|
|
adTextData += "Why: <b>"+ad.adWhy+"</b>"
|
|
adTextData += "<br><br><a href=\""+ad.adLink+"\">"+ad.adSite+"</a>"
|
|
adTextData += "<br><br><a href=\"https://crawlerop.github.io/psassist/js/getmaplace.html?lat="+ld[0]+"&lng="+ld[1]+"\">PassiveAssist</a>"
|
|
} else {
|
|
adTextData = "<h1>"+ad.promoData.adPromo.promoTitle+"</h1>"
|
|
if (!ad.adPinImage || !ad.adPinImage.startsWith(ad.promoData.adImage)) {
|
|
adTextData += "<center><img src=\""+ad.promoData.adImage+"\" width=128></center>"
|
|
}
|
|
adTextData += "<h2>"+ad.adName+"</h2>"
|
|
adTextData += "In: <b>(LocationName)</b><br>"
|
|
adTextData += "<h3>"+ad.promoData.adPromo.promoDesc+"</h3>"
|
|
adTextData += "Why: <b>"+ad.adWhy+"</b>"
|
|
adTextData += "<br><br><a href=\""+ad.adLink+"\" title=\""+ad.promoData.toolTip+"\">"+ad.promoData.adPromo.promoButton+"</a>"
|
|
adTextData += "<br><br><a href=\"https://crawlerop.github.io/psassist/js/getmaplace.html?lat="+ld[0]+"&lng="+ld[1]+"\">PassiveAssist</a>"
|
|
}
|
|
|
|
pins.push(m)
|
|
return m
|
|
}
|
|
|
|
function fixHash(adData) {
|
|
for (i=0;i<overrides.length;i++) {
|
|
if (overrides[i].target.hash == undefined) {
|
|
if (overrides[i].target.adPlace == undefined) {
|
|
if (adData.adName == overrides[i].target.adName && adData.adSite == overrides[i].target.adSite) {
|
|
overrides[i].target.adPlace = adData.adPlace
|
|
}
|
|
}
|
|
if (adData.adPlace == overrides[i].target.adPlace) {
|
|
overrides[i].target.hash = adData.hash
|
|
return
|
|
}
|
|
}
|
|
}
|
|
//console.log("No override found for "+adData+"!")
|
|
}
|
|
|
|
function loadPins(adData) {
|
|
var fa_index = 0
|
|
var not_found = false
|
|
adData.forEach(function(ad) {
|
|
lp = ad.adLocation.split(", ")
|
|
switch (up.get("geocoder")) {
|
|
case "bing":
|
|
tg = searchAPIURLBing.replace("(query)", lp[0] + "," + lp[1])
|
|
break
|
|
|
|
case "mapbox":
|
|
tg = searchAPIURL.replace("(query)", lp[1] + "," + lp[0])
|
|
break
|
|
|
|
case "nominatim":
|
|
tg = searchAPIURLNominatim.replace("(lat)", lp[0]).replace("(long)", lp[1])
|
|
break
|
|
|
|
case "none":
|
|
default:
|
|
not_found = true
|
|
break
|
|
|
|
}
|
|
var atwn = null
|
|
if (not_found) atwn = "Geocoding disabled"
|
|
if (adParseFunction != null) {
|
|
resp = adParseFunction(JSON.parse(JSON.stringify(ad)))
|
|
if (resp != null) {
|
|
ad = JSON.parse(JSON.stringify(resp))
|
|
if (ad.adTown) {
|
|
atwn = ad.adTown
|
|
}
|
|
}
|
|
}
|
|
if (overrides != null) {
|
|
fixHash(ad)
|
|
for (c = 0; c<overrides.length; c++) {
|
|
v = overrides[c]
|
|
if (ad.hash == v.target.hash) {
|
|
console.log("Overriding "+ad.adName+" ad...")
|
|
ad = v.new
|
|
atwn = v.new.adTown
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if (atwn) {
|
|
m = setupMarker(JSON.parse(JSON.stringify(ad)), fa_index++)
|
|
adTextData = adTextData.replace("(LocationName)", atwn)
|
|
m.bindPopup(adTextData)
|
|
m.addTo(data)
|
|
} else {
|
|
adMarker.dragging.disable()
|
|
adMarker.off('click')
|
|
adMarker.on('click', function(){return;})
|
|
findloc._currentState.onClick = function(){return;}
|
|
asyncRequest(tg, function(rt){
|
|
m = setupMarker(JSON.parse(JSON.stringify(ad)), fa_index++)
|
|
switch (up.get("geocoder")) {
|
|
case "bing":
|
|
adTextData = adTextData.replace("(LocationName)", JSON.parse(rt).resourceSets[0].resources[0].name)
|
|
break
|
|
|
|
case "mapbox":
|
|
adTextData = adTextData.replace("(LocationName)", JSON.parse(rt).features[0].place_name)
|
|
break
|
|
|
|
case "nominatim":
|
|
default:
|
|
let osmdata = JSON.parse(rt);
|
|
adTextData = adTextData.replace("(LocationName)", osmdata.display_name)
|
|
if (up.get("parsetemplate") == "true") {
|
|
adTextData = adTextData.replace(/\{LOCATION\(City\)\}/g, osmdata.address.city).replace(/\{LOCATION\(State\)\}/g, osmdata.address.state).replace(/\{LOCATION\(Suburb\)\}/g, osmdata.address.suburb).replace(/\{LOCATION\(Country\)\}/g, osmdata.address.country)
|
|
}
|
|
break
|
|
}
|
|
m.bindPopup(adTextData)
|
|
m.addTo(data)
|
|
})
|
|
}
|
|
})
|
|
onGeocode = true
|
|
doAsync(0, function(){console.log("Geocode Done!"); findloc._currentState.onClick = dosearch; adMarker.on('click', clk); adMarker.dragging.enable(); onGeocode=false; asyncPayload=[]}, function(){if (!onGeocode) { console.log("Geocode Aborted!"); } return onGeocode}, 75)
|
|
}
|
|
|
|
var adData = null;
|
|
|
|
var pins = [];
|
|
|
|
adMarker = new L.marker(start, {
|
|
title: "Drag or click me to find location ads nearby!",
|
|
draggable: true,
|
|
icon: setupIcon("https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678111-map-marker-64.png", [43,42])
|
|
})
|
|
|
|
adRadius = new L.circle(start, {radius: dist/dist_modifier})
|
|
|
|
/*
|
|
d = new L.marker(start)
|
|
d.addTo(mymap)
|
|
*/
|
|
|
|
adMarker.addTo(data)
|
|
adRadius.addTo(data)
|
|
|
|
adMarker.on("dragstart", function() {
|
|
if (going == true) {
|
|
xhr.abort()
|
|
onGeocode = false
|
|
//xhr4.abort()
|
|
going = false
|
|
searching = false
|
|
}
|
|
pins.forEach(function(k){
|
|
k.remove()
|
|
});
|
|
pins = []
|
|
adData = null
|
|
adRadius.remove()
|
|
})
|
|
|
|
adMarker.on("dragend", function(ev) {
|
|
mk = ev.target
|
|
mkpos = mk.getLatLng()
|
|
mk.setLatLng(new L.LatLng(mkpos.lat, mkpos.lng),{draggable:'true'})
|
|
mymap.panTo(new L.LatLng(mkpos.lat, mkpos.lng))
|
|
adRadius = new L.circle(new L.LatLng(mkpos.lat, mkpos.lng), {radius: dist/dist_modifier})
|
|
adRadius.addTo(data)
|
|
xhr.open("GET", selLPUrl(lpadURL.replace("(dist)", dist).replace("(long)", mkpos.lng).replace("(lat)", mkpos.lat).replace("(LN)", lang).replace("(GL)", country)))
|
|
xhr.onreadystatechange = function() {
|
|
if (this.readyState == 4) {
|
|
going = false
|
|
out = xhr.responseText.replace(")]}'\n", "")
|
|
//console.log(out)
|
|
try {
|
|
adProto = JSON.parse(out)
|
|
} catch (e) {
|
|
return
|
|
}
|
|
adResp = parseAds(mkpos.lat, mkpos.lng, adProto, blacklist, placeBlacklist)
|
|
if (adResp.noAds == true) {
|
|
console.warn("No ads found on "+mkpos.lat+", "+mkpos.lng+"!")
|
|
} else {
|
|
adData = adResp.mapAds
|
|
loadPins(adData)
|
|
}
|
|
}
|
|
}
|
|
going = true
|
|
xhr.send()
|
|
})
|
|
|
|
function clk(){
|
|
if (going == true) {
|
|
xhr.abort()
|
|
onGeocode = false
|
|
//xhr4.abort()
|
|
going = false
|
|
searching = false
|
|
}
|
|
pins.forEach(function(k){
|
|
k.remove()
|
|
});
|
|
pins = []
|
|
adData = null
|
|
pos = adMarker.getLatLng()
|
|
xhr.open("GET", selLPUrl(lpadURL.replace("(dist)", dist).replace("(long)", pos.lng).replace("(lat)", pos.lat).replace("(LN)", lang).replace("(GL)", country)))
|
|
xhr.onreadystatechange = function() {
|
|
if (this.readyState == 4) {
|
|
going = false
|
|
out = xhr.responseText.replace(")]}'\n", "")
|
|
//console.log(out)
|
|
try {
|
|
adProto = JSON.parse(out)
|
|
} catch (e) {
|
|
return
|
|
}
|
|
adResp = parseAds(pos.lat, pos.lng, adProto, blacklist, placeBlacklist)
|
|
if (adResp.noAds == true) {
|
|
console.warn("No ads found on "+pos.lat+", "+pos.lng+"!")
|
|
} else {
|
|
adData = adResp.mapAds
|
|
loadPins(adData)
|
|
}
|
|
}
|
|
}
|
|
going = true
|
|
xhr.send()
|
|
}
|
|
|
|
adMarker.on('click', clk)
|
|
|
|
if (adStartFunction != null) {
|
|
adStartFunction()
|
|
}
|
|
|
|
xhr.open("GET", selLPUrl(lpadURL.replace("(dist)", dist).replace("(long)", start[1]).replace("(lat)", start[0]).replace("(LN)", lang).replace("(GL)", country)))
|
|
xhr.onreadystatechange = function() {
|
|
if (this.readyState == 4) {
|
|
going = false
|
|
out = xhr.responseText.replace(")]}'\n", "")
|
|
//console.log(out)
|
|
try {
|
|
adProto = JSON.parse(out)
|
|
} catch (e) {
|
|
return
|
|
}
|
|
adResp = parseAds(parseFloat(start[0]), parseFloat(start[1]), adProto, blacklist, placeBlacklist)
|
|
if (adResp.noAds == true) {
|
|
console.warn("No ads found on "+start[0]+", "+start[1]+"!")
|
|
} else {
|
|
adData = adResp.mapAds
|
|
loadPins(adData)
|
|
}
|
|
}
|
|
}
|
|
going = true
|
|
xhr.send()
|
|
|
|
function dosearch() {
|
|
if (searching == true && going == true) {
|
|
xhr.abort()
|
|
onGeocode = false
|
|
//xhr4.abort()
|
|
going = false
|
|
searching = false
|
|
return
|
|
}
|
|
if (going == true) {
|
|
xhr.abort()
|
|
onGeocode = false
|
|
//xhr4.abort()
|
|
going = false
|
|
searching = false
|
|
}
|
|
searching = true
|
|
pins.forEach(function(k){
|
|
k.remove()
|
|
});
|
|
pins = []
|
|
adData = null
|
|
pos = adMarker.getLatLng()
|
|
xhr.open("GET", selLPUrl(lpadURL.replace("(dist)", dist).replace("(long)", pos.lng).replace("(lat)", pos.lat).replace("(LN)", lang).replace("(GL)", country)))
|
|
xhr.onreadystatechange = function() {
|
|
if (this.readyState == 4) {
|
|
going = false
|
|
out = xhr.responseText.replace(")]}'\n", "")
|
|
//console.log(out)
|
|
try {
|
|
adProto = JSON.parse(out)
|
|
} catch (e) {
|
|
return
|
|
}
|
|
adResp = parseAds(pos.lat, pos.lng, adProto, blacklist, placeBlacklist)
|
|
if (adResp.noAds == true) {
|
|
console.warn("No ads found on "+pos.lat+", "+pos.lng+"!")
|
|
if (searching) {dosearch()}
|
|
} else {
|
|
searching = false
|
|
adData = adResp.mapAds
|
|
loadPins(adData)
|
|
}
|
|
}
|
|
}
|
|
going = true
|
|
xhr.send()
|
|
}
|
|
|
|
findloc = L.easyButton('fa-map-marker', dosearch)
|
|
findloc.addTo(mymap)
|
|
|
|
L.easyButton('fa-search', function(){
|
|
document.location = "search.html"
|
|
}).addTo(mymap)
|
|
|
|
L.easyButton('fa-pencil', function(){
|
|
adm = adMarker.getLatLng()
|
|
document.location = "editor.html?lat="+adm.lat+"&lng="+adm.lng+"&dist="+dist+((up.get("override") != null) ? "&override=" + up.get("override") : "")
|
|
}).addTo(mymap)
|
|
|
|
//console.log(addLayer)
|
|
</script>
|
|
</body>
|
|
</html>
|