-
-
Save knutole/318b9e25c3d2b43d12db to your computer and use it in GitHub Desktop.
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
// rememeber map state | |
function ressurect_map_state(get) { | |
// set active layers | |
for (layer in get['layers'] ) { | |
var l = get['layers'][layer]; | |
click_select_layer(false, l) | |
} | |
var lt = get['lat']; | |
var ln = get['lng']; | |
var zm = parseInt(get['zoom']); | |
map.setView([lt, ln], zm); | |
// edit Leaflet.Draw | |
leaflet_draw_api_extend(); | |
var drawnItems = new L.FeatureGroup(); | |
for (var item in get['drawnItems']) { | |
console.log('...adding draw layer'); | |
var layer = get['drawnItems'][item] | |
var geojsonLayer = L.geoJson(JSON.parse(layer),{ | |
onEachFeature: function (feature, layer) { | |
// if circle | |
if (feature.properties.layerType == 'circle') { | |
// create circle | |
var g = feature.geometry.coordinates; | |
var latlng = new L.latLng(g[1], g[0]); | |
var latlng2 = new L.latLng(g[1], g[0]); | |
x = new L.Draw.Circle(map,{}) | |
x._startLatLng = latlng; | |
//x._drawShape(latlng2); | |
x._createCircl(latlng); | |
x._shape._mRadius = feature.properties._mRadius; | |
//x._fireCreatedEvent() | |
//drawnItems.addLayer(x); | |
/* | |
var circle = L.circleMarker( | |
latlng, { | |
'radius' : feature.properties.radius | |
}); | |
drawnItems.addLayer(circle); | |
*/ | |
} else { | |
drawnItems.addLayer(layer); | |
} | |
} | |
}); | |
} | |
map.addLayer(drawnItems); | |
} | |
function leaflet_draw_api_extend() { | |
L.Draw.Circle.extend({ | |
_drawShape: function (latlng) { | |
if (!this._shape) { | |
this._shape = new L.Circle(this._startLatLng, | |
this._startLatLng.distanceTo(latlng), | |
this.options.shapeOptions); | |
this._map.addLayer(this._shape); | |
} else { | |
this._shape.setRadius(this._startLatLng.distanceTo(latlng)); | |
} | |
}, | |
_createCircle: function (latlng) { | |
this._drawShape(latlng) | |
L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle); | |
}, | |
_fireCreatedEvent: function () { | |
var circle = new L.Circle(this._startLatLng, | |
this._shape.getRadius(), | |
this.options.shapeOptions); | |
L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle); | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment