Initial commit
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Refactoria</title>
|
||||
<meta name="viewport" content="initial-scale=1.0">
|
||||
<meta charset="utf-8">
|
||||
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,600,700|Open+Sans:300,400,600" rel="stylesheet">
|
||||
|
||||
<!-- Include Leaflet -->
|
||||
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
||||
<link href="https://unpkg.com/leaflet/dist/leaflet.css" rel="stylesheet">
|
||||
|
||||
<!-- Include CARTO.js -->
|
||||
<script src="../../dist/public/carto.js"></script>
|
||||
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body, *{ margin: 0; padding: 0; }
|
||||
#map {
|
||||
position: absolute;
|
||||
height: 400px;
|
||||
width: 50%;
|
||||
top: 100px;
|
||||
z-index: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<span>Popups should position correctly even if page is scrolled</span>
|
||||
<div id="map"></div>
|
||||
<div style="height: 1200px; width: 3000px;"></div>
|
||||
|
||||
<script>
|
||||
const map = L.map('map').setView([30, 0], 3);
|
||||
map.scrollWheelZoom.disable();
|
||||
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}.png', {
|
||||
maxZoom: 18
|
||||
}).addTo(map);
|
||||
|
||||
const client = new carto.Client({
|
||||
apiKey: 'default_public',
|
||||
username: 'cartojs-test'
|
||||
});
|
||||
|
||||
const populatedPlacesSource = new carto.source.Dataset(`
|
||||
ne_10m_populated_places_simple
|
||||
`);
|
||||
const populatedPlacesStyle = new carto.style.CartoCSS(`
|
||||
#layer {
|
||||
marker-width: 7;
|
||||
marker-fill: #EE4D5A;
|
||||
marker-line-color: #FFFFFF;
|
||||
}
|
||||
`);
|
||||
const populatedPlacesLayer = new carto.layer.Layer(populatedPlacesSource, populatedPlacesStyle, {
|
||||
featureOverColumns: ['name', 'pop_max', 'pop_min']
|
||||
});
|
||||
|
||||
client.addLayer(populatedPlacesLayer);
|
||||
client.getLeafletLayer().addTo(map);
|
||||
|
||||
const popup = L.popup({ closeButton: false });
|
||||
|
||||
function openPopup(featureEvent) {
|
||||
let content = '<div class="widget">';
|
||||
|
||||
if (featureEvent.data.name) {
|
||||
content += `<h2 class="h2">${featureEvent.data.name}</h2>`;
|
||||
}
|
||||
|
||||
if (featureEvent.data.pop_max || featureEvent.data.pop_min) {
|
||||
content += `<ul>`;
|
||||
|
||||
if (featureEvent.data.pop_max) {
|
||||
content += `<li><h3>Max:</h3><p class="open-sans">${featureEvent.data.pop_max}</p></li>`;
|
||||
}
|
||||
|
||||
if (featureEvent.data.pop_min) {
|
||||
content += `<li><h3>Min:</h3><p class="open-sans">${featureEvent.data.pop_min}</p></li>`;
|
||||
}
|
||||
|
||||
content += `</ul>`;
|
||||
}
|
||||
|
||||
content += `</div>`;
|
||||
|
||||
popup.setContent(content);
|
||||
popup.setLatLng(featureEvent.latLng);
|
||||
if (!popup.isOpen()) {
|
||||
popup.openOn(map);
|
||||
}
|
||||
}
|
||||
|
||||
function closePopup(featureEvent) {
|
||||
popup.removeFrom(map);
|
||||
}
|
||||
|
||||
function setPopupsClick() {
|
||||
populatedPlacesLayer.off('featureOver');
|
||||
populatedPlacesLayer.off('featureOut');
|
||||
populatedPlacesLayer.on('featureClicked', openPopup);
|
||||
}
|
||||
|
||||
setPopupsClick();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,88 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<!-- Include Carto.js -->
|
||||
<script src="../../dist/public/carto.js"></script>
|
||||
<!-- Include Leaflet -->
|
||||
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places,visualization,drawing"></script>
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<button onclick="LAYERS.loadLayer('europe')">Activar capa</button>
|
||||
<button onclick="LAYERS.removeLayer('europe')">Desactivar capa</button>
|
||||
<div id="map" style="width: 100%;height: 96vh;"></div>
|
||||
|
||||
<script>
|
||||
const MAP = new google.maps.Map(document.getElementById('map'), {
|
||||
zoom: 3,
|
||||
center: { lat: 0, lng: 0 }
|
||||
});
|
||||
|
||||
var LAYERS = {
|
||||
populatedPlaces: {
|
||||
loaded: false,
|
||||
client: new carto.Client({
|
||||
apiKey: 'default_public',
|
||||
username: 'cartojs-test'
|
||||
}),
|
||||
source: new carto.source.Dataset('ne_10m_populated_places_simple'),
|
||||
cartoCSS: new carto.style.CartoCSS(`
|
||||
#layer {
|
||||
marker-width: 7;
|
||||
marker-fill: #EE4D5A;
|
||||
marker-line-color: #FFFFFF;
|
||||
}
|
||||
`),
|
||||
},
|
||||
europe: {
|
||||
loaded: false,
|
||||
client: new carto.Client({
|
||||
apiKey: 'default_public',
|
||||
username: 'cartojs-test'
|
||||
}),
|
||||
source: new carto.source.Dataset('ne_adm0_europe'),
|
||||
cartoCSS: new carto.style.CartoCSS(`
|
||||
#layer {
|
||||
polygon-fill: #826DBA;
|
||||
polygon-opacity: 0.8;
|
||||
::outline {
|
||||
line-width: 1;
|
||||
line-color: #FFFFFF;
|
||||
line-opacity: 0.8;
|
||||
}
|
||||
}
|
||||
`),
|
||||
},
|
||||
loadLayer: function (layerName) {
|
||||
const dataset = LAYERS[layerName];
|
||||
const layer = new carto.layer.Layer(dataset.source, dataset.cartoCSS, {});
|
||||
window.layers = window.layers || {};
|
||||
window.layers[layerName] = layer;
|
||||
|
||||
dataset.client.addLayer(layer)
|
||||
|
||||
if (!dataset.loaded) {
|
||||
MAP.overlayMapTypes.push(dataset.client.getGoogleMapsMapType(MAP));
|
||||
dataset.loaded = true;
|
||||
}
|
||||
},
|
||||
removeLayer: function (layerName) {
|
||||
const dataset = LAYERS[layerName];
|
||||
const layer = dataset.client.getLayers()[0];
|
||||
|
||||
dataset.client.removeLayer(layer);
|
||||
}
|
||||
};
|
||||
|
||||
LAYERS.loadLayer('europe');
|
||||
LAYERS.loadLayer('populatedPlaces');
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user