mirror of
https://github.com/farcasclaudiu/BlazorDeviceInterop.git
synced 2026-06-25 13:00:55 +03:00
Add project files.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
var deviceInterop = deviceInterop || {};
|
||||
|
||||
deviceInterop.objRefs = {};
|
||||
deviceInterop.objRefId = 0;
|
||||
deviceInterop.objRefKey = '__jsObjRefId';
|
||||
deviceInterop.storeObjRef = function (obj) {
|
||||
var id = deviceInterop.objRefId++;
|
||||
deviceInterop.objRefs[id] = obj;
|
||||
var objRef = {};
|
||||
objRef[deviceInterop.objRefKey] = id;
|
||||
return objRef;
|
||||
}
|
||||
deviceInterop.removeObjectRef = function (id) {
|
||||
delete deviceInterop.objRefs[id];
|
||||
}
|
||||
|
||||
DotNet.attachReviver(function (key, value) {
|
||||
if (value &&
|
||||
typeof value === 'object' &&
|
||||
value.hasOwnProperty(deviceInterop.objRefKey) &&
|
||||
typeof value[deviceInterop.objRefKey] === 'number') {
|
||||
var id = value[deviceInterop.objRefKey];
|
||||
if (!(id in deviceInterop.objRefs)) {
|
||||
throw new Error("The JS object reference doesn't exist: " + id);
|
||||
}
|
||||
const instance = deviceInterop.objRefs[id];
|
||||
return instance;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
window.LeafletMap = {
|
||||
|
||||
map: function (id, options) {
|
||||
return deviceInterop.storeObjRef(L.map(id, options));
|
||||
},
|
||||
|
||||
marker: function (latlng, options) {
|
||||
return deviceInterop.storeObjRef(L.marker(latlng, options));
|
||||
},
|
||||
|
||||
polyline: function (latlngs, options) {
|
||||
return deviceInterop.storeObjRef(L.polyline(latlngs, options));
|
||||
},
|
||||
|
||||
tileLayer: function (urlTemplate, options) {
|
||||
return deviceInterop.storeObjRef(L.tileLayer(urlTemplate, options));
|
||||
},
|
||||
|
||||
Layer: {
|
||||
|
||||
addTo: function (layer, map) {
|
||||
layer.addTo(map);
|
||||
},
|
||||
|
||||
remove: function (layer) {
|
||||
layer.remove();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
Polyline: {
|
||||
|
||||
addLatLng: function (polyline, latlng, latlngs) {
|
||||
polyline.addLatLng(latlng, latlngs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user