Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@coreo/ionic-map
Advanced tools
Ionic 2+ module to bring up a map.
This module depends upon leaflet
.
yarn add leaflet @types/leaflet @coreo/ionic-map
Import the module in your app.module.ts
:
import { CoreoMapModule } from '@coreo/ionic-map';
...
@NgModule({
imports: [
...
CoreoMapModule
...
]
})
export class AppModule {}
Use the component in your HTML:
<ion-header>
<ion-navbar>
<ion-title>
Map Test
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<coreo-map geolocate taplocate markLocation (coordsChanged)="coordsChanged($event)" (mapSetupFailed)="mapSetupFailed($event)" (geolocatorStarted)="geolocatorStarted()" (geolocatorStopped)="geolocatorStopped()"></coreo-map>
</ion-content>
With no configuration, a default tile layer will added to the map using the Open Street Maps (OSM) set of tiles.
You may add your own tiles by using the [layers]
input.
An example of a basic leaflet tile layer
Leaflet.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
id: 'OpenTopoMap',
maxZoom: 17,
attribution: '...'
})
It is possible to use google maps tile layer, using the leaflet.gridlayer.googlemutant
module.
import 'leaflet.gridlayer.googlemutant';
...
@Component({
...
})
export class MyPage{
googleReady: Promise;
constructor(googleMaps: CoreoGoogleMaps){}
ngOnInit(){
this.googleReady =
}
}
coords
: Coordinates to center the map on. Coords should conform to the CoreoMapCoords
interface. When setting the coords, the map will center at the specified location.layers
: An array of L.TileLayer objects. If omitted, a default will be used (see above).mapConfig
: Configuration for Google Map. Refer to the Google Mutant plugin for full configuration options.geolocate
: Show the geolocate button in the top right hand corner of the map. In addition, if no coords are passed, attempt to locate the user when the map first loads.geolocatorColor
: hex colour to use for the geolocator icon. Default: #000
.tolerateAccuracyMeters
: number in meters to accept as accuracy when geolocating. If the geolocation service returns a result with a wider accuracy than specified, it will keep trying until it finds a location with an acceptable accuracy, up to a maximum of 60s. Once the 60s is passed, the best accuracy location will be returned via the coordsChanged
output, if any was found. Default: 50fallbackCoords
: if the geolocator couldn't find the user's location, the map will be centered at this location. Value should be a latitude/longtitude string. Default: 54.729223,-3.7391789
(center of the UK).taplocate
: Allow the user to change the coords
by tapping on the map. Often used in conjunction with geolocate
and markLocation
.markLocation
: Show a pin marker at the curent coords.markerFillColor
: hex colour to use for the marker colour. Default: #007fff
(a blue hue).markerStrokeColor
: hex colour to use for the marker outline. Default: #000
.markerCircleColor
: hex colour to use for the marker inner circle. Default: #000
.initAfter
: wait to initialise the map until after the specified number of ms has passed. Useful when the DOM needs to sort itself out beforehand (e.g. when using an Ionic modal). Default: 0.coordsChanged
: emitted whenever the coordinates have changed. Value emitted will confirm to CoreoMapCoords
.mapSetupFailed
: emitted if the Google Maps API could not be reached. Normally this will be due to the user being offline.geolocatorStarted
: emitted when the geolocator startsgeolocatorStopped
: emitted when the geolocator stopsThe map can be mounted as a ViewChild
in your host component. The following properties and methods are available:
map
: the L.Map
instance. Useful for modifying the map with the Leaflet API.locationMarker
: the L.Marker
pin marker instance. Will only be available if the markLocation
attribute was set.googleMapLayer
: the L.GridLayer
Google Map layer.map.html
<ion-header>
<ion-navbar>
<ion-title>
Map Test
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<coreo-map
[mapConfig]="mapConfig"
initAfter="100"
[coords]="coords"
fallbackCoords="49.4089694,5.5960209"
geolocate
geolocatorColor="#222"
tolerateAccuracyMeters="20"
taplocate
markLocation
markerFillColor="#cc271f"
markerStrokeColor="#5b201d"
markerCircleColor="#5b201d"
(coordsChanged)="coordsChanged($event)"
(mapSetupFailed)="mapSetupFailed($event)"
(geolocatorStarted)="geolocatorStarted($event)"
(geolocatorStopped)="geolocatorStopped($event)"></coreo-map>
<p *ngIf="coords">Your coords are: {{ coords.lat }}, {{ coords.lng }}.</p>
<p *ngIf="coords?.acc">Your position is accurate to {{ coords.acc }}m.</p>
</ion-content>
map.ts
import { AfterViewInit, Component, ViewChild } from '@angular/core';
import { CoreoMapComponent } from '@coreo/ionic-map';
@Component({
selector: 'page-map',
templateUrl: 'map.html'
})
export class MapPage implements AfterViewInit {
coords;
mapConfig = {
type: 'satellite'
}
@ViewChild(CoreoMapComponent) coreoMap;
ngAfterViewInit() {
console.log(this.coreoMap);
}
coordsChanged(c) {
this.coords = c;
}
mapSetupFailed() {
console.log('map setup failed');
}
geolocationFailed() {
console.log('geo failed');
}
}
FAQs
Ionic 2+ module for rendering a map component.
The npm package @coreo/ionic-map receives a total of 5 weekly downloads. As such, @coreo/ionic-map popularity was classified as not popular.
We found that @coreo/ionic-map demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.