Tak już zdobione to dla środowisk, ale powinna być taka sama dla wielokątów. To naprawdę proste. Mam nadzieję, że poniższy kod odpowiada na twoje pytanie, ale jeśli nie, daj mi znać, a ja mogę zamieścić więcej informacji na ten temat.
// Creates the circle on the map for the given latLng and Radius
// If the createdWithAddress flag is true, the circle will not update
// it's address according to its position.
createCircle: function(latLng, radius, createdWithAddress) {
if (!this.circle) {
var self = this,
centerIcon,
centerMarker;
centerIcon = new L.Icon({
iconUrl: '/assets/location_pin_24px.png',
iconSize: [24, 24],
iconAnchor: [12, 24],
shadowUrl: '/assets/marker-shadow.png',
shadowSize: [20, 20],
shadowAnchor:[6, 20]
})
// Setup the options for the circle -> Override icons, immediately editable
options = {
stroke: true,
color: '#333333',
opacity: 1.0,
weight: 4,
fillColor: '#FFFFFF',
moveIcon: centerIcon,
resizeIcon: new L.Icon({
iconUrl: '/assets/radius_handle_18px.png',
iconSize: [12, 12],
iconAnchor: [0,0]
})
}
if (someConfigVarYouDontNeedToKnow) {
options.editable = false
centerMarker = new L.Marker(latLng, { icon:centerIcon })
} else {
options.editable = true
}
// Create our location circle
// NOTE: I believe I had to modify Leaflet or Leaflet.draw to allow for passing in
// options, but you can make it editable with circle.editing.enable()
this.circle = L.circle([latLng.lat, latLng.lng], radius, options)
// Add event handlers to update the location
this.circle.on('add', function() {
if (!createdWithAddress) {
self.reverseGeocode(this.getLatLng())
}
self.updateCircleLocation(this.getLatLng(), this.getRadius())
self.updateMapView()
})
this.circle.on('edit', function() {
if (self.convertLatLngToString(this.getLatLng()) !== self.getLocationLatLng()) {
self.reverseGeocode(this.getLatLng())
}
self.updateCircleLocation(this.getLatLng(), this.getRadius())
self.updateMapView()
})
this.map.addLayer(this.circle)
if (centerMarker) {
centerMarker.addTo(this.map)
this.circle.redraw()
centerMarker.update()
}
}
},
Przepraszam, że to po prostu hałas, ale powinien dać ci pomysł, jak sobie z tym poradzić. Możesz kontrolować edycję tak, jak powiedziałeś za pomocą edit.enable() /. Disable().
Pamiętaj, aby skomentować wszelkie pytania. Powodzenia.
Muszę to również wymyślić. Jeśli znalazłeś odpowiedź, opublikuj ją tutaj, dzięki. – Gowiem
Muszę jeszcze znaleźć odpowiedź sam. – SamEsla
To proste demo robocze: http://stackoverflow.com/questions/22730888/how-to-click-a-button-and-start-a-new-polygon-without-using- the-leaflet-draw-ui –