/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import {SuperMap} from '../SuperMap';
import {Feature} from './Feature';
import {Util} from './Util';
/**
* @class SuperMap.Feature.Vector
* @category BaseTypes Geometry
* @classdesc ç¢éè¦ç´ ç±»ã该类å
·æ Geometry 屿§åæ¾å ä½ä¿¡æ¯ï¼
* attributes 屿§åæ¾éå ä½ä¿¡æ¯ï¼å¦å¤è¿å
å«äº style 屿§ï¼ç¨æ¥å®ä¹ç¢éè¦ç´ çæ ·å¼ï¼
* å
¶ä¸ï¼é»è®¤çæ ·å¼å¨ {@link SuperMap.Feature.Vector.style} ç±»ä¸å®ä¹ï¼å¦ææ²¡æç¹å«çæå®å°ä½¿ç¨é»è®¤çæ ·å¼ã
* @extends {SuperMap.Feature}
* @param {SuperMap.Geometry} geometry - 代表è¦ç´ çå ä½å½¢ç¶ã
* @param {Object} [attributes] - æè¿°è¦ç´ çä»»æçå¯åºåå屿§ï¼å°è¦æ å°å° attributes 屿§ä¸ç对象ã
* @param {Object} [style] - æ ·å¼å¯¹è±¡ã
* @example
* var geometry = new SuperMap.Geometry.Point(-115,10);
* var style = {
* strokeColor:"#339933",
* strokeOpacity:1,
* strokeWidth:3,
* pointRadius:6
* }
* var pointFeature = new SuperMap.Feature.Vector(geometry,null,style);
* vectorLayer.addFeatures(pointFeature);
*/
export class Vector extends Feature {
constructor(geometry, attributes, style) {
super(null, null, attributes);
/**
* @member {string} SuperMap.Feature.Vector.prototype.fid
* @description fid
*/
this.fid = null;
/**
* @member {SuperMap.Geometry} SuperMap.Feature.Vector.prototype.geometry
* @description è¯¥å±æ§ç¨äºåæ¾å ä½ä¿¡æ¯ã
*/
this.geometry = geometry ? geometry : null;
/**
* @member {Object} SuperMap.Feature.Vector.prototype.attributes
* @description æè¿°è¦ç´ çä»»æçå¯åºåå屿§ã
*/
this.attributes = {};
if (attributes) {
this.attributes = Util.extend(this.attributes, attributes);
}
/**
* @member {SuperMap.Bounds} SuperMap.Feature.Vector.prototype.bounds
* @description The box bounding that feature's geometry, that
* property can be set by an object when
* deserializing the feature, so in most cases it represents an
* information set by the server.
*/
this.bounds = null;
/**
* @member {string} SuperMap.Feature.Vector.prototype.state
* @description state
*/
this.state = null;
/**
* @member {Object} SuperMap.Feature.Vector.prototype.style
* @description è¦ç´ çæ ·å¼å±æ§ï¼å°å¾æ¥è¯¢è¿åç feature ç styleï¼8C å为nullã
*/
this.style = style ? style : null;
/**
* @member {string} SuperMap.Feature.Vector.prototype.url
* @description å¦æè®¾ç½®äºè¿ä¸ªå±æ§ï¼å¨æ´æ°æè
å é¤è¦ç´ æ¶éè¦èè {@link SuperMap.HTTP} ã
*/
this.url = null;
this.lonlat = null;
this.CLASS_NAME = "SuperMap.Feature.Vector";
// TRASH THIS
SuperMap.State = {
/** states */
UNKNOWN: 'Unknown',
INSERT: 'Insert',
UPDATE: 'Update',
DELETE: 'Delete'
};
Vector.style = {
'default': {
fillColor: "#ee9900",
fillOpacity: 0.4,
hoverFillColor: "white",
hoverFillOpacity: 0.8,
strokeColor: "#ee9900",
strokeOpacity: 1,
strokeWidth: 1,
strokeLinecap: "round",
strokeDashstyle: "solid",
hoverStrokeColor: "red",
hoverStrokeOpacity: 1,
hoverStrokeWidth: 0.2,
pointRadius: 6,
hoverPointRadius: 1,
hoverPointUnit: "%",
pointerEvents: "visiblePainted",
cursor: "inherit",
fontColor: "#000000",
labelAlign: "cm",
labelOutlineColor: "white",
labelOutlineWidth: 3
},
'select': {
fillColor: "blue",
fillOpacity: 0.4,
hoverFillColor: "white",
hoverFillOpacity: 0.8,
strokeColor: "blue",
strokeOpacity: 1,
strokeWidth: 2,
strokeLinecap: "round",
strokeDashstyle: "solid",
hoverStrokeColor: "red",
hoverStrokeOpacity: 1,
hoverStrokeWidth: 0.2,
pointRadius: 6,
hoverPointRadius: 1,
hoverPointUnit: "%",
pointerEvents: "visiblePainted",
cursor: "pointer",
fontColor: "#000000",
labelAlign: "cm",
labelOutlineColor: "white",
labelOutlineWidth: 3
},
'temporary': {
fillColor: "#66cccc",
fillOpacity: 0.2,
hoverFillColor: "white",
hoverFillOpacity: 0.8,
strokeColor: "#66cccc",
strokeOpacity: 1,
strokeLinecap: "round",
strokeWidth: 2,
strokeDashstyle: "solid",
hoverStrokeColor: "red",
hoverStrokeOpacity: 1,
hoverStrokeWidth: 0.2,
pointRadius: 6,
hoverPointRadius: 1,
hoverPointUnit: "%",
pointerEvents: "visiblePainted",
//cursor:"inherit",
cursor: "default",
fontColor: "#000000",
labelAlign: "cm",
labelOutlineColor: "white",
labelOutlineWidth: 3
},
'delete': {
display: "none"
}
};
}
/**
* @function SuperMap.Feature.Vector.prototype.destroy
* @description nullify references to prevent circular references and memory leaks
*/
destroy() {
if (this.layer) {
this.layer.removeFeatures(this);
this.layer = null;
}
this.geometry = null;
super.destroy();
}
/**
* @function SuperMap.Feature.Vector.prototype.clone
* @description Create a clone of this vector feature. Does not set any non-standard
* properties.
* @returns {SuperMap.Feature.Vector} An exact clone of this vector feature.
*/
clone() {
return new Vector(
this.geometry ? this.geometry.clone() : null,
this.attributes,
this.style);
}
/**
* @function SuperMap.Feature.Vector.prototype.toState
* @description 设置æ°ç¶æã
* @param {string} state - ç¶æã
*/
toState(state) {
if (state === SuperMap.State.UPDATE) {
switch (this.state) {
case SuperMap.State.UNKNOWN:
case SuperMap.State.DELETE:
this.state = state;
break;
case SuperMap.State.UPDATE:
case SuperMap.State.INSERT:
break;
}
} else if (state === SuperMap.State.INSERT) {
switch (this.state) {
case SuperMap.State.UNKNOWN:
break;
default:
this.state = state;
break;
}
} else if (state === SuperMap.State.DELETE) {
switch (this.state) {
case SuperMap.State.INSERT:
// the feature should be destroyed
break;
case SuperMap.State.DELETE:
break;
case SuperMap.State.UNKNOWN:
case SuperMap.State.UPDATE:
this.state = state;
break;
}
} else if (state === SuperMap.State.UNKNOWN) {
this.state = state;
}
}
}
/**
*
* @typedef {Object} SuperMap.Feature.Vector.style
* @description SuperMap.features æå¤§éçæ ·å¼å±æ§ï¼å¦ææ²¡æç¹å«çæå®å°ä½¿ç¨é»è®¤çæ ·å¼ï¼
* 大é¨åæ ·å¼éè¿ SVG æ åå®ä¹å±æ§ã
* - fill properties èµæä»ç»ï¼{@link http://www.w3.org/TR/SVG/painting.html#FillProperties}
* - stroke properties èµæä»ç»ï¼{@link http://www.w3.org/TR/SVG/painting.html#StrokeProperties}
* @property {boolean} [fill] - ä¸éè¦å¡«å
å设置为 falseã
* @property {string} [fillColor='#ee9900'] - åå
è¿å¶å¡«å
é¢è²ã
* @property {number} [fillOpacity=0.4] - å¡«å
ä¸éæåº¦ã
* @property {boolean} [stroke] - ä¸éè¦æè¾¹å设为 falseã
* @property {string} [strokeColor='#ee9900'] - åå
è¿å¶æè¾¹é¢è²ã
* @property {number} [strokeOpacity=0.4] - æè¾¹çä¸éæåº¦(0-1)ã
* @property {number} [strokeWidth=1] - åç´ æè¾¹å®½åº¦ã
* @property {string} [strokeLinecap='round'] - strokeLinecap æä¸ç§ç±»å buttï¼roundï¼squareã
* @property {string} [strokeDashstyle='solid'] - æ dotï¼dashï¼dashdotï¼longdashï¼longdashdotï¼solid å ç§æ ·å¼ã
* @property {boolean} [graphic] - ä¸éè¦å设置为 falseã
* @property {number} [pointRadius=6] - åç´ ç¹åå¾ã
* @property {string} [pointerEvents='visiblePainted'] - pointerEventsã
* @property {string} [cursor] - cursorã
* @property {boolean} [allowRotate='false'] - æ¯å¦å
è®¸å¾æ éçè¿è¡æ¹åæè½¬ãç¨äºæ¶ç©ºæ°æ®å¾å±ã
* @property {string} [externalGraphic] - è¿æ¥å°ç¨æ¥æ¸²æç¹çå¤é¨çå¾å½¢ã
* @property {number} [graphicWidth] - å¤é¨å¾è¡¨çåç´ å®½åº¦ã
* @property {number} [graphicHeight] - å¤é¨å¾è¡¨çé«å®½åº¦ã
* @property {number} [graphicOpacity] - å¤é¨å¾è¡¨çä¸éæåº¦(0-1)ã
* @property {number} [graphicXOffset] - å¤é¨å¾è¡¨æ²¿çxæ¹åçåç§»éã
* @property {number} [graphicYOffset] - å¤é¨å¾è¡¨æ²¿çyæ¹åçåç§»é Pixelã
* @property {number} [rotation] - ä¸ä¸ªå¾è¡¨æ²¿çå
¶ä¸å¿ç¹ï¼æè
åç§»ä¸å¿æå®ç¹ï¼å¨é¡ºæ¶éæ¹åæè½¬ã
* @property {number} [graphicZIndex] - æ¸²ææ¶ä½¿ç¨çç´¢å¼å¼ã
* @property {string} [graphicName='circle'] - 渲æç¹æ¶å¾æ 使ç¨çååãæ¯æ"circle" , "square", "star", "x", "cross", "triangle"ã
* @property {string} [graphicTitle] - å¤é¨å¾è¡¨çæç¤ºæ¡ã
* @property {string} [backgroundGraphic] - å¤é¨å¾è¡¨çèæ¯ã
* @property {number} [backgroundGraphicZIndex] - èæ¯å¾æ¸²ææ¶ä½¿ç¨çç´¢å¼å¼ã
* @property {number} [backgroundXOffset] - èæ¯å¾å¨ x è½´çåç§»éã
* @property {number} [backgroundYOffset] - èæ¯å¾å¨ y è½´çåç§»éã
* @property {number} [backgroundHeight] - èæ¯å¾çé«åº¦ãå¦ææ²¡æè®¾ç½®ï¼å°ç¨ graphicHeightã
* @property {number} [backgroundWidth] - èæ¯å¾ç宽度ãå¦ææ²¡æè®¾ç½®ï¼å°ç¨ graphicWidthã
* @property {boolean} [isUnicode=false] - è¿ä¸ªå±æ§è¦é
å label 屿§æ¥ç¨ï¼å½ä¸º trueæ¶ï¼label å°±å¯ä»¥ä½¿ç¨ unicode ç¼ç ï¼
* æ¯å¦ "a" ç unicode åå
è¿å¶ç¼ç 为 61ï¼å label 屿§å¯ä»¥ä¸º "a",å
¶ä¸ "" 为åç¼ï¼æ å¿è¿ä¸ªä¸º unicode ç¼ç ï¼
* "x" æ¯æ 16 è¿å¶,è¿æ¶é¡µé¢æ¾ç¤ºçæ¯ "a"ï¼å½æ¤å¼ä¸º false çæ¶åï¼label çå
容ä¼è¢«ç´æ¥è¾åºï¼
* æ¯å¦ï¼label 为 "a"ï¼è¿æ¶é¡µé¢æ¾ç¤ºç乿¯ "a"ã
* @property {string} [label] - å¯éçæ ç¾ææ¬ã
* @property {string} [labelAlign='cm'] - æ ç¾å¯¹é½ï¼æ¯ç±ä¸¤ä¸ªåç¬¦ç»æçå符串ï¼å¦ï¼"lt", "cm", "rb"ï¼
* å
¶ä¸ç¬¬ä¸ä¸ªå符代表水平æ¹åä¸ç对é½ï¼"l"=left, "c"=center, "r"=rightï¼
* 第äºä¸ªå符代表åç´æ¹åä¸ç对é½ï¼"t"=top, "m"=middle, "b"=bottomã
* @property {number} [labelXOffset] - æ ç¾å¨ x è½´æ¹åçåç§»éã
* @property {number} [labelYOffset] - æ ç¾å¨ y è½´æ¹åçåç§»éã
* @property {boolean} [labelSelect=false] - å¦æè®¾ä¸º trueï¼æ ç¾å¯ä»¥éç¨ SelectFeature æè
similar æ§ä»¶ã
* @property {string} [fontColor='#000000'] - æ ç¾åä½é¢è²ã
* @property {number} [fontOpacity] - æ ç¾éæåº¦ (0-1)ã
* @property {string} [fontFamily] - æ ç¾çåä½ç±»åã
* @property {string} [fontSize] - æ ç¾çåä½å¤§å°ã
* @property {string} [fontStyle] - æ ç¾çå使 ·å¼ã
* @property {string} [fontWeight] - æ ç¾çåä½ç²ç»ã
* @property {string} [display] - 妿 display 屿§è®¾ç½®ä¸º ânoneâï¼ç¬¦å·å°æ²¡æä»»ä½ææã
* @example
* // labelçç¨æ³å¦ä¸ï¼
* function addGeoTest(){
* var geometry = new SuperMap.Geometry.Point(105, 35);
* var pointFeature = new SuperMap.Feature.Vector(geometry);
* var styleTest = {
* label:"supermap",
* fontColor:"#0000ff",
* fontOpacity:"0.5",
* fontFamily:"é¶ä¹¦",
* fontSize:"8em",
* fontWeight:"bold",
* fontStyle:"italic",
* labelSelect:"true",
* }
* pointFeature.style = styleTest;
* vectorLayer.addFeatures([pointFeature]);
* }
*/
SuperMap.Feature.Vector = Vector;