Published
Edited
Jul 8, 2021
Insert cell
test = {

let container = DOM.element('div', { style: `width:${width}px;height:${width/1.6}px` });
yield container;

let map = L.map(container).setView([35, 10], 2);

//initialize svg to add to map
// let PhilAreasLayer = L.geoJson({clickable:true}).addTo(map) // we have to make the svg layer clickable
L.svg({clickable:true}).addTo(map) // we have to make the svg layer clickable
//Create selection using D3
const overlay = d3.select(map.getPanes().overlayPane)
const svg = overlay.select('svg').attr("pointer-events", "auto")
// create a group that is hidden during zooming
const g = svg.append('g').attr('class', 'leaflet-zoom-hide')
// Use Leaflets projection API for drawing svg path (creates a stream of projected points)
const projectPoint = function(x, y) {
const point = map.latLngToLayerPoint(new L.LatLng(y, x))
this.stream.point(point.x, point.y)
}
// Use d3's custom geo transform method to implement the above
const projection = d3.geoTransform({point: projectPoint})
// creates geopath from projected points (SVG)
const pathCreator = d3.geoPath().projection(projection)



const areaPaths = g.selectAll('path')
.data(world.features)
.join('path')
//'red'
//getColor(VanAreas.features.properties.ID_1)
.attr('stroke', 'black')
.attr('fill', 'white')

.attr("z-index", 3000)
.attr('stroke-width', 2.5)
//.on("mouseover", mouseover )

let PhilAreasLayer2 = L.geoJson(capital, { //instantiates a new geoJson layer using built in geoJson handling
weight: 2, //Attributes of polygons including the weight of boundaries and colors of map.
color: "#432",
}).bindPopup(function (Layer) { //binds a popup when clicking on each polygon to access underlying data
return '<a href="https://globalreportingcentre.org/" target="_blank"><h1> Test Title </h1><img src="https://upload.wikimedia.org/wikipedia/commons/4/4a/100x100_logo.png" width=100 height=100 /></a>';
})
//only works with https

.addTo(map); //Adds the layer to the map.

//map.fitBounds(PhilAreasLayer.getBounds());
// Function to place svg based on zoom
const onZoom = () => areaPaths.attr('d', pathCreator)
// initialize positioning
onZoom()
// reset whenever map is moved
map.on('zoomend', onZoom)
map.fitBounds(PhilAreasLayer2.getBounds());
}
Insert cell
L = require('leaflet@1.2.0')
Insert cell
import {world} from "@zavenanarsh/philippines-map"
Insert cell
import {capital} from "@zavenanarsh/philippines-map"
Insert cell
d3 = require('d3@5')
Insert cell
a = html`<link href='${resolve('leaflet@1.2.0/dist/leaflet.css')}' rel='stylesheet' />`

Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more