Skip to content

Instantly share code, notes, and snippets.

@danwild
Last active March 29, 2021 06:17
Show Gist options
  • Save danwild/bad25212abb326b9d55179c4a22ee006 to your computer and use it in GitHub Desktop.
Save danwild/bad25212abb326b9d55179c4a22ee006 to your computer and use it in GitHub Desktop.
Leaflet.glify conflict example
<!DOCTYPE html>
<!-- saved from url=(0062)https://leaflet.github.io/Leaflet.draw/docs/examples/full.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Leaflet.glify conflict example</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-draw@1.0.4/dist/leaflet.draw.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-draw@1.0.4/dist/leaflet.draw.css" />
<!-- note: avoid v3.1.0, has color issue -->
<script src="https://unpkg.com/leaflet.glify@3.0.2/dist/glify-browser.js"></script>
<script>
var geoJSON = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
147.66448974609375,
-43.31518656029048
],
[
147.70843505859375,
-43.43696596521823
],
[
147.4420166015625,
-43.5326204268101
],
[
147.8814697265625,
-43.61022814178641
],
[
147.974853515625,
-43.31918320532584
],
[
147.66448974609375,
-43.31518656029048
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
148.3648681640625,
-42.627896481020834
],
[
148.25775146484375,
-42.67839711889055
],
[
148.16986083984372,
-42.88602714832882
],
[
148.44451904296875,
-43.03075300142832
],
[
148.61480712890625,
-42.696567309696974
],
[
148.3648681640625,
-42.627896481020834
]
]
]
}
}
]
}
</script>
</head>
<body class="">
<div id="map" style="width: 800px; height: 600px; border: 1px solid rgb(204, 204, 204); position: relative;"></div>
<script>
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, { maxZoom: 18, attribution: osmAttrib }),
map = new L.Map('map', { center: new L.LatLng(51.505, -0.04), zoom: 13 }),
drawnItems = L.featureGroup().addTo(map);
L.control.layers({
'osm': osm.addTo(map),
"google": L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', {
attribution: 'google'
})
}, { 'drawlayer': drawnItems }, { position: 'topleft', collapsed: false }).addTo(map);
map.addControl(new L.Control.Draw({
edit: {
featureGroup: drawnItems,
poly: {
allowIntersection: false
}
},
draw: {
polygon: {
allowIntersection: false,
showArea: true
}
}
}));
map.on(L.Draw.Event.CREATED, function (event) {
var layer = event.layer;
drawnItems.addLayer(layer);
});
L.glify.shapes({
map,
data: geoJSON,
click(e, feature) {
console.log('click', { e, feature});
},
hover(e, feature) {
console.log('hover', { e, feature});
},
});
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment