Category Archives: Openlayers - Page 18

OpenLayersのControl.SelectFeature classについて[Chapter 44]

OpenLayersを使ってみる。[Chapter 44]

OpenLayersのFeature classについて[Chapter 43] に引き続き、OpenLayersのFeature classについて基本を学んでいきます。

この章以降は、

  • どのようにvector layerを描いているか?
  • Vector Classとは?
  • GeometryとFeature classについて → 今回もここ
  • Strategy,Protocol,Format classの使い方

について順番に学んでいきます。

OpenLayers 2.10 Beginner's Guideなる書籍の章立てにあわせて、OpenLayersの使い方を学んでいきます。

SelectFeature control properties

propertiesは、SelectFeature controlがインスタンスされたときにセットされます。
例えば、SelectFeature control objectを呼び出すには、

var select_feature_control = new OpenLayers.Control.SelectFeature(
  vector_layer,
  {}
);

となります。
ここで{}はoptional options objectであり、propertiesを設定する事になります。

SelectFeature control のpropertiesについてみてみます。それほど難しい英語ではないので、原文のまま載せます。

box

box: {Boolean} Specifies whether features can be selected by drawing a box. Set to false by default. If set to true, when activating the SelectFeature control object, you'll be able to draw a box to select features instead of clicking on eatures to select them.

clickout

clickout: {Boolean} Determines if features will be unselected when clicking outside of any feature. Default is false.

geometryType

geometryType: {Array{String}} An array of strings which specify the only geometry types that the feature will be able to select. Each string should be the name of a Geometry class. By default, null is specified for this property, meaning all geometry types can be selected. For example, if you wanted the control to only allow the selection of Point objects, you would pass in this property like:
geometryTypes: ['OpenLayers.Geometry.Point']

handlers

handlers: {Object} This contains a reference to handler object instances.

highlightOnly

highlightOnly: {Boolean} This specifies whether features can be selected, or if features can only be highlighted. Set to false by default. If hover is set to true, this will do nothing.

hover

hover: {Boolean} Set to false by default. If this is set to true, features will be selected (and added to the vector_layer.features array) when the user mouse overs a feature—clicking on a feature will do nothing, only mousing over them will.

layer

layer: {OpenLayers.Layer.Vector} or {Array{OpenLayers.Layer.Vector}} Specifies the vector layer(s) the selectFeature control is associated with.

multiple

multiple: {Boolean} Controls whether or not multiple features will be selected by clicking on them. Default is false. This does not mean multiple features can never be selected (you can use the multipleKey to select multiple features even if this is set to false). If set to true, features will not be unselected when clicking on other features.

multipleKey

multipleKey: {String} Specifies a key to be used to allow for multiple selection of features. When holding down the key, multiple features can be selected. An example would be multipleKey: 'shiftKey' or 'altKey'. Default value is null.

onBeforeSelect

onBeforeSelect: {Function} Function to be called before a feature is selected. By default, this is an empty function.

onSelect

onSelect: {Function} Function to be called when a feature is selected. By default, this is an empty function.

onUnselect

onUnselect: {Function} Function to be called when a feature is unselected. By
default, this is an empty function.

renderIntent

renderIntent: {String} Used to get the style to use from the style map of the layer. Styles are covered in Chapter 10.

selectStyle

selectStyle: {Object} Contains an object of styles. Styles are discussed later in this chapter.

toggle

toggle: {Boolean} Determines whether or not to unselect a selected feature when the feature is clicked. Default value is false. If the hover property is set to true, this will do nothing.

toggleKey

toggleKey: {String} Specifies a key that, when held down, will set the toggle property to true. When the key is released, the toggle property will be set back to false. An example would be multipleKey: 'altKey'. Default value is null.

SelectFeature control methods

SelectFeature controlのいくつかのmethodについてみてみましょう。

activate()

activate(): Activates the control, allowing us to use it.

deactivate()

deactivate(): Deactivates the control. After calling, features cannot be selected until the control is activated again.

highlight(feature)

highlight(feature): Draws the passed in feature with the feature's select style.

unhighlight(feature)

unhighlight(feature): Draws the passed in feature with the feature's normal style.

select(feature)

select(feature): Selects a passed in feature object, adding it to the layer's selectedFeature array, calling the onSelect method, and rendering the feature as selected (applying any styles, etc.).

unselect(feature)

unselect(feature): Unselects a passed in feature object, removing it from the layer's selectedFeature array, calling the onUnselect method, and rendering the feature back to its normal state (applying any styles, etc.).

unselectAll(options)

unselectAll(options): Calling this will unselect all features currently selected by the control. If you wish to unselect everything except a specific feature, pass it in to the options parameter as an except property.

今回のまとめ

OpenLayersの簡単なControl.SelectFeature classについて学びました。(ちょい手抜きの部分もありますが。。。)
次回は、OpenLayersのVector Layer classについて、Format, protocol, and strategy classesの基本を学んでいきます。

また、本tutorialは、htmlやCSSやJavaScriptの基本的なことはある程度理解している前提で今後も話を進めていきます。また、誤字、脱字、spell間違いや勘違いも多々出てくると考えられます。
それは違うじゃん!!とかいろんな意見をいただければと思います。
そこんところ ヨロシク~~!!

OpenLayers Tutorialの目次に戻る。

Social Widgets powered by AB-WebLog.com.