Leaflet SVG circle marker with detachable label and text
Usage
$ npm install --save leaflet-labeled-circle
var L = ;var LabeledMarker = ; var map = L; var feature = "type": "Feature" "properties": "text": 122 "labelPosition": 11429819682617189 22477347822506356 "geometry": "type": "Point" "coordinates": 1141952 2242658 ; var marker = featuregeometrycoordinates feature markerOptions: color: '#050' ;
You can avoid using GeoJSON here if you want, but I see it as a good data format
API
Marker options
optionsmarkerOptions : // all L.CircleMarker options + following: textStyle: color: '#fff' fontSize: 12 fontFamily: 'Helvetica, Arial, sans-serif' shiftY: 6 // to compensate vertical margin, SVG rect is not accurate
Anchor marker options
optionsanchorOptions = /* see L.CircleMarker options */ ;
Dragging line options
optionslineOptions = /* see L.Polyline options */ ;
Get label text
options { // here you can use any field from GeoJSON properties you like}
Get initial label position
options { // here you can get the initial position from the feature data // or fall back to the marker coordinates}
Serialize
marker = latlng feature labelPositionKey: 'labelPosition';console;// {// type: 'Feature',// properties: {// ...// labelPosition: [lon, lat]// },// geometry: {// type: 'Point',// coordinates: [lon, lat]// }// }
Alternatively, you can serialize into a GeometryCollection:
marker = latlng feature labelPositionKey: 'labelPosition';console; "type": "Feature" "properties": "text": 12 "labelPosition": lon2 lat2 "geometriesTypes": "anchor" "connection" "label" "textbox" "geometry": "type": "GeometryCollection" "geometries": "type": "Point" "coordinates": lon1 lat1 "type": "LineString" "coordinates": lon1 lat1 lon2 lat2 "type": "Point" "coordinates": lon2 lat2 "type": "Point" "coordinates": lon2 lat2
License
The MIT License (MIT)
Copyright (c) 2016 Alexander Milevski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.