-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5d3586
commit 34facab
Showing
7 changed files
with
212 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 16 additions & 127 deletions
143
inst/htmlwidgets/lfx-layergroupcollision/layergroup-binding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,28 @@ | ||
/* global LeafletWidget, $, L, Shiny, HTMLWidgets */ | ||
LeafletWidget.methods.addLayerGroupCollision = function( | ||
data, layerId, group, options, | ||
className, html, popup, popupOptions, | ||
label, labelOptions, margin) { | ||
|
||
data, group, margin) { | ||
|
||
var collisionLayer = L.LayerGroup.collision({margin: margin}); | ||
console.log("collisionLayer"); console.log(collisionLayer) | ||
|
||
// Manually parse the GeoJSON and create the L.Markers one by one | ||
// Note that 'cities' is defined in the natural earth data files. | ||
console.log("data"); console.log(data) | ||
for (var i=0; i < data.features.length; i++) { | ||
|
||
var feat = data.features[i]; | ||
var labelClass = 'city-label city-label-' + feat.properties.strklasse_numeric; | ||
|
||
// Note that the markers are not interactive because MSIE on a WinPhone will take *ages* | ||
// to run addEventListener() on them. | ||
var marker = L.marker(L.GeoJSON.coordsToLatLng(feat.geometry.coordinates), { | ||
icon: L.divIcon({ | ||
html: | ||
"<span class='" + labelClass + "'>" + | ||
feat.properties.strnummer + | ||
"</span>" | ||
}) | ||
,interactive: false // Post-0.7.3 | ||
,clickable: false // 0.7.3 | ||
}); | ||
// Note that the markers are not interactive because MSIE on a WinPhone will take *ages* | ||
// to run addEventListener() on them. | ||
var marker = new L.marker( | ||
L.GeoJSON.coordsToLatLng(feat.geometry.coordinates), { | ||
icon: L.divIcon({ | ||
html: | ||
"<span class='" + feat.properties["className__"] + "'>" + | ||
feat.properties["html__"] + | ||
"</span>" | ||
}) | ||
, interactive: false // Post-0.7.3 | ||
, clickable: false // 0.7.3 | ||
}); | ||
|
||
collisionLayer.addLayer(marker); | ||
} | ||
collisionLayer.addTo(this); | ||
this.layerManager.addLayer(collisionLayer, "collison", null, group); | ||
|
||
}; | ||
/* | ||
(function() { | ||
var collisionLayer = L.LayerGroup.collision({margin:5}); | ||
// Make a Dataframe | ||
let df = new LeafletWidget.DataFrame() | ||
.col("lat", lat) | ||
.col("lng", lng) | ||
.col("layerId", layerId) | ||
.col("group", group) | ||
.col("popup", popup) | ||
.col("popupOptions", popupOptions) | ||
.col("label", label) | ||
.col("labelOptions", labelOptions) | ||
.col("className", className) | ||
.col("html", html) | ||
.cbind(options) | ||
.cbind(crosstalkOptions || {}); | ||
// Add Cluster | ||
let clusterGroup = this.layerManager.getLayer("cluster", clusterId), | ||
cluster = clusterOptions !== null; | ||
if (cluster && !clusterGroup) { | ||
clusterGroup = L.markerClusterGroup.layerSupport(clusterOptions); | ||
if(clusterOptions.freezeAtZoom) { | ||
let freezeAtZoom = clusterOptions.freezeAtZoom; | ||
delete clusterOptions.freezeAtZoom; | ||
clusterGroup.freezeAtZoom(freezeAtZoom); | ||
} | ||
clusterGroup.clusterLayerStore = new LeafletWidget.ClusterLayerStore(clusterGroup); | ||
} | ||
let extraInfo = cluster ? { clusterId: clusterId } : {}; | ||
for (let i = 0; i < df.nrow(); i++) { | ||
if($.isNumeric(df.get(i, "lat")) && $.isNumeric(df.get(i, "lng"))) { | ||
(function() { | ||
let thisId = df.get(i, "layerId"); | ||
let thisGroup = cluster ? null : df.get(i, "group"); | ||
// Create a new marker with DivIcon | ||
var divIconOptions = Object.assign({}, divOptions, { | ||
className: df.get(i, "className"), | ||
html: df.get(i, "html") | ||
}); | ||
var divmarker = new L.Marker( | ||
[df.get(i, "lat"), df.get(i, "lng")], | ||
Object.assign({}, options, { | ||
icon: new L.DivIcon(divIconOptions) | ||
})); | ||
collisionLayer.addLayer(divmarker); | ||
if (cluster) { | ||
clusterGroup.clusterLayerStore.add(divmarker, thisId); | ||
} else { | ||
this.layerManager.addLayer(divmarker, "marker", thisId, thisGroup, df.get(i, "ctGroup", true), df.get(i, "ctKey", true)); | ||
} | ||
// Bind popup to the marker if popup content is provided | ||
let popup = df.get(i, "popup"); | ||
let popupOptions = df.get(i, "popupOptions"); | ||
if (popup !== null) { | ||
if (popupOptions !== null){ | ||
divmarker.bindPopup(popup, popupOptions); | ||
} else { | ||
divmarker.bindPopup(popup); | ||
} | ||
} | ||
// Assign label (tooltip) to marker if label content is provided | ||
let label = df.get(i, "label"); | ||
let labelOptions = df.get(i, "labelOptions"); | ||
if (label !== null) { | ||
if (labelOptions !== null) { | ||
if(labelOptions.permanent) { | ||
divmarker.bindTooltip(label, labelOptions).openTooltip(); | ||
} else { | ||
divmarker.bindTooltip(label, labelOptions); | ||
} | ||
} else { | ||
divmarker.bindTooltip(label); | ||
} | ||
} | ||
// Add the marker to the map's layer manager | ||
this.layerManager.addLayer(divmarker, "marker", thisId, thisGroup); | ||
// Add Listener | ||
divmarker.on("click", LeafletWidget.methods.mouseHandler(this.id, thisId, thisGroup, "marker_click", extraInfo), this); | ||
divmarker.on("mouseover", LeafletWidget.methods.mouseHandler(this.id, thisId, thisGroup, "marker_mouseover", extraInfo), this); | ||
divmarker.on("mouseout", LeafletWidget.methods.mouseHandler(this.id, thisId, thisGroup, "marker_mouseout", extraInfo), this); | ||
divmarker.on("dragend", LeafletWidget.methods.mouseHandler(this.id, thisId, thisGroup, "marker_dragend", extraInfo), this); | ||
}).call(this); | ||
} | ||
} | ||
if (cluster) { | ||
this.layerManager.addLayer(clusterGroup, "cluster", clusterId, group); | ||
} | ||
collisionLayer.addTo(this); | ||
}).call(this); | ||
*/ |
Oops, something went wrong.