All Projects → w8r → leaflet-labeled-circle

w8r / leaflet-labeled-circle

Licence: MIT license
Special type of SVG marker with a label inside and draggable around the anchor point

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to leaflet-labeled-circle

auto-label
Auto Label Issue Based on Issue Description
Stars: ✭ 34 (-2.86%)
Mutual labels:  label
nagmapReborn
Nagmap Reborn - Standalone integration with some server monitoring systems providing a user-friendly interface through geographic visualization.
Stars: ✭ 19 (-45.71%)
Mutual labels:  leaflet
databases-w-r
Databases with R, the latest - rstudio::conf2019
Stars: ✭ 33 (-5.71%)
Mutual labels:  leaflet
Leaflet Cluster Example
🗺 Example of using the clustering plugin with Leaflet
Stars: ✭ 26 (-25.71%)
Mutual labels:  leaflet
leaflet-layerJSON
Build dynamic JSON Layer via Ajax/JSONP with caching
Stars: ✭ 82 (+134.29%)
Mutual labels:  leaflet
Leaflet.streetlabels
Display the street labels following polylines for Leaflet
Stars: ✭ 58 (+65.71%)
Mutual labels:  leaflet
rainviewer-api-example
How to use RainViewer API: simple HTML + JS code which render an animated weather radar overlay on the map
Stars: ✭ 56 (+60%)
Mutual labels:  leaflet
dtp-stat-archive
Карта ДТП v1.0. 👉 База знаний о проекте: https://github.com/dtpstat/dtp-project/wiki
Stars: ✭ 142 (+305.71%)
Mutual labels:  leaflet
Leaflet.TileLayer.Fallback
Replaces missing Tiles by scaled lower zoom Tiles
Stars: ✭ 29 (-17.14%)
Mutual labels:  leaflet
react-native-leaflet
A LeafletView component using WebView and Leaflet map for React Native applications
Stars: ✭ 53 (+51.43%)
Mutual labels:  leaflet
leaflet-defaulticon-compatibility
Retrieve all Leaflet Default Icon options from CSS, in particular all icon images URL's, to improve compatibility with bundlers and frameworks that modify URL's in CSS.
Stars: ✭ 71 (+102.86%)
Mutual labels:  leaflet
react-leaflet-bing
Bing layer as React component for Leaflet | This repo is obsolete. Plz, use https://github.com/TA-Geoforce/react-leaflet-bing
Stars: ✭ 13 (-62.86%)
Mutual labels:  leaflet
leaflet-opencage-search
A Leaflet geocoding control that uses the OpenCage geocoding API
Stars: ✭ 18 (-48.57%)
Mutual labels:  leaflet
objmap
Breath of the Wild object map
Stars: ✭ 61 (+74.29%)
Mutual labels:  leaflet
antaresViz
ANTARES Visualizations
Stars: ✭ 19 (-45.71%)
Mutual labels:  leaflet
leaflet-velocity
Visualise velocity data on a leaflet layer
Stars: ✭ 467 (+1234.29%)
Mutual labels:  leaflet
GeoNature
Application de saisie et de synthèse des observations faune et flore
Stars: ✭ 81 (+131.43%)
Mutual labels:  leaflet
esri-leaflet-vector
Display ArcGIS Online vector basemaps w/ Esri Leaflet
Stars: ✭ 39 (+11.43%)
Mutual labels:  leaflet
enmodal
transit planning & analysis in your browser
Stars: ✭ 38 (+8.57%)
Mutual labels:  leaflet
video labeler
A GUI tool for conveniently label the objects in video, using the powerful object tracking.
Stars: ✭ 87 (+148.57%)
Mutual labels:  label

Leaflet SVG circle marker with detachable label and text npm version CircleCI

Screenshot

Usage

$ npm install --save leaflet-labeled-circle
var L = require('leaflet');
var LabeledMarker = require('leaflet-labeled-circle');

var map = L.map('map').setView(center, zoom);

var feature = {
  "type": "Feature",
  "properties": {
    "text": 122,
    "labelPosition": [
      114.29819682617189,
      22.477347822506356
    ]
  },
  "geometry": {
    "type": "Point",
    "coordinates": [ 114.1952, 22.42658]
  }
};

var marker = new LabeledMarker(
  feature.geometry.coordinates.slice().reverse(),
  feature, {
    markerOptions: { color: '#050' }
  }).addTo(map);

You can avoid using GeoJSON here if you want, but I see it as a good data format

API

Marker options

options.markerOptions : {
  // 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

options.anchorOptions = { /* see L.CircleMarker options */ };

Dragging line options

options.lineOptions = { /* see L.Polyline options */ };

Get label text

options.getLabelText = function(marker, feature) {
  // here you can use any field from GeoJSON properties you like
}

Get initial label position

options.getLabelPosition = function(marker, feature, latlng) {
   // here you can get the initial position from the feature data
   // or fall back to the marker coordinates
}

Serialize

marker = new LabeledMarker(latlng, feature, {
  labelPositionKey: 'labelPosition'
});
console.log(marker.toGeoJSON());
// {
//   type: 'Feature',
//   properties: {
//     ...
//     labelPosition: [lon, lat]
//   },
//   geometry: {
//     type: 'Point',
//     coordinates: [lon, lat]
//   }
// }

Alternatively, you can serialize into a GeometryCollection:

marker = new LabeledMarker(latlng, feature, {
  labelPositionKey: 'labelPosition'
});
console.log(marker.toGeoJSON(true));
{
  "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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].