Skip to content
Permalink
Browse files

AMap factory

  • Loading branch information
joe223 committed Jun 28, 2017
1 parent f2b901b commit 96ebbb6aea4ce4a6ec0d806bbd0b0d8591b2e4e4
Showing with 273 additions and 138 deletions.
  1. +73 βˆ’0 example/amap.html
  2. +4 βˆ’5 package.json
  3. +37 βˆ’37 src/constructors/amap/amap.d.ts
  4. +55 βˆ’47 src/constructors/amap/index.ts
  5. +14 βˆ’16 src/constructors/bmap/index.ts
  6. +15 βˆ’16 src/constructors/gmap/index.ts
  7. +0 βˆ’2 src/constructors/lmap/lmap.ts
  8. +3 βˆ’0 src/factory/icon.ts
  9. +5 βˆ’4 src/factory/mapsEventListener.ts
  10. +2 βˆ’0 src/options/mapOptions.ts
  11. +7 βˆ’3 src/plain.ts
  12. +47 βˆ’3 src/utils.ts
  13. +3 βˆ’2 src/var.ts
  14. +3 βˆ’2 tsconfig.json
  15. +5 βˆ’1 yarn.lock
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Plain</title>
<style media="screen">
* {
margin: 0;
padding: 0;
}
html,
body,
#map {
width: 100%;
height: 100%;
}
</style>
</head>

<body>
<div id="map">loading</div>
<!--do not use async defer-->
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=c6cf0a6f81c01e6226691a7308962357"></script>
<script src="../dist/plain.js"></script>
<script>
var plain = new Plain().use('AMAP');
var path = [
[39.910, 116.404],
[39.71, 116.5],
[39.909, 117],
[39.710, 118]
];
var map = plain.Map({
container: "map",
center: [39.910, 116.404],
zoom: 15
});
var icon = plain.Icon({
url: 'https://unpkg.com/leaflet@1.0.3/dist/images/marker-icon.png',
size: [25, 40],
anchor: [12.5, 40]
});
var markerOpt = {
icon: icon,
draggable: true
};
var marker = plain.Marker([39.910, 116.404], markerOpt);
var marker2 = plain.Marker([39.910, 116.402], markerOpt);
var polyline = plain.Polyline(path, {
color: "#f00",
weight: 2,
opacity: 0.8
});
map.addLayer([marker, marker2]);
map.addLayer(polyline);
function eventHandler (e) {
alert(e);
console.log(plain.Util.formatEvent.call(this, e));
}
var listener = marker.on('click', eventHandler);
setTimeout(() => {
console.log("remove listener");
marker.off(listener);
}, 4000);
</script>
</body>

</html>
@@ -22,6 +22,9 @@
},
"homepage": "https://github.com/XingzheFE/plain#readme",
"devDependencies": {
"@types/node": "^8.0.4",
"@types/googlemaps": "^3.26.14",
"@types/leaflet": "^1.0.63",
"karma": "^1.7.0",
"karma-phantomjs-launcher": "^1.0.4",
"mocha": "^3.4.2",
@@ -30,9 +33,5 @@
"rollup-plugin-typescript": "^0.8.1",
"rollup-watch": "^4.0.0",
"should": "^11.2.1"
},
"dependencies": {
"@types/googlemaps": "^3.26.14",
"@types/leaflet": "^1.0.63"
}
}
}
@@ -31,6 +31,8 @@ declare namespace AMap {

/****** LngLat ******/
export class LngLat {
lat: number;
lng: number;
constructor(lng: number, lat: number);
offset(w: number, s: number): LngLat;
distance(lnglat: LngLat | LngLat[]): number;
@@ -52,13 +54,13 @@ declare namespace AMap {

/****** Map *******/
export class Map {
constructor(container: string|HTMLDivElement, opts: MapOptions);
constructor(container: string | Element, opts: MapOptions);
poiOnAMAP(obj: object): void;
detailOnAMAP(obj: object): void;
getZoom(): number:
getZoom(): number;
getLayers(): any[]; // TODO: Layer[]
getCenter(): LngLat;
getContainer(): HTMLDivElement;
getContainer(): Element;
getCity(): any;
getBounds(): Bounds;
getlabelzIndex(): number;
@@ -71,9 +73,9 @@ declare namespace AMap {
getScale(dpi: number): number;
setZoom(zoom: number): void;
setlabelzIndex(index: number): void;
setLayers(layers: Layers[]): void;
setLayers(layers: Overlayer[]): void;
add(overlayers: Overlayer[]): void;
remove(overlayers: Overlayer[]);
remove(overlayers: Overlayer[]): void;
setAllOverlays(type: any): Overlayer[]; // TODO:
setCenter(position: LngLat): void;
setZoomAndCenter(zoom: number, center: LngLat): void;
@@ -89,7 +91,7 @@ declare namespace AMap {
setFitView(overlayers: Overlayer[]): void;
clearMap(): void;
destroy(): void;
plugin(name: string|stringp[], callback: Function): void;
plugin(name: string|string[], callback: Function): void;
addControl(obj: object): void;
removeControl(obj: object): void;
clearInfoWindow(): void;
@@ -98,15 +100,15 @@ declare namespace AMap {
lngLatToContainer(lnglat: LngLat): Pixel;
setMapStyle(style: string): void;
getMapStyle(): string;
setFeatures(features: array): void;
getFeatures(): array;
setDefaultLayer(layer: TIleLayer): void;
setFeatures(features: any[]): void;
getFeatures(): any[];
setDefaultLayer(layer: TileLayer): void;
}
export interface MapOptions {
view?: View2D;
zoom?: number; // []
zooms?: number[]; // pc[3,18], mobile[3,19]
center?: LngLat;
center?: LngLat | number[];
layers?: any[];
labelzIndex?: number;
lang?: string;
@@ -123,7 +125,6 @@ declare namespace AMap {
showBuildingBlock?: boolean;
features?: any[];
mapStyle?: string;
showBuildingBlock?: boolean;
}

/******** View2D ********/
@@ -132,10 +133,10 @@ declare namespace AMap {
}

export interface View2DOptions {
center: LngLat;
rotation: number;
zoom: number;
crs: string;
center?: LngLat;
rotation?: number;
zoom?: number;
crs?: string;
}

/******* event *******/
@@ -151,10 +152,10 @@ declare namespace AMap {
}

export interface MapsEvent {
lnglat: LngLat;
pixel: Pixel;
type: string;
target: object;
lnglat?: LngLat;
pixel?: Pixel;
type?: string;
target?: object;
}

/****** TileLayer *******/
@@ -172,15 +173,15 @@ declare namespace AMap {
}

export interface TileLayerOptions {
map: Map;
titleSize: number;
tileUrl: string;
errorUrl: string;
getTileUrl: string | Function(x: number, y: number, z: number);
zIndex: number;
opacity: number;
zooms: number[];
detectRetina: boolean;
map?: Map;
titleSize?: number;
tileUrl?: string;
errorUrl?: string;
getTileUrl?: string | { Function(x: number, y: number, z: number): string};
zIndex?: number;
opacity?: number;
zooms?: number[];
detectRetina?: boolean;
}

/******* Marker *******/
@@ -243,16 +244,16 @@ declare namespace AMap {
clickable?: boolean;
shape?: MarkerShape;
extData?: any;
label: {content: string | Element, offset: number[]};
label?: {content: string | Element, offset: number[]};
}

export class MarkerShape {
constructor(opt: MarkerShapeOptions);
}

export interface MarkerShapeOptions {
coords: number[],
type: string
coords?: number[],
type?: string
}

/******* Icon ********/
@@ -265,17 +266,16 @@ declare namespace AMap {
export interface IconOptions {
// You'd better set size to new AMap.Size(19, 31)
// Because AMap.Icon can not set offset
size: Size;
imageOffset: Pixel;
image: string;
imageOffset: Size;
size?: Size;
imageOffset?: Pixel;
image?: string;
}

/******* Polyline ********/
export class Polyline extends Overlayer {
constructor(opt: PolylineOptions);
getPath(): LngLat[];
setPath(lnglats: LngLat[]): void;
getPath(): number[][];
setPath(lnglats: number[][]): void;
setOptions(opt: PolylineOptions): void;
getOptions(): PolylineOptions;
getLength(): number; // m

0 comments on commit 96ebbb6

Please sign in to comment.
You can’t perform that action at this time.