├── .gitignore ├── logos └── leaflet │ ├── img.png │ └── LICENSE.md ├── package.json ├── leaflet0.7.3_example.html ├── LICENSE ├── example.html ├── leaflet1.9.4_example.html ├── README.md ├── gh-pages └── gh-pages-example.html ├── dgis.js └── dgis-leaflet-0.7.3.js /.gitignore: -------------------------------------------------------------------------------- 1 | ./.idea -------------------------------------------------------------------------------- /logos/leaflet/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emikhalev/leaflet-2gis/HEAD/logos/leaflet/img.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaflet-2gis", 3 | "version": "1.0.1", 4 | "description": "This plugin adds 2GIS support to the LeafletJS.", 5 | "main": "dgis.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/emikhalev/leaflet-2gis.git" 9 | }, 10 | "keywords": [ 11 | "map", 12 | "leaflet", 13 | "gis", 14 | "2gis", 15 | "2-gis", 16 | "leafletjs", 17 | "2gis-map", 18 | "geo" 19 | ], 20 | "author": "Eugene Mikhalev", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/emikhalev/leaflet-2gis/issues" 24 | }, 25 | "homepage": "https://github.com/emikhalev/leaflet-2gis#readme", 26 | "peerDependencies": { 27 | "leaflet": "^1.0.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /leaflet0.7.3_example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Leaflet: 2GIS Example 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2023 Eugene Mikhalev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Leaflet: 2GIS Example 7 | 8 | 9 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /leaflet1.9.4_example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Leaflet: 2GIS Example 7 | 8 | 9 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /logos/leaflet/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright © 2010-2016 Vladimir Agafonkin, CloudMade 2 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 3 | 4 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 5 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 6 | THIS SOFTWARE IS PROVIDED BY VLADIMIR AGAFONKIN, CLOUDMADE "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL VLADIMIR AGAFONKIN, CLOUDMADE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 7 | 8 | USource: https://github.com/Leaflet/Leaflet/blob/master/src/images/logo.svg[https://github.com/Leaflet/Leaflet/blob/master/src/images/logo.svg] 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Leaflet 2GIS 2 |   3 | 4 | This plugin adds 2GIS support to the LeafletJS. 5 | 6 | ## Requirements 7 | * Leaflet 0.7.3 or newer 8 | * 2GIS api library (see example) 9 | 10 | ## Demo 11 | See [demo](http://emikhalev.github.io/leaflet-2gis/) 12 | 13 | # Examples 14 | - [Leaflet 1.9.4 example](https://github.com/emikhalev/leaflet-2gis/blob/master/leaflet1.9.4_example.html) 15 | - [Leaflet 0.7.3 example](https://github.com/emikhalev/leaflet-2gis/blob/master/leaflet0.7.3_example.html) 16 | 17 | ## Usage 18 | ```javascript 19 | var map = new L.Map("map", { 20 | center: new L.LatLng(54.99014, 73.365319), 21 | zoom: 10, 22 | zoomAnimation: false, 23 | zoomDelta: 1, 24 | attributionControl: false 25 | }); 26 | 27 | var dgis = new L.DGis(); 28 | map.addLayer(dgis); 29 | ``` 30 | 31 | ## License 32 | Leaflet 2GIS is free software, and may be redistributed under the MIT-LICENSE. 33 | -------------------------------------------------------------------------------- /gh-pages/gh-pages-example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Leaflet: 2GIS Example 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 |
26 | Leaflet 2GIS 27 |
28 |
29 | 30 | Star 31 | 32 | Watch 33 | 34 | Fork 35 |
36 | 37 |
38 |
39 |
40 | 41 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /dgis.js: -------------------------------------------------------------------------------- 1 | L.DGis = L.Layer.extend({ 2 | includes: L.Mixin.Events, 3 | 4 | options: { 5 | attribution: '', 6 | opacity: 0.99, 7 | enableGeoClicker: false 8 | }, 9 | 10 | // Init object 11 | initialize: function(name, options) { 12 | this.name = name 13 | L.Util.setOptions(this, options); 14 | }, 15 | 16 | // Layer events 17 | onAdd: function(map, insertAtTheBottom) { 18 | this._map = map; 19 | this._insertAtTheBottom = insertAtTheBottom; 20 | 21 | // Create map container 22 | this._initContainer(); 23 | 24 | // Create map object 25 | this._initMapObject(); 26 | 27 | // Setting events handlers 28 | this._setHandlers(); 29 | 30 | map._controlCorners['bottomright'].style.marginBottom = "3em"; 31 | this._reset(); 32 | }, 33 | onRemove: function(map) { 34 | // Remove map container 35 | this._map._container.removeChild(this._container); 36 | // Unset events handlers 37 | this._unsetHandlers(); 38 | this._map._controlCorners['bottomright'].style.marginBottom = "0em"; 39 | }, 40 | 41 | // Methods 42 | getAttribution: function() { 43 | return this.options.attribution; 44 | }, 45 | 46 | setOpacity: function(opacity) { 47 | this.options.opacity = opacity; 48 | if (opacity < 1) { 49 | L.DomUtil.setOpacity(this._container, opacity); 50 | } 51 | }, 52 | 53 | setElementSize: function(e, size) { 54 | e.style.width = size.x + "px"; 55 | e.style.height = size.y + "px"; 56 | }, 57 | 58 | // Helpers 59 | _initContainer: function() { 60 | var tilePane = this._map._container, 61 | first = tilePane.firstChild; 62 | 63 | if (!this._container) { 64 | this._container = L.DomUtil.create('div', 'leaflet-2gis-layer leaflet-top leaflet-left leaflet-zoom-hide'); 65 | this._container.id = "_2GisContainer_" + L.Util.stamp(this); 66 | this._container.style.zIndex = "auto"; 67 | } 68 | 69 | if (this.options.overlay) { 70 | first = this._map._container.getElementsByClassName('leaflet-map-pane')[0]; 71 | first = first.nextSibling; 72 | // XXX: Bug with layer order 73 | if (L.Browser.opera) 74 | this._container.className += " leaflet-objects-pane"; 75 | } 76 | tilePane.insertBefore(this._container, first); 77 | 78 | this.setOpacity(this.options.opacity); 79 | this.setElementSize(this._container, this._map.getSize()); 80 | }, 81 | 82 | _initMapObject: function() { 83 | // Init main object 84 | if (typeof this._map == "undefined") { 85 | return; 86 | } 87 | if (typeof this._dg == "undefined") { 88 | this._dg = new DG.Map(this._container); 89 | this._dg.fullscreen.disable(); 90 | if (this.options.enableGeoClicker) { 91 | this._dg.geoclicker.enable(); 92 | } else { 93 | this._dg.geoclicker.disable(); 94 | } 95 | } 96 | 97 | // Set map center and zoom 98 | this._setCenter(); 99 | 100 | var zoom = this._map.getZoom(); 101 | this._dg.setZoom(zoom); 102 | 103 | //Firing event with map-object as its argument, for the code that uses plug-in 104 | //will be able to use the 2GIS JS API through it. 105 | this.fire('MapObjectInitialized', { mapObject: this._dg }); 106 | }, 107 | 108 | _setCenter: function(){ 109 | var center = this._map.getCenter(); 110 | this._dg.setCenter(new DG.GeoPoint(center.lng, center.lat) ); 111 | }, 112 | 113 | _setHandlers: function(){ 114 | this._map.on('viewreset', this._resetCallback, this); 115 | this._map.on('move', this._move, this); 116 | this._map.on('moveend', this._move, this); 117 | }, 118 | 119 | _unsetHandlers: function(){ 120 | this._map.off('viewreset', this._resetCallback, this); 121 | this._map.off('move', this._move, this); 122 | this._map.off('moveend', this._move, this); 123 | }, 124 | 125 | // Event handlers 126 | _resetCallback: function(e) { 127 | this._reset(e.hard); 128 | }, 129 | 130 | _reset: function(clearOldContainer) { 131 | this._initContainer(); 132 | }, 133 | 134 | _move: function(force) { 135 | if (typeof this._dg == "undefined") { 136 | return; 137 | } 138 | if (!this._map) return; 139 | this._resize(force); 140 | // Zoom 141 | var zoom = this._map.getZoom(); 142 | if (force || this._dg.getZoom() != zoom) 143 | this._dg.setZoom(zoom); 144 | 145 | // Position 146 | var llCenter = this._map.getCenter(); // L.LatLng 147 | var dgCenter = this._dg.getCenter(); // DG.GeoPoint 148 | var dgllCenter = [dgCenter.lat, dgCenter.lon]; // L.LatLng <- DG.GeoPoint 149 | 150 | var llCenterPx = this._map.project(llCenter); // L.Point 151 | var dgCenterPx = this._map.project(dgllCenter); // L.Point 152 | 153 | var offsetX = dgCenterPx.x - llCenterPx.x; 154 | var offsetY = dgCenterPx.y - llCenterPx.y; 155 | 156 | this._dg.moveE( -offsetX ); // X-offset (East) 157 | this._dg.moveN( offsetY ); // Y-offset (North) 158 | 159 | }, 160 | 161 | _resize: function(force) { 162 | if (typeof this._dg == "undefined") { 163 | return; 164 | } 165 | var size = this._map.getSize(), style = this._container.style; 166 | if (style.width == size.x + "px" && 167 | style.height == size.y + "px") 168 | if (force != true) return; 169 | this.setElementSize(this._container, size); 170 | var b = this._map.getBounds(), sw = b.getSouthWest(), ne = b.getNorthEast(); 171 | this._dg.redraw(); 172 | } 173 | }); 174 | -------------------------------------------------------------------------------- /dgis-leaflet-0.7.3.js: -------------------------------------------------------------------------------- 1 | L.DGis = L.Class.extend({ 2 | includes: L.Mixin.Events, 3 | 4 | options: { 5 | attribution: '', 6 | opacity: 0.99, 7 | enableGeoClicker: false 8 | }, 9 | 10 | // Init object 11 | initialize: function(options) { 12 | L.Util.setOptions(this, options); 13 | }, 14 | 15 | // Layer events 16 | onAdd: function(map, insertAtTheBottom) { 17 | this._map = map; 18 | this._insertAtTheBottom = insertAtTheBottom; 19 | 20 | // Create map container 21 | this._initContainer(); 22 | 23 | // Create map object 24 | this._initMapObject(); 25 | 26 | // Setting events handlers 27 | this._setHandlers(); 28 | 29 | map._controlCorners['bottomright'].style.marginBottom = "3em"; 30 | this._reset(); 31 | }, 32 | onRemove: function(map) { 33 | // Remove map container 34 | this._map._container.removeChild(this._container); 35 | // Unset events handlers 36 | this._unsetHandlers(); 37 | this._map._controlCorners['bottomright'].style.marginBottom = "0em"; 38 | }, 39 | 40 | // Methods 41 | getAttribution: function() { 42 | return this.options.attribution; 43 | }, 44 | 45 | setOpacity: function(opacity) { 46 | this.options.opacity = opacity; 47 | if (opacity < 1) { 48 | L.DomUtil.setOpacity(this._container, opacity); 49 | } 50 | }, 51 | 52 | setElementSize: function(e, size) { 53 | e.style.width = size.x + "px"; 54 | e.style.height = size.y + "px"; 55 | }, 56 | 57 | // Helpers 58 | _initContainer: function() { 59 | var tilePane = this._map._container, 60 | first = tilePane.firstChild; 61 | 62 | if (!this._container) { 63 | this._container = L.DomUtil.create('div', 'leaflet-2gis-layer leaflet-top leaflet-left leaflet-zoom-hide'); 64 | this._container.id = "_2GisContainer_" + L.Util.stamp(this); 65 | this._container.style.zIndex = "auto"; 66 | } 67 | 68 | if (this.options.overlay) { 69 | first = this._map._container.getElementsByClassName('leaflet-map-pane')[0]; 70 | first = first.nextSibling; 71 | // XXX: Bug with layer order 72 | if (L.Browser.opera) 73 | this._container.className += " leaflet-objects-pane"; 74 | } 75 | tilePane.insertBefore(this._container, first); 76 | 77 | this.setOpacity(this.options.opacity); 78 | this.setElementSize(this._container, this._map.getSize()); 79 | }, 80 | 81 | _initMapObject: function() { 82 | // Init main object 83 | if (typeof this._map == "undefined") { 84 | return; 85 | } 86 | if (typeof this._dg == "undefined") { 87 | this._dg = new DG.Map(this._container); 88 | this._dg.fullscreen.disable(); 89 | if (this.options.enableGeoClicker) { 90 | this._dg.geoclicker.enable(); 91 | } else { 92 | this._dg.geoclicker.disable(); 93 | } 94 | } 95 | 96 | // Set map center and zoom 97 | this._setCenter(); 98 | 99 | var zoom = this._map.getZoom(); 100 | this._dg.setZoom(zoom); 101 | 102 | //Firing event with map-object as its argument, for the code that uses plug-in 103 | //will be able to use the 2GIS JS API through it. 104 | this.fire('MapObjectInitialized', { mapObject: this._dg }); 105 | }, 106 | 107 | _setCenter: function(){ 108 | var center = this._map.getCenter(); 109 | this._dg.setCenter(new DG.GeoPoint(center.lng, center.lat) ); 110 | }, 111 | 112 | _setHandlers: function(){ 113 | this._map.on('viewreset', this._resetCallback, this); 114 | this._limitedUpdate = L.Util.limitExecByInterval(this._move, 150, this); 115 | this._map.on('move', this._move, this); 116 | this._map.on('moveend', this._move, this); 117 | }, 118 | 119 | _unsetHandlers: function(){ 120 | this._map.off('viewreset', this._resetCallback, this); 121 | this._map.off('move', this._move, this); 122 | this._map.off('moveend', this._move, this); 123 | }, 124 | 125 | // Event handlers 126 | _resetCallback: function(e) { 127 | this._reset(e.hard); 128 | }, 129 | 130 | _reset: function(clearOldContainer) { 131 | this._initContainer(); 132 | }, 133 | 134 | _move: function(force) { 135 | if (typeof this._dg == "undefined") { 136 | return; 137 | } 138 | if (!this._map) return; 139 | this._resize(force); 140 | // Zoom 141 | var zoom = this._map.getZoom(); 142 | if (force || this._dg.getZoom() != zoom) 143 | this._dg.setZoom(zoom); 144 | 145 | // Position 146 | var llCenter = this._map.getCenter(); // L.LatLng 147 | var dgCenter = this._dg.getCenter(); // DG.GeoPoint 148 | var dgllCenter = [dgCenter.lat, dgCenter.lon]; // L.LatLng <- DG.GeoPoint 149 | 150 | var llCenterPx = this._map.project(llCenter); // L.Point 151 | var dgCenterPx = this._map.project(dgllCenter); // L.Point 152 | 153 | var offsetX = dgCenterPx.x - llCenterPx.x; 154 | var offsetY = dgCenterPx.y - llCenterPx.y; 155 | 156 | this._dg.moveE( -offsetX ); // X-offset (East) 157 | this._dg.moveN( offsetY ); // Y-offset (North) 158 | 159 | }, 160 | 161 | _resize: function(force) { 162 | if (typeof this._dg == "undefined") { 163 | return; 164 | } 165 | var size = this._map.getSize(), style = this._container.style; 166 | if (style.width == size.x + "px" && 167 | style.height == size.y + "px") 168 | if (force != true) return; 169 | this.setElementSize(this._container, size); 170 | var b = this._map.getBounds(), sw = b.getSouthWest(), ne = b.getNorthEast(); 171 | this._dg.redraw(); 172 | } 173 | }); 174 | --------------------------------------------------------------------------------